From 2b6d006fd0baca0d2980053672ee8465fa867811 Mon Sep 17 00:00:00 2001 From: Markus Kreth Date: Sun, 16 Dec 2018 23:41:26 +0100 Subject: [PATCH] First UI Test --- pom.xml | 41 +++++++++-- .../vaadinclubhelper/ui/MainUi.java | 4 +- .../ui/components/CalendarComponent.java | 3 + .../ui/components/PersonGrid.java | 5 ++ .../VaadinClubhelperApplicationTests.java | 68 ++++++++++++++++--- 5 files changed, 105 insertions(+), 16 deletions(-) diff --git a/pom.xml b/pom.xml index 5c07b00..99cadc3 100644 --- a/pom.xml +++ b/pom.xml @@ -28,6 +28,7 @@ UTF-8 11 8.6.2 + 3.141.59 1.23.0 v4-rev488-1.23.0 v3-rev271-1.23.0 @@ -100,6 +101,12 @@ com.google.apis google-api-services-calendar ${google-api-calendar-version} + + + com.google.guava + guava-jdk5 + + com.google.api-client @@ -126,6 +133,11 @@ commons-io 2.6 + + com.google.guava + guava + 22.0 + org.slf4j slf4j-api @@ -144,11 +156,11 @@ spring-boot-starter-test test - - org.springframework.security - spring-security-test - test - + + + + + org.springframework.boot spring-boot-starter-webflux @@ -160,6 +172,25 @@ test + + org.seleniumhq.selenium + selenium-server + ${selenium.version} + test + + + org.seleniumhq.selenium + selenium-java + ${selenium.version} + test + + + com.google.code.gson + gson + 2.8.2 + test + + simple-jndi simple-jndi diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/MainUi.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/MainUi.java index 5123848..d30d94a 100644 --- a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/MainUi.java +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/MainUi.java @@ -54,10 +54,11 @@ public class MainUi extends UI { @Override protected void init(VaadinRequest request) { - LOGGER.debug("Starting Vaadin UI with " + getClass().getName()); + LOGGER.debug("Starting Vaadin UI with {}", getClass().getName()); List persons = personDao.listAll(); personGrid = new PersonGrid(groupDao); + personGrid.setId("main.person"); personGrid.setItems(persons); personGrid.setCaption("Personen"); personGrid.onClosedFunction(() -> detailClosed()); @@ -65,6 +66,7 @@ public class MainUi extends UI { personGrid.onPersonEdit(p -> onPersonEdit(p)); this.calendar = new CalendarComponent(); + calendar.setId("main.calendar"); calendar.setHandler(this::onItemClick); contentLayout = new HorizontalLayout(); diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/CalendarComponent.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/CalendarComponent.java index bbabeda..8548c17 100644 --- a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/CalendarComponent.java +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/CalendarComponent.java @@ -59,15 +59,18 @@ public class CalendarComponent extends CustomComponent { public CalendarComponent() { monthName = new Label(); + monthName.setId("calendar.month"); monthName.setStyleName("title_label"); Button popupButton = new Button("Menu"); + popupButton.setId("calendar.menu"); popupButton.addClickListener(ev -> openPopupMenu(ev)); HorizontalLayout head = new HorizontalLayout(monthName, popupButton); dataProvider = new ClubEventProvider(); calendar = new Calendar<>(dataProvider).withMonth(Month.from(LocalDateTime.now())); + calendar.setId("calendar.calendar"); calendar.setCaption("Events"); calendar.setSizeFull(); calendar.addListener(ev -> calendarEvent(ev)); diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/PersonGrid.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/PersonGrid.java index 959b67b..2018b8a 100644 --- a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/PersonGrid.java +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/PersonGrid.java @@ -61,14 +61,17 @@ public class PersonGrid extends CustomComponent { public PersonGrid(GroupDao groupDao) { textTitle = new TextField(); + textTitle.setId("person.title"); textTitle.setStyleName("title_label"); textTitle.setCaption("Veranstaltung"); textTitle.setEnabled(false); textTitle.setSizeFull(); checkIncluded = new CheckBox("Nur gemeldete"); + checkIncluded.setId("person.filter.checked"); checkIncluded.addValueChangeListener(ev -> onSelectedOnly(ev)); comboGroups = new ComboBox<>("Gruppenfilter"); + comboGroups.setId("person.filter.groups"); comboGroups.setEmptySelectionAllowed(true); comboGroups.setEmptySelectionCaption("Alle"); comboGroups.setItemCaptionGenerator(GroupDef::getName); @@ -82,6 +85,7 @@ public class PersonGrid extends CustomComponent { dataProvider = new ListDataProvider(new ArrayList<>()).withConfigurableFilter(); grid = new Grid<>(); grid.setDataProvider(dataProvider); + grid.setId("person.grid"); grid.addColumn(Person::getPrename).setCaption("Vorname"); grid.addColumn(Person::getSurname).setCaption("Nachname"); grid.addColumn(Person::getBirth, b -> b != null ? birthFormat.format(b) : "").setCaption("Geburtstag"); @@ -94,6 +98,7 @@ public class PersonGrid extends CustomComponent { closedFunction.closed(); } }); + close.setId("person.close"); VerticalLayout panel = new VerticalLayout(); panel.addComponents(textTitle, filters, grid, close); diff --git a/src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/tests/VaadinClubhelperApplicationTests.java b/src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/tests/VaadinClubhelperApplicationTests.java index 7432de4..ed6be79 100644 --- a/src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/tests/VaadinClubhelperApplicationTests.java +++ b/src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/tests/VaadinClubhelperApplicationTests.java @@ -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)); + } }