Selenium RobotFramework - Chrome 模拟手机

深圳-Max · April 26, 2017 · 879 hits

Max.Bai
2017-04

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}  
    Create Webdriver    Chrome    chrome_options=${chromeoptions}  
    Go To    http://www.baidu.com  
    sleep    5s  
    Close All Browsers  

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

执行截图:

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
No Reply at the moment.
需要 Sign In 后方可回复, 如果你还没有账号请点击这里 Sign Up