在robotframework中,如何配置chrome驱动程序和视口设置?

时间:2016-02-16 17:04:59

标签: python robotframework

在过去的几天里,我一直在努力配置机器人框架测试以在Chrome中打开,但可以通过更改视口来查看移动设置。我终于解决了Chrome驱动程序问题(Mac OS),但视口修改仍然令人困惑。

我是否需要(a)创建Webdriver或(b)从python文件传递设置,如下所示Mobile Emulation

1 个答案:

答案 0 :(得分:4)

如果您使用的是非本地Web驱动程序,则可以使用“打开浏览器”,但使用Create Webdriver可以正常工作。这是您引用的页面的翻译(为我工作):

*** Settings ***
Test Teardown     Close All Browsers
Library           Selenium2Library

*** Test Cases ***
Specifying a Known Mobile Device
    ${mobile emulation}=    Create Dictionary    deviceName=Google Nexus 5
    ${chrome options}=    Evaluate    sys.modules['selenium.webdriver'].ChromeOptions()    sys, selenium.webdriver
    Call Method    ${chrome options}    add_experimental_option    mobileEmulation    ${mobile emulation}
    Create Webdriver    Chrome    chrome_options=${chrome options}
    Goto    https://stackoverflow.com
    Sleep    10 secs

Specifying Individual Device Attributes
    ${device metrics}=    Create Dictionary    width=${360}    height=${640}    pixelRatio=${3.0}    userAgent=Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19
    ${mobile emulation}=    Create Dictionary    deviceMetrics=${device metrics}
    ${chrome options}=    Evaluate    sys.modules['selenium.webdriver'].ChromeOptions()    sys, selenium.webdriver
    Call Method    ${chrome options}    add_experimental_option    mobileEmulation    ${mobile emulation}
    Create Webdriver    Chrome    chrome_options=${chrome options}
    Goto    https://stackoverflow.com
    Sleep    10 secs