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

In robotframework how do you configure the chrome driver and viewport settings?

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

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

如果您使用的是非本地网络驱动程序,则可以使用“打开浏览器”,但使用 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://whosebug.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://whosebug.com
    Sleep    10 secs