Pau*_*ish 14 mobile webdriver selenium-chromedriver
如果您将ChromeDriver与Chrome(通过Chromedriver)一起使用,则可能需要模拟移动视口特性.同样,您可能希望在桌面上自动执行测试,而无需在Android设置上使用正确的Chrome.
你是怎样做的?
Pau*_*ish 14
该mobile_emulation功能已在2.11中添加到ChromeDriver
完整文档:https://sites.google.com/a/chromium.org/chromedriver/mobile-emulation
我的笔记如下:
使用mobile_emulation功能选项在Python中创建驱动程序:
driver = self.CreateDriver(
mobile_emulation = {
'deviceMetrics': {'width': 360, 'height': 640, 'pixelRatio': 3}})
Run Code Online (Sandbox Code Playgroud)
目前,您可以模拟devicepixelratio,useragent,视口高度和宽度.
mobile_emulation dict的可能属性:
deviceName:如果使用,必须是唯一的财产.匹配Chrome中预设的设备(例如'Google Nexus 5').deviceMetrics:一个dict,可以包括width(int),height(int),pixelRatio(double),如上所示.userAgent:一个欺骗请求标头和导航器对象的字符串.小智 7
这是最新的官方chromedriver版本(2.11).
java中的示例:
final DesiredCapabilities dc = DesiredCapabilities.chrome();
dc.setCapability(ChromeOptions.CAPABILITY, new ChromeOptions() {
{
setExperimentalOption("mobileEmulation", new HashMap<String, Object>() {
{
put("deviceName", "Google Nexus 5");
}
});
}
});
ChromeDriver driver = new ChromeDriver(dc);
Run Code Online (Sandbox Code Playgroud)
mobileEmulation选项在最后一个ChromeDriver版本(v 2.11)中实现.使用WebDriverJs,您必须将其作为属性添加到功能对象.
var webdriver = require('selenium-webdriver');
var capabilities = {
browserName: 'chrome',
chromeOptions: {
mobileEmulation: {
deviceName: 'Apple iPhone 5'
}
}
};
var
driver = new webdriver
.Builder()
.withCapabilities(capabilities)
.build();
driver.get('http://google.com');
var bool = false;
setTimeout(function () {
bool = true;
}, 9000);
driver.wait(function() {
return bool;
}, 10000);
driver.quit();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16542 次 |
| 最近记录: |