我想在 linux 服务器上使用 selenium2 的 chrome webdriver 运行自动化测试。
我已经使用 Xvfb 将 firefox 设置为在服务器上运行(参见http://www.semicomplete.com/blog/geekery/xvfb-firefox.html),并且想用 chrome 做类似的事情。这可能吗?
我想在 linux 服务器上使用 selenium2 的 chrome webdriver 运行自动化测试。
我已经使用 Xvfb 将 firefox 设置为在服务器上运行(参见http://www.semicomplete.com/blog/geekery/xvfb-firefox.html),并且想用 chrome 做类似的事情。这可能吗?
我面临着使用 selenium + chromedriver 设置 linux 盒子的同样挑战,这是我的笔记:
先决条件:
安装 JRE 以运行 selenium jar
安装硒服务器
从https://code.google.com/p/selenium/downloads/list获取 jar 文件)
安装 xvfb(你似乎已经完成了这部分)
为您的 linux 发行版安装 google-chrome
下载 chrome 驱动程序您可以从这里获取它:https ://sites.google.com/a/chromium.org/chromedriver/downloads
安装您可能需要的其他 selenium 依赖项(但以上是让 chromedriver 工作的最低要求)
跑步:
Xvfb :1 -screen 5 1024x768x8 &
export DISPLAY=:1.5
java -jar selenium-server-standalone-2.30.0.jar -Dwebdriver.chrome.bin=/path/to/google-chrome -Dwebdriver.chrome.driver=/path/to/chromedriver
2013 年 3 月 19 日上午 10:07:27 org.openqa.grid.selenium.GridLauncher 主要信息:启动独立服务器
将系统属性 webdriver.chrome.bin 设置为 {location of google-chrome}
将系统属性 webdriver.chrome.driver 设置为 {location of chromedriver}
10:07:34.258 信息 - RemoteWebDriver 实例应连接到:
http://127.0.0.1:4444/wd/hub
10:07:34.259 信息 - 版本 Jetty/5.1.x 10:07:34.259 信息 - 已启动 HttpContext[/selenium-server/driver,/selenium-server/driver] ...
参考: http ://www.yann.com/en/use-xvfb-selenium-and-chrome-to-drive-a-web-browser-in-php-23/08/2012.html
干杯!
根据SetEnvironmentProperty to ChromeDriver 以编程方式,您可以执行以下操作:
service = new ChromeDriverService.Builder()
.usingChromeDriverExecutable(new File("/path/to/chromedriver"))
.usingAnyFreePort()
.withEnvironment(ImmutableMap.of("DISPLAY",":20"))
.build();
我无法像使用 FirefoxBinary 一样为 ChromeDriver 找到以编程方式执行此操作的方法。
我已经提交了一个改进请求,其中附加了一个补丁来允许这样做。你可以在这里看到它:http ://code.google.com/p/selenium/issues/detail?id=2673
编辑:您可以在下面看到斯蒂芬关于如何使用它的回复,现在更改已合并。:https ://stackoverflow.com/a/16619608/998442
我明白你想要做什么,但你可能只是运行硒网格。它是为自动化浏览器测试而设计的。在服务器上工作得很好。