1
这里运行在Chrome司机无头模式是我的镀铬驱动程序代码: -如何使用Java
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
,然后开始了我的JUnit测试in Intellij
如何在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());
有没有办法修改现有的selenium代码并在AWS实例或本地机器中使用它? – karan
@karan yes它允许您从selenium和testng导入代码 – AaronBDC
我想在无头的AWS ec2实例中运行我的junit。我希望它不会帮助我做到这一点。 RedwoodHQ在用户界面中打开。 – karan