以编程方式将SetEnvironmentProperty设置为ChromeDriver

时间:2011-10-11 07:21:50

标签: google-chrome selenium-webdriver webdriver xvfb

我正在用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

2 个答案:

答案 0 :(得分:8)

看起来他们已经解决了这个问题(至少目前为止)

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

答案 1 :(得分:1)

另一种非程序化方法,转到 / etc / chromium / default (或 / etc / chromium-browser / default 或类似的,取决于分发)并设置在那里显示:

CHROMIUM_FLAGS="--display :99"