Skip to content

Commit

Permalink
chore: allow running tests in headless mode
Browse files Browse the repository at this point in the history
  • Loading branch information
manolo committed Aug 6, 2023
1 parent 0b7b742 commit e406b0d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/test/java/com/vaadin/testbenchexample/AbstractIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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.
Expand All @@ -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");
}
Expand Down

0 comments on commit e406b0d

Please sign in to comment.