Chrome mobile emulator for Selenium testing- can#39;t use all devices(用于硒测试的Chrome移动模拟器-不能使用所有设备)
本文介绍了用于硒测试的Chrome移动模拟器-不能使用所有设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Chrome驱动程序及其仿真器为移动设备进行Selify Java测试。问题是,我不能使用最先进的移动设备,如iPhone7,8等--尽管当我在DevTool中手动测试时,它在我的下拉列表中。 这是驱动程序初始化。这与许多移动设备完美配合:
if(browser.equalsIgnoreCase("mobileIPhone6")){
Map<String, String> mobileEmulation = new HashMap<String, String>();
mobileEmulation.put("deviceName", "iPhone 6");
String exePathChromeDriver = Consts.chromeDriverPath;
System.setProperty("webdriver.chrome.driver", exePathChromeDriver);
PropertyLoader.loadCapabilities();
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setExperimentalOption("mobileEmulation", mobileEmulation);
driver = new ChromeDriver(chromeOptions);
但是,当我将第3行更改为"iPhone 7"时,我收到以下错误:
2018-03-16 21:25:49 INFO LogLog4j:210 - org.openqa.selenium.WebDriverException: unknown error: cannot parse capability: chromeOptions
from unknown error: cannot parse mobileEmulation
from unknown error: 'iPhone 7' must be a valid device
from unknown error: must be a valid device
你知道为什么吗?非常感谢
推荐答案
我已找到解决方案,现在工作正常。我必须首先设置Device Metrics对象:
...else if(browser.equalsIgnoreCase("iPhone678")){
String exePathChromeDriver = Consts.chromeDriverPath;
System.setProperty("webdriver.chrome.driver", exePathChromeDriver);
Map<String, Object> deviceMetrics = new HashMap<>();
deviceMetrics.put("width", 375);
deviceMetrics.put("height", 667);
deviceMetrics.put("pixelRatio", 2.0);
Map<String, Object> mobileEmulation = new HashMap<>();
mobileEmulation.put("deviceMetrics", deviceMetrics);
mobileEmulation.put("userAgent", "Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) Version/11.0 Mobile/15A5341f Safari/604.1");
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setExperimentalOption("mobileEmulation", mobileEmulation);
driver = new ChromeDriver(chromeOptions); }
这篇关于用于硒测试的Chrome移动模拟器-不能使用所有设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:用于硒测试的Chrome移动模拟器-不能使用所有设备
![](/xwassets/images/pre.png)
![](/xwassets/images/next.png)
猜你喜欢
- GC_FOR_ALLOC 是否更“严重"?在调查内存使用情况时? 2022-01-01
- java.lang.IllegalStateException:Bean 名称“类别"的 BindingResult 和普通目标对象都不能用作请求属性 2022-01-01
- 将 Java Swing 桌面应用程序国际化的最佳实践是什么? 2022-01-01
- 如何使 JFrame 背景和 JPanel 透明且仅显示图像 2022-01-01
- 在 Java 中,如何将 String 转换为 char 或将 char 转换 2022-01-01
- 获取数字的最后一位 2022-01-01
- 如何指定 CORS 的响应标头? 2022-01-01
- 未找到/usr/local/lib 中的库 2022-01-01
- 转换 ldap 日期 2022-01-01
- Eclipse 的最佳 XML 编辑器 2022-01-01