【发布时间】:2017-06-27 05:47:43
【问题描述】:
这是我的 chrome 驱动程序代码:-
String driverPath = driverFile.getAbsolutePath();
System.setProperty("webdriver.chrome.driver", driverPath);
Callable<ChromeDriver> startChromedriver = new Callable<ChromeDriver>() {
public ChromeDriver call() {
ChromeOptions Chromeoptions = new ChromeOptions();
Chromeoptions.addArguments("--startMaximized");
caps.setCapability("newCommandTimeout", 300);
caps.setCapability(ChromeOptions.CAPABILITY, Chromeoptions);
return new ChromeDriver(caps);
}
};
我已经在终端启动了以下内容:-
Xvfb -ac :99 -screen 0 1280x1024x16 &
export DISPLAY=:99
然后在 Intellij 中开始我的 Junit 测试
如何在 ubuntu 机器上使用 chrome 驱动在 java 中运行 junit 测试?
对于 Firefox,我已经尝试过了,它的工作原理。
apt-get update
sudo apt-get install xvfb
sudo apt-get install -y xorg xvfb dbus-x11 xfonts-100dpi xfonts-75dpi xfonts-cyrillic
sudo Xvfb :2 -ac
export DISPLAY=:2
Firefox 中的设置
// Setup firefox binary to start in Xvfb
String Xport = System.getProperty(
"lmportal.xvfb.id", ":2");
final File firefoxPath = new File(System.getProperty(
"lmportal.deploy.firefox.path", "/usr/bin/firefox"));
FirefoxBinary firefoxBinary = new FirefoxBinary(firefoxPath);
firefoxBinary.setEnvironmentProperty("DISPLAY", Xport);
// Start Firefox driver
WebDriver driver = new FirefoxDriver(firefoxBinary, null);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get("http://google.com/");
System.out.println("page source" + driver.getCurrentUrl());
【问题讨论】:
标签: java google-chrome selenium junit headless