Robotframework+Selenium2 WebDriver进行Web UI测试

因为工作原因,基本上没有接触到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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值