在过去的几天里,我一直在尽我所能将机器人框架测试配置为在 Chrome 中打开,但通过更改视口使用移动设置进行查看。我终于解决了chrome驱动程序问题(Mac OS(,但是视口修改仍然令人困惑。
我是否需要 (a( 创建 Web 驱动程序或 (b( 从 python 文件传递设置,如此处所示 移动仿真
如果您使用的是非本地 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