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

Fre*_*ddy 0 python robotframework

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

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

omb*_*e42 5

如果您使用的是非本地网络驱动程序,则可以使用 Open Browser,但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
Run Code Online (Sandbox Code Playgroud)