在 Selenium 测试中指定自定义屏幕分辨率 [英] Specifying custom screen resolution in Selenium tests
问题描述
如下文所述,我们可以在 selenium 测试运行期间修改屏幕分辨率.http://blog.testingbot.com/2013/03/15/screen-resolution-option-now-available-for-all-selenium-tests
As mentioned in the below blog, we can modify screen resolution during selenium test runs. http://blog.testingbot.com/2013/03/15/screen-resolution-option-now-available-for-all-selenium-tests
尝试了以下代码(如https://saucelabs.com/docs/additional-config"),但没有设置指定的分辨率.这仍然不适用于 Selenium 吗?
Tried the below code(as mentioned in "https://saucelabs.com/docs/additional-config"), but not setting the specified resolution. Is this still not available for Selenium?
DesiredCapabilities dc=new DesiredCapabilities();
dc.setCapability("screen-resolution","1280x1024");
推荐答案
Sauce Labs != Selenium
Sauce Labs != Selenium
Sauce 实验室使用该功能为您提供具有所需分辨率的 VM,Selenium 本身并不了解该功能.
Sauce labs use that capability to provision you a VM with the desired resolution, it's not a capability that Selenium itself knows about.
Selenium 无法修改您的桌面分辨率!
如果您想在 Selenium 中修改您的浏览器大小以使其与特定分辨率匹配,您可以执行以下操作:
If you want to modify your browser size in Selenium so that it matches a specific resolution you can do a:
driver.manage().window().setSize(new Dimension(1024, 768))
Opera 驱动程序不支持上述内容,因此您需要执行以下操作:
The above is not supported with Opera driver, so instead you would need to do:
DesiredCapabilities capabilities = DesiredCapabilities.opera()
capabilities.setCapability("opera.arguments", "-screenwidth 1024 -screenheight 768")
虽然设置浏览器大小与设置屏幕分辨率不同,但它应该满足您的所有意图和目的.
While setting the browser size is not the same as setting the screen resolution, it should for all intents and purposes meet your requirements.
这篇关于在 Selenium 测试中指定自定义屏幕分辨率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!