我正在 headless 环境中使用 SE2 和 firefoxDriver 运行测试 环境(Xvfb)。使用 FirefoxDriver 我可以非常设置 DISPLAY 环境属性 很容易:
FirefoxBinary firefox = new FirefoxBinary();
firefox.setEnvironmentProperty("DISPLAY",":"+DISPLAY);
FirefoxProfile firefoxProfile = new ProfilesIni().getProfile(Config.webDriverFirefoxProfile);
this.webDriver = new FirefoxDriver(firefox,firefoxProfile);
如何使用 ChromeDriver 执行上述操作?
更新:看来这还不可能做到!这里有一个与我类似的问题,其中解释了这种情况:ChromeDriver Headless
最佳答案
看起来他们已经解决了这个问题(至少现在是这样)
service = new ChromeDriverService.Builder()
.usingChromeDriverExecutable(new File("/path/to/chromedriver"))
.usingAnyFreePort()
.withEnvironment(ImmutableMap.of("DISPLAY",":20"))
.build();
这是添加此方法的代码修订版: http://code.google.com/p/selenium/source/detail?r=15232
关于google-chrome - 以编程方式将EnvironmentProperty设置为ChromeDriver,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7722615/