Skip to content

Commit

Permalink
Merge pull request #65 from automate-website/#64-chrome-headless
Browse files Browse the repository at this point in the history
Added support for Chrome headless (#64)
  • Loading branch information
build-failure authored Jul 9, 2017
2 parents dc6359c + 36e55c5 commit 2aed3b7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,22 @@ public class WebDriverProvider {

public WebDriver createInstance(Type type) {
switch (type) {
case FIREFOX:
return new FirefoxDriver();
case CHROME:
return new ChromeDriver();
case CHROME_HEADLESS:
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless", "--disable-gpu");
ChromeDriver chromeDriver = new ChromeDriver(options);

return chromeDriver;
case OPERA:
return new OperaDriver(getOperaCapabilities());
case FIREFOX:
default:
throw new RuntimeException("Unsupported web driver type.");
return new FirefoxDriver();
}
}

private DesiredCapabilities getOperaCapabilities(){
DesiredCapabilities capabilities = DesiredCapabilities.operaBlink();
String operaBinaryPath = System.getProperty("webdriver.opera.binary");
Expand All @@ -34,16 +39,21 @@ private DesiredCapabilities getOperaCapabilities(){
}

public enum Type {
FIREFOX,
CHROME,
OPERA;
FIREFOX("firefox"),
CHROME("chrome"),
CHROME_HEADLESS("chrome-headless"),
OPERA("opera");

private final String canonicalName;

Type(String canonicalName) {
this.canonicalName = canonicalName;
}

public static Type fromString(String typeString) {
if (typeString != null) {
for (Type type : Type.values()) {
if (typeString.equalsIgnoreCase(type.name())) {
return type;
}
for (Type type : Type.values()) {
if (type.canonicalName.equalsIgnoreCase(typeString)) {
return type;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package website.automate.jwebrobot;

public interface ChromeHeadlessTests extends ChromeTests {
}
10 changes: 10 additions & 0 deletions src/test/java/website/automate/jwebrobot/JWebRobotIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,14 @@ public void simpleScenarioShouldBeExecutedWithChrome() {
"-browser", "chrome"
});
}

@Ignore
@Test
@Category(ChromeHeadlessTests.class)
public void simpleScenarioShouldBeExecutedWithChromeHeadless() {
JWebRobot.main(new String [] {
"-" + SCENARIO_PATH_PARAM_NAME, ROOT_PACKAGE_DIRECTORY_PATH + "wikipedia-test.yaml",
"-browser", "chrome-headless"
});
}
}

0 comments on commit 2aed3b7

Please sign in to comment.