RobotFramework模拟手机浏览器

转自

http://blog.csdn.net/max229max/article/details/70808867

 

感谢max bai提供的思路

Python - Selenium Chrome 模拟手机可以实现chrome浏览器模拟手机进行自动化测试,当然Robotframework也是可以的。

基本思路:

1.创建chromeoption

2.创建mobileEmulation字典包含模拟器的相关信息

3. 设置chromeoption的模拟器信息

4. 开始测试吧

*** Settings ***  
Library           Selenium2Library  
  
*** Test Cases ***  
testmclient  
    ${devname}    Create Dictionary    deviceName=Google Nexus 5  
    #${mobile_emulation}    Create Dictionary    mobileEmulation=${devname}  
    ${chromeoptions}=    Evaluate    sys.modules['selenium.webdriver.chrome.options'].Options()    sys, selenium.webdriver.chrome.options  
    # ${chromeoptions._experimental_options}    Set Variable    ${mobile_emulation}  
    Call Method    ${chromeoptions}    add_experimental_option    mobileEmulation    ${devname}  
    Create Webdriver    Chrome    chrome_options=${chromeoptions}  
    Go To    http://www.baidu.com  
    sleep    5s  
    Close All Browsers  

脚本设置了简单的模拟器信息,详细的可以参照 Python - Selenium Chrome 模拟手机

 

执行截图:

 

posted @ 2017-04-26 18:32  悠然现南山  阅读(534)  评论(0编辑  收藏  举报