There's a massive amount of postings on this topic, but for some reason, I've found little relating to Chrome (it seems the support was recently added for headless). The tests work running locally with a browser.
Is it possible to trigger an Xvfb display from Java so I can manage everything in one place? I'd rather not have to do:
Xvfb :1 -screen 0 1024x768x24 &
Via the command line. It'd be useful to run a display, then shut it down.
- SetEnvironmentProperty to ChromeDriver programatically is what I found to be the solution.
The problem? I can't get it to work on an Ubuntu machine.
The error I receive is:
/home/ubuntu/myproject/conf/chromedriver: 1: Syntax error: Unterminated quoted string
The test class I'm using:
import java.io.File;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeDriverService;
import play.Logger;
import utils.LocalInfo;
import com.google.common.collect.ImmutableMap;
public class TestCI {
private WebDriver driver;
@SuppressWarnings("deprecation")
public TestCI(String url) {
if (!LocalInfo.isEC2()) {
Logger.info("Running tests by opening a browser...");
System.setProperty("webdriver.chrome.driver", "conf/chromedriver");
setWebDriver(new ChromeDriver());
} else {
Logger.info("Running tests headlessly...");
String xPort = System.getProperty("Importal.xvfb.id", ":1");
ChromeDriverService service = new ChromeDriverService.Builder()
.usingChromeDriverExecutable(new File("conf/chromedriver"))
.usingAnyFreePort()
.withEnvironment(ImmutableMap.of("DISPLAY", xPort)).build();
setWebDriver(new ChromeDriver(service));
}
getWebDriver().get("http://www.google.com");
try {
someUITest();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
getWebDriver().close();
}
public WebDriver getWebDriver() {
return driver;
}
public void setWebDriver(ChromeDriver driver) {
this.driver = driver;
}
public void someUITest() throws Exception {
getWebDriver().findElement(By.name("q"));
}
}