最近再做robot自动测试系统,使用的是selenium2library库,原因是在网上查找发现其能设置各个浏览器的UA进行手机端模拟测试,在google上查到了可以配置chrome的UA:http://stackoverflow.com/questions/21155750/how-do-i-modify-google-chrome-user-agent-string-with-robot-framework ,但是蛋疼的是竟然找不到设置firefox的,只能自己硬着头皮查阅文档来看了,几个小时过去终于有结果。
参考的文档:
http://code.google.com/p/selenium/wiki/TipsAndTricks
http://selenium.googlecode.com/git/docs/api/py/api.html
http://rtomac.github.io/robotframework-selenium2library/doc/Selenium2Library.html#Create Webdriver
关键字可以这么写:
${ffprofile}= Evaluate sys.modules['selenium.webdriver.firefox.firefox_profile'].FirefoxProfile() sys, selenium.webdriver.firefox.firefox_profile
Call Method ${ffprofile} set_preference general.useragent.override Mozilla/4.0 (compatible; MSIE 4.01; Windows CE; .NET CLR 2.0.50727)/UCWEB8.0.3.99/31/999
Create WebDriver Firefox firefox_profile=${ffprofile}
Go To http://www.baidu.com/
OK了。