用例编写前提:
- 已经部署好了robot/python3环境,详见:
- 安装selenium,推荐3.11.0版本: pip install selenium==3.11.0
- 安装robotframework-seleniumlibrary,推荐3.1.1版本: pip install robotframework-seleniumlibrary==3.1.1
- 安装webdriver,推荐比较流行的chromedriver,从这里下载:http://chromedriver.storage.googleapis.com/index.html
chromedriver的版本需要和本机的chrome浏览器对应,才能正常使用;下载对应版本的chromedriver驱动文件,具体版本对应关系表:
chromedriver版本 ?????| 支持的Chrome版本
v2.33 ??| v60-62
v2.32 ??| v59-61
v2.31 ??| v58-60
v2.30 ??| v58-60
v2.29 ??| v56-58
v2.28 ??| v55-57
v2.27 ??| v54-56
v2.26 ??| v53-55
v2.25 ??| v53-55
v2.24 ??| v52-54
v2.23 ??| v51-53
v2.22 ??| v49-52
v2.21 ??| v46-50
v2.20 ??| v43-48
v2.19 ??| v43-47
v2.18 ??| v43-46
v2.17 ??| v42-43
v2.13 ??| v42-45window平台的话,解压后放到本机chrome浏览器文件路径里,如:
C:\Program Files (x86)\Google\Chrome\Application
或者系统path里增加chromedriver的解压地址
在用例文件中引用selenium包
*** Settings ***Library ?CollectionsLibrary ?SeleniumLibrary
一个样例如下:
*** Test Cases ***my first html ???????#创建一个chrome浏览器 ???Open Browser ???http://www.我的域名.cn/ ????chrome ????#输入文本框 ???input text ?????id=inputName ???????????admin ???input text ?????id=inputPassword ???????admin ???input text ?????id=inputCode ???????????123 ???#点击按钮 ???Click Button ???Xpath=//form/div/span/button ???????#单击A标签 ???| locator表示定位器 ???????#Click Link | locator ???????#单击某个标签 ???????#Click Element ???Xpath=//ul[@id=‘systemSetting0‘] ???${cnt} ?????????get title ???log ????${cnt} ???${title} ???????get window titles ???log ????${title} ???Title Should Be ???一个后台 ???Location should Contain ?http://www.我的域名.cn/ ???Page Should Not Contain ????不包含我 ???Page Should Contain ????????必须包含我 ???????# 关闭打开的浏览器 ???????Close Browser ???Close All Browsers
执行用例你将会看到,一个chrome自动打开,并且输入密码,点击了登录,也可能速度奇快看不清,为了看的清晰,可以用sleep方法在每步停留几秒:
# 这里的单位是秒sleep ??3
当然,如果你的web加载比较慢,用停留几秒来规避是不靠谱的,建议用这个方法:
Wait Until Page Contains Element
robot+selenium编写web UI自动化用例
原文地址:http://blog.51cto.com/7717647/2114466