以编程方式将环境属性设置为ChromeDriver

问题描述:

我正在使用SE2和firefoxDriver在无头环境 环境(Xvfb)中运行测试。随着FirefoxDriver我可以设置显示环境属性很容易 :以编程方式将环境属性设置为ChromeDriver

 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

另一非编程方法,转到的/ etc /铬/默认(或的/ etc /铬的浏览器/默认或类似,依赖于分布),并有设置显示:

CHROMIUM_FLAGS="--display :99"