




免费预览已结束,剩余47页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
LOGO selenium2python 自动化测试实战 虫师 http itest info http itest info http itest info 前言 为什么要做自动化测试 A 节省手工测试的人才和成本B 有助于提升测试团队的技术力量C 能够生成直观的图形化报表D 我不知道 领导要求做的 http itest info 前言 分层的自动化测试 http itest info 前言 什么样的产品适合做自动化测试 功能成熟 需求变动较小 产品更新维护周期长项目进度不太大比较频繁的回归测试软件开发比较规范 具有可测试性可以脚本具有可复用性 http itest info 本课程学习重点 selenium技术 元素定位的几种方法WebDriverAPI seleniumIDE seleniumgridpython技术 函数 类 方法 读写文件 unitest单元测试框架 HTMLTestRunner py 发邮件模块 多线程技术等 http itest info selenium selenium的特点 开源 免费多浏览器支持 firefox chrome IE多平台支持 linux windows MAC多语言支持 java python ruby php C 对web页面有良好的支持简单 API简单 灵活 用开发语言驱动 支持分布式测试用例执行 http itest info selenium家谱 selenium1 0 selenium2 0 selenium1 0 WebDriver http itest info http itest info 环境搭建 window安装 第一步 安装python第二步 安装setuptoolsC setuptools 1 3 pythonsetup pyinstall第三步 安装pipC pip 1 4 1 pythonsetup pyinstall第四步 安装seleniumC Python27 Scripts pipinstall Uselenium环境变量 变量名 PATH变量值 C Python27 http itest info 环境搭建 简易安装 ActivePython ActivePython包含了一个完整的Python内核 并附加了一些Python的Windows扩展第一步 下载安装ActivePython第二步 安装seleniumC Python27 Scripts pipinstall Uselenium http itest info 环境搭建 linux安装 ubuntu 第一步 安装 setuptoolsroot fnngj H24X apt getinstallpython setuptools第二步 安装piproot fnngj H24X pip 1 4 1 pythonsetup pyinstall第三步 安装seleniumroot fnngj H24X pip 1 4 1 pipinstall Uselenium http itest info 第一个自动化脚本 百度搜索 http itest info http itest info 元素的定位 WebDriver提供的八种定位方法 find element by id find element by name find element by class name find element by tag name find element by link text find element by partial link text find element by xpath find element by css selector http itest info 元素的定位 id name classname tagname 百度搜索框前端代码 通过firebug查看 find element by id kw1 find element by name wd find element by class name s ipt find element by tag name input 注 页面上的元素tagname相同的几率很高 http itest info 元素的定位 link partiallink 百度首页文字链接 新闻贴吧知道find element by link text u 新闻 find element by partial link text 新 find element by link text u 贴吧 注 中文字符串加u是将中文转换成unicode 防止编码问题 http itest info 元素的定位 xpath find element by xpath id kw1 find element by xpath input id kw1 find element by xpath input name wd find element by xpath input class s ipt find element by xpath span class bgs iptwr input find element by xpath form id form1 span input find element by xpath html body div div 4 div 2 div form span input http itest info 元素的定位 CSS常见语法 http itest info 元素的定位 CSS 定位find element by css selector from 定位find element by css selector subdiv find element by css selector from div 定位find element by css selector recordlist find element by css selector ul recordlist find element by css selector div ul 定位Headingfind element by css selector div ul find element by css selector div subdiv ul p Heading http itest info http itest info WebDriverAPI 浏览器最大化 maximize window 设置浏览器宽 高 set window size 480 800 控制浏览器后退 前进 back forward http itest info WebDriverAPI WebElement接口常用方法 clear清除元素的内容send keys在元素上模拟按键输入click单击元素submit提交表单size返回元素的尺寸text获取元素的文本get attribute name 获得属性值is displayed 设置该元素是否用户可见 http itest info WebDriverAPI ActionChains类鼠标操作的常用方法 context click 右击double click 双击drag and drop 拖动move to element 鼠标悬停在一个元素上click and hold 按下鼠标左键在一个元素上 http itest info WebDriverAPI ActionChains类鼠标操作的常用方法 context click 右击 http itest info WebDriverAPI ActionChains类鼠标操作的常用方法 drag and drop 拖动 http itest info WebDriverAPI ActionChains类鼠标操作的常用方法 move to element 鼠标悬停 http itest info WebDriverAPI Keys类键盘操作的常用方法 send keys Keys BACK SPACE 删除键 BackSpace send keys Keys SPACE 空格键 Space send keys Keys TAB 制表键 Tab send keys Keys ESCAPE 回退键 Esc send keys Keys ENTER 回车键 Enter send keys Keys CONTROL a 全选 Ctrl A send keys Keys CONTROL c 复制 Ctrl C send keys Keys CONTROL x 剪切 Ctrl X send keys Keys CONTROL v 粘贴 Ctrl V http itest info WebDriverAPI ActionChains类鼠标操作的常用方法 move to element 鼠标悬停 http itest info WebDriverAPI 打印信息 断言的信息 title返回当前页面的标题current url获取当前加载页面的URLtext获取元素的文本信息 http itest info WebDriverAPI 打印信息 126邮箱 http itest info WebDriverAPI 脚本中的等待时间 sleep python提供设置固定休眠时间的方法 implicitly wait 是webdirver提供的一个超时等待 WebDriverWait 同样也是webdirver提供的方法 http itest info WebDriverAPI webdriver提供定位一组对象的方法 find elements by id find elements by name find elements by class name find elements by tag name find elements by link text find elements by partial link text find elements by xpath find elements by css selector http itest info WebDriverAPI 定位一组对象 例一 http itest info WebDriverAPI 定位一组对象 例二 http itest info WebDriverAPI 层级定位 http itest info WebDriverAPI frame表单嵌套的定位 switch to frame方法 http itest info WebDriverAPI div弹窗的处理 http itest info WebDriverAPI 多窗口的处理 current window handle获得当前窗口句柄window handles返回的所有窗口的句柄到当前会话switch to window 用于处理多窗口之前切换 http itest info WebDriverAPI 多窗口的处理 http itest info WebDriverAPI alert confirm prompt处理 switch to alert 用于获取网页上的警告信息 text返回alert confirm prompt中的文字信息 accept点击确认按钮 dismiss点击取消按钮 如果有的话 send keys输入值 这个alert confirm没有对话框就不能用了 不然会报错 http itest info WebDriverAPI 下拉框处理 二次定位 driver find element by xx xx find element by xx xx click http itest info WebDriverAPI 文件上传 driver find element by xx xx send keys d abc txt http itest info WebDriverAPI 文件下载 确定Content Type 下载文件的类型方法一 curl IURL grep Content Type 方法二 http itest info WebDriverAPI 文件下载 http itest info WebDriverAPI 调用javaScript execute script 调用js方法 http itest info WebDriverAPI 控制浏览器滚动条 http itest info WebDriverAPI cookie处理 get cookies 获得所有cookie信息get cookie name 返回特定name有cookie信息add cookie cookie dict 添加cookie 必须有name和value值delete cookie name 删除特定 部分 的cookie信息delete all cookies 删除所有cookie信息 http itest info WebDriverAPI cookie处理 get cookies 获得所有cookie信息get cookie name 返回特定name有cookie信息add cookie cookie dict 添加coo
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 无色素性黑色素瘤护理查房
- 安顺市2024-2025学年七年级下学期语文期末模拟试卷
- 阿拉善盟2024-2025学年八年级上学期语文期中模拟试卷
- 安徽省滁州市来安县2024-2025学年高三上学期期末考试化学试卷及答案
- 湖南省常德市桃源县凌津滩乡中学2025年上学期七年级《生物体的结构层次》测试(无答案)
- 心理健康家长讲堂携手共育成就孩子未来模板
- 社区消防知识培训课件活动
- 社区消防知识培训课件会
- 2024-2025学年江西省部分学校九年级(下)月考物理试卷(3月份)-自定义类型(含答案)
- 午餐外卖合同范本
- 企业员工居家办公管理制度
- 产品研发与技术转移制度
- 八年级语文重点知识及文学常识归纳总结
- 台州市开发投资集团有限公司招聘笔试题库2024
- 乡镇供电所全能型员工评聘考试题库(精简600题)
- 机械设备投标书范本
- 河北安装工程消耗量定额计算规则
- 义务教育《数学课程标准》2022年版原文
- YC/T 310-2024烟草漂浮育苗基质
- 智慧公厕设备采购投标方案(技术方案技术标)
- MapInfo使用教程教学课件
评论
0/150
提交评论