其他实例.ppt

  1. 1、本文档共9页,可阅读全部内容。
  2. 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
其他实例.ppt

使用pexpect实现命令行自动化测试 徐荣中 2015-03-06 Email:xurongzhong#126.com 个人博客:/blog 微博:/cizhenshi 一览社群:679983 qq群:241450660 实地交流地址:/group_article/5191422951800241.htm 一、分享内容概述 介绍 安装 快速入门 EOF和TIMEOUT 类介绍 实例 Pexpect介绍 Pexpect allows easy control of interactive console applications. Pexpect is a pure Python module for spawning child applications; controlling them; and responding to expected patterns in their output. Pexpect works like Don Libes’ Expect. Pexpect allows your script to spawn a child application and control it as if a human were typing commands. Pexpect can be used for automating interactive applications such as ssh, ftp, passwd, telnet, etc. It can be used to a automate setup scripts for duplicating software package installations on different servers. It can be used for automated software testing. It should work on any platform that supports the standard Python pty module. The Pexpect interface was designed to be easy to use. 参考资料: /pypi/pexpect Pexpect安装 pip install pexpect 或 easy_install pexpect 要求: This version of Pexpect(3.3) requires Python 2.6 or 3.2 or above. Pexpect only works on POSIX systems, where the pty module is present in the standard library. It may be possible to run it on Windows using Cygwin. 参考资料: /en/latest/install.html Pexpect快速入门 import pexpect child = pexpect.spawn(ftp ) child.expect(Name .*: ) child.sendline(anonymous) child.expect(Password:) child.sendline() child.expect(ftp ) child.sendline(lcd /tmp) child.expect(ftp ) child.sendline(cd pub/OpenBSD) child.expect(ftp ) child.sendline(get README) child.expect(ftp ) child.sendline(bye) 两个重要方法: expect() and send() (or sendline() ) 信息输出: before 包含预期字符串之前的信息, after包含匹配模式。 参考资料: /en/latest/overview.html 常量EOF和TIMEOUT End Of File (EOF):子进程退出时会生成EOF异常。相关信息存储在before中。 child.expect(password:) child.sendline(my_secret_password) # We expect any of these three patterns... i = child.expect ([Permission denied, Terminal type, [#\$] ]) if i==0: print(Permission denied on host. Cant

您可能关注的文档

文档评论(0)

youbika + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档