- 1、本文档共9页,可阅读全部内容。
- 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 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
您可能关注的文档
- 使用ADO访问数据库.ppt.ppt
- 使用QWT绘制科学图表、绘图.doc.doc
- 使用单变量求解和规划求解分析数据.ppt
- 使用导出实用程序使用导入实用程序-Read.ppt
- 使用帮助-数字资源管理发布系统.doc
- 使用手册-登录.doc
- 使用指南2-苏州市职业大学图书馆.ppt
- 使用说明书-东北林业大学远程接入系统.doc
- 例1求下列函数的定义域.ppt
- 例文-金旭学校.ppt
- 2024年浙江衢州江山市上余镇卫生院招聘编外医生2人笔试模拟试题及答案解析.docx
- 2024吉林省吉林市丰满区“家门口”就业创业服务专员公益岗招聘34人笔试备考试题及答案解析.docx
- 教科版科学四年级下册复习课件-2.7电路中的开关.pptx
- 2025年潍坊市坊子区公开招聘高中教师(15名)笔试模拟试题及答案解析.docx
- 2024年浙江绍兴市本级卫生健康单位赴浙江中医药大学招聘应届医学类毕业生53人笔试备考试题及答案解析.docx
- 2024西安市工业合作联社下属企业招聘(16人)笔试模拟试题及答案解析.docx
- 2025年国网英大国际控股集团有限公司招聘2人笔试模拟试题及答案解析.docx
- 果洛西宁民族中学2024年秋学期临聘教师招聘笔试模拟试题及答案解析.docx
- 2024吉林省吉林市丰满区“家门口”就业创业服务专员公益岗招聘34人笔试备考题库及答案解析.docx
- 2024西安市远东第二中学11月教师招聘笔试模拟试题及答案解析.docx
文档评论(0)