diff --git a/src/test/java/com/vaadin/testbenchexample/AbstractIT.java b/src/test/java/com/vaadin/testbenchexample/AbstractIT.java index c5185d2..403bfd8 100644 --- a/src/test/java/com/vaadin/testbenchexample/AbstractIT.java +++ b/src/test/java/com/vaadin/testbenchexample/AbstractIT.java @@ -3,9 +3,11 @@ import org.junit.Before; import org.junit.Rule; import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.chrome.ChromeOptions; import com.vaadin.testbench.IPAddress; import com.vaadin.testbench.ScreenshotOnFailureRule; +import com.vaadin.testbench.TestBench; import com.vaadin.testbench.TestBenchTestCase; /** @@ -20,7 +22,11 @@ public abstract class AbstractIT extends TestBenchTestCase { @Before public void setUp() throws Exception { - setDriver(new ChromeDriver()); + ChromeOptions options = new ChromeOptions(); + if (Boolean.getBoolean("com.vaadin.testbench.Parameters.headless")) { + options.addArguments("--headless"); + } + setDriver(TestBench.createDriver(new ChromeDriver(options))); getDriver().get("http://" + IPAddress.findSiteLocalAddress() + ":8080"); getCommandExecutor().waitForVaadin(); } diff --git a/src/test/java/com/vaadin/testbenchexample/junit5/AbstractJUnit5IT.java b/src/test/java/com/vaadin/testbenchexample/junit5/AbstractJUnit5IT.java index 21da9d5..be50e2b 100644 --- a/src/test/java/com/vaadin/testbenchexample/junit5/AbstractJUnit5IT.java +++ b/src/test/java/com/vaadin/testbenchexample/junit5/AbstractJUnit5IT.java @@ -5,12 +5,14 @@ import org.junit.jupiter.api.BeforeEach; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.chrome.ChromeOptions; import com.vaadin.flow.component.button.testbench.ButtonElement; import com.vaadin.flow.component.textfield.testbench.TextFieldElement; import com.vaadin.testbench.BrowserTestBase; import com.vaadin.testbench.DriverSupplier; import com.vaadin.testbench.IPAddress; +import com.vaadin.testbench.TestBench; /** * Base class for all our JUnit5 tests, allowing us to change the applicable driver, @@ -20,7 +22,11 @@ public abstract class AbstractJUnit5IT extends BrowserTestBase implements Driver @Override public WebDriver createDriver() { - return new ChromeDriver(); + ChromeOptions options = new ChromeOptions(); + if (Boolean.getBoolean("com.vaadin.testbench.Parameters.headless")) { + options.addArguments("--headless"); + } + return TestBench.createDriver(new ChromeDriver(options)); } @BeforeEach diff --git a/src/test/java/com/vaadin/testbenchexample/junit5/SimpleCaseSeleniumIT.java b/src/test/java/com/vaadin/testbenchexample/junit5/SimpleCaseSeleniumIT.java index 9ac723c..e66647f 100644 --- a/src/test/java/com/vaadin/testbenchexample/junit5/SimpleCaseSeleniumIT.java +++ b/src/test/java/com/vaadin/testbenchexample/junit5/SimpleCaseSeleniumIT.java @@ -1,5 +1,6 @@ package com.vaadin.testbenchexample.junit5; +import io.github.bonigarcia.seljup.Arguments; import io.github.bonigarcia.seljup.SeleniumJupiter; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -15,6 +16,7 @@ import com.vaadin.testbench.IPAddress; import com.vaadin.testbench.TestBench; + /** * This example shows how to use SeleniumJupiter together with TestBench. * Developer should remember to wrap driver for enabling TestBench features. @@ -25,7 +27,8 @@ public class SimpleCaseSeleniumIT implements HasElementQuery { private WebDriver driver; @BeforeEach - public void beforeEach(ChromeDriver driver) { // driver injection by Selenium + + public void beforeEach(@Arguments("--headless") ChromeDriver driver) { // driver injection by Selenium this.driver = TestBench.createDriver(driver); // TestBench driver proxy this.driver.get("http://" + IPAddress.findSiteLocalAddress() + ":8080"); }