robot-selenium2library 使用经验

本文档详细介绍了如何在Linux和Windows环境下安装配置Selenium2Library,并提供了使用该库进行Web自动化测试的关键字示例及常见问题解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

RIDE上:

F5 帮助文档,那些库有哪些关键字可用

ctrl+shift+空格   在输入框按下后,快速补全关键字


关键字举例:

Page Should Contain Image  xpath=//img[@src="http://***.jpg"]    --》使用了xpath找节点

Execute Javascript${CURDIR}/test.js                                        --》页面上执行js来模拟用户行为


在线文档:

主页:http://robotframework.org/

robot丰富的开源库:http://robotframework.org/#test-libraries

Selenium2Library的帮助文档:http://rtomac.github.io/robotframework-selenium2library/doc/Selenium2Library.html


Linux上使用selenium2library

yum install xorg-x11-server-Xvfb.i386      --虚拟界面

python get-pip.py   

pip install xvfbwrapper

pip install robotframework

pip install robotframework-selenium2library==1.4.1   可以使用pip install -U 升级

pip install robotframework-sshlibrary

yum install firefox.i386

发现selenium最新的 selenium 2.40 只支持Firefox 27的。类似这种问题也要注意下!


Windows上使用selenium2library(可以使用神马项目里面SVN路径“质量保障\06工具”的一键安装包

python-2.7.6.msi

setuptools-0.6c11.win32-py2.7.exe      --》  装easy_install 

wxPython2.8-win32-unicode-2.8.12.1-py27.exe   

robotframework-2.8.1.win32.exe

easy_install robotframework-selenium2library

robotframework-ride-1.2.win32.exe

python -c "from robotide import main; main()"

记得在环境变量加上C:\Python27 C:\Python27\Lib C:\Python27\Scripts


使用selenium遇到的问题汇总:

1、使用selenium时如何针对不同的ua进行测试,拿firefox举例(自己研究的,网上找不到这个,估计只能找到chrome的):

编写一个关键字openurl_ua, 参数为${ua}:

${ffprofile}= Evaluate sys.modules['selenium.webdriver.firefox.firefox_profile'].FirefoxProfile()sys, selenium.webdriver.firefox.firefox_profile

Call Method         ${ffprofile} set_preferencegeneral.useragent.override${ua}

Create WebDriver Firefox firefox_profile=${ffprofile}

2、有时候会遇到“Keyword 'Capture Page Screenshot' could not be run on failure: No browser is open”然后测试失败,全部红色

原因:

1) firefox被kill掉或者自动退出了;

2) selenium2使用上本身遗留的一个问题,如果偶然遇到这个问题,可以多给两次机会跑用例,一般运气没那么差会连续两三次都遇到这种偶现情况

3、类似“WebDriverException: Message: u'elem is null' ; Stacktrace”这种提示google不到答案的,问题就处在自己写的测试案例身上

4pybot layout/css/test.txt  不执行最顶层suite的setup,应该要加参数才行,目前还不知道怎么搞。

5关键字不要乱起名字以免误解,要求清晰直接,这才是关键字的精髓


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值