通过编程将EnEnvironmentProperty设置为ChromeDriver [英] SetEnvironmentProperty to ChromeDriver programmatically

查看:119
本文介绍了通过编程将EnEnvironmentProperty设置为ChromeDriver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用SE2和firefoxDriver进行无头测试 环境(Xvfb).使用FirefoxDriver,我可以非常设置DISPLAY环境属性 轻松:

I am running tests with SE2 and firefoxDriver in a headless enviroment(Xvfb). With FirefoxDriver I can set the DISPLAY environment property very easily:

     FirefoxBinary firefox = new FirefoxBinary(); 
     firefox.setEnvironmentProperty("DISPLAY",":"+DISPLAY); 
     FirefoxProfile firefoxProfile = new ProfilesIni().getProfile(Config.webDriverFirefoxProfile); 
     this.webDriver = new FirefoxDriver(firefox,firefoxProfile); 

如何使用ChromeDriver进行上述操作?

How can I do the above with ChromeDriver?

更新:看来这还不可能!我的这里有一个类似的问题,说明了这种情况: ChromeDriver无头

UPDATE: Seems that this is not possible to do yet! There is a similar question with mine here where explains the situation: ChromeDriver Headless

推荐答案

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

looks like they've fixed this (at least for now)

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

Here's the revision in the code which adds this method: http://code.google.com/p/selenium/source/detail?r=15232

这篇关于通过编程将EnEnvironmentProperty设置为ChromeDriver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆