parent
b2ca1903b8
commit
2b6d006fd0
@ -1,25 +1,73 @@ |
||||
package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.tests; |
||||
|
||||
import java.awt.GraphicsEnvironment; |
||||
import java.time.YearMonth; |
||||
import java.time.format.TextStyle; |
||||
import java.util.Locale; |
||||
|
||||
import org.hamcrest.Matchers; |
||||
import org.junit.jupiter.api.AfterEach; |
||||
import org.junit.jupiter.api.BeforeAll; |
||||
import org.junit.jupiter.api.BeforeEach; |
||||
import org.junit.jupiter.api.Test; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.openqa.selenium.By; |
||||
import org.openqa.selenium.WebDriver; |
||||
import org.openqa.selenium.WebElement; |
||||
import org.openqa.selenium.chrome.ChromeDriver; |
||||
import org.openqa.selenium.chrome.ChromeOptions; |
||||
import org.openqa.selenium.support.ui.WebDriverWait; |
||||
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient; |
||||
import org.springframework.boot.test.context.SpringBootTest; |
||||
import org.springframework.test.web.reactive.server.WebTestClient; |
||||
import org.springframework.boot.web.server.LocalServerPort; |
||||
|
||||
//@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) |
||||
@AutoConfigureWebTestClient |
||||
//@SpringApplicationConfiguration(classes = VaadinClubhelperApplication.class)
|
||||
//@WebAppConfiguration
|
||||
public class VaadinClubhelperApplicationTests { |
||||
|
||||
@Autowired |
||||
private WebTestClient webClient; |
||||
private static ChromeOptions options; |
||||
// @Autowired
|
||||
// private WebTestClient webClient;
|
||||
@LocalServerPort |
||||
int port; |
||||
|
||||
@Test |
||||
public void contextLoads() { |
||||
private WebDriver driver; |
||||
|
||||
@BeforeAll |
||||
static void setupDriverConfiguration() { |
||||
|
||||
if (System.getProperty("webdriver.chrome.driver") == null) { |
||||
System.setProperty("webdriver.chrome.driver", System.getenv("webdriver.chrome.driver")); |
||||
} |
||||
|
||||
options = new ChromeOptions(); |
||||
options.setHeadless(!GraphicsEnvironment.isHeadless()); |
||||
// options.setPageLoadStrategy(PageLoadStrategy.EAGER);
|
||||
|
||||
} |
||||
|
||||
webClient.get().uri("/").exchange().expectStatus().isOk().expectBody(String.class).isEqualTo("Hello World"); |
||||
@BeforeEach |
||||
void setUp() throws Exception { |
||||
driver = new ChromeDriver(options); |
||||
} |
||||
|
||||
@AfterEach |
||||
void shutdown() { |
||||
if (driver != null) { |
||||
driver.close(); |
||||
} |
||||
} |
||||
|
||||
@Test |
||||
public void seleniumWebWorkflow() { |
||||
WebDriverWait driverWait = new WebDriverWait(driver, 45L); |
||||
|
||||
driver.get("http://localhost:" + port); |
||||
|
||||
driverWait.until(dr -> dr.findElements(By.id("calendar.month")).size() > 0); |
||||
|
||||
WebElement monthLabel = driver.findElement(By.id("calendar.month")); |
||||
String month = monthLabel.getText(); |
||||
String expected = YearMonth.now().getMonth().getDisplayName(TextStyle.FULL_STANDALONE, Locale.getDefault()); |
||||
org.hamcrest.MatcherAssert.assertThat(month, Matchers.containsString(expected)); |
||||
} |
||||
} |
||||
|
||||
Loading…
Reference in new issue