在基于selenium的测试中,我将窗口大小设置为400(w) 719(h),以创建400x640的内部视区大小。我的大多数测试都基于这个大小,但也有一些使用其他大小。
Dimension size = new Dimension(400, 719);
driver.manage().window().setSize(size);较新版本的chrome未能将窗口大小设置为400像素宽度,而是生成的窗口宽度约为500px (尽管有所不同)。
https://bugs.chromium.org/p/chromedriver/issues/detail?id=2639 (bug,声称其已修复,但似乎没有)
因此,我想设置内部视区的大小。
我如何在selenium/chrome webdriver中做到这一点?
发布于 2019-05-09 17:41:22
你可以看看chromedriver Moblie Emulation。
如上所述,
java示例
Map<String, Object> deviceMetrics = new HashMap<>();
deviceMetrics.put("width", 360);
deviceMetrics.put("height", 640);
deviceMetrics.put("pixelRatio", 3.0);
Map<String, Object> mobileEmulation = new HashMap<>();
mobileEmulation.put("deviceMetrics", deviceMetrics);
mobileEmulation.put("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");
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setExperimentalOption("mobileEmulation", mobileEmulation);
WebDriver driver = new ChromeDriver(chromeOptions);https://stackoverflow.com/questions/56054665
复制相似问题