因为工作原因,基本上没有接触到Web测试,但是在做Robotium的Webview app的时候接触到hybird app的测试,这只是针对android app测试,所以有了闲暇时间研究了一下Selenium的web测试,发现这个开源软件异常强大,可以在github上找到机会你想要的库,所以留个记号,以后备用。
1. 安装
很容易,首先安装Python,我是用的2.7版本,经典版本。windows下64位,傻瓜式安装不说了。
然后管理员权限打开cmd,运行
pip install decorator
pip install robotframework
pip install robotframework-selenium2library
pip install -U selenium
pip install robotframework-ride
http://sourceforge.net/projects/wxpython/下载unicode版本
具体的case,需要导入Selenium2Library,默认打开的是firefox,当然可以改变浏览器
下面是个非常简单的例子
*** Settings ***
Library Selenium2Library
*** Test Cases ***
TestCase1
Open Browser http://www.baidu.com
Input Text id=kw robot framework学习
Click Button id=su
Sleep 3s
Input Text id=kw 北京人民政府
Click Element id=su
Click Element id=result_logo
Sleep 3s
Close Browser
运行使用pybot xxx.robot
关于定位,提供了很多种方法,常用的有:
可以通过id或name定位界面
也可以通过Xpath或Dom,必须用xpath=和dom=开头
Strategy | Example | Description |
identifier | Click Element | identifier=my_element | Matches by @id or @name attribute |
id | Click Element | id=my_element | Matches by @id attribute |
name | Click Element | name=my_element | Matches by @name attribute |
xpath | Click Element | xpath=/html/div | Matches with arbitrary XPath |
class | Click Element | class=UIAPickerWheel | Matches by class |
accessibility_id | Click Element | accessibility_id=t | Accessibility options utilize. |
输入:
Input Text 位置 文本内容
详细可以查阅相关文档
写UI case可以使用chrome上,在元素上右键,审查元素,就能打开相应的调试工具,非常方便。
写case不能想我上面的写法,要分层结构,具体,这里给一个链接供参考
https://blog.codecentric.de/en/2012/03/robot-framework-tutorial-overview/
这个里面详细描述了robotframework的写法,会让case更易维护观看
附Robotframework有很多插件,例如:
BuildIn,Dialogs,Collections,OperatingSystem,Remote,Screenshot,String,Telnet,XML,Android Library,Anywhere Library,AppiumLibrary,Archive Library,AutoIt Library,Database Library,DiffLibrary,EclipseLibrary,robotframework-faker,FTP Library,HTTP Library,iOS Library,MongoDB Library,Rammbock,RemoteSwingLibrary,SeleniumLibrary,Selenium2Library,SSH Library,Suds Library,Swing Library,watir-robo