First UI Test

master
Markus Kreth 7 years ago
parent b2ca1903b8
commit 2b6d006fd0
  1. 41
      pom.xml
  2. 4
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/MainUi.java
  3. 3
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/CalendarComponent.java
  4. 5
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/PersonGrid.java
  5. 68
      src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/tests/VaadinClubhelperApplicationTests.java

@ -28,6 +28,7 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>11</java.version> <java.version>11</java.version>
<vaadin.version>8.6.2</vaadin.version> <vaadin.version>8.6.2</vaadin.version>
<selenium.version>3.141.59</selenium.version>
<google-api-version>1.23.0</google-api-version> <google-api-version>1.23.0</google-api-version>
<google-api-sheets-version>v4-rev488-1.23.0</google-api-sheets-version> <google-api-sheets-version>v4-rev488-1.23.0</google-api-sheets-version>
<google-api-calendar-version>v3-rev271-1.23.0</google-api-calendar-version> <google-api-calendar-version>v3-rev271-1.23.0</google-api-calendar-version>
@ -100,6 +101,12 @@
<groupId>com.google.apis</groupId> <groupId>com.google.apis</groupId>
<artifactId>google-api-services-calendar</artifactId> <artifactId>google-api-services-calendar</artifactId>
<version>${google-api-calendar-version}</version> <version>${google-api-calendar-version}</version>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava-jdk5</artifactId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.google.api-client</groupId> <groupId>com.google.api-client</groupId>
@ -126,6 +133,11 @@
<artifactId>commons-io</artifactId> <artifactId>commons-io</artifactId>
<version>2.6</version> <version>2.6</version>
</dependency> </dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>22.0</version>
</dependency>
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId> <artifactId>slf4j-api</artifactId>
@ -144,11 +156,11 @@
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <!-- <dependency> -->
<groupId>org.springframework.security</groupId> <!-- <groupId>org.springframework.security</groupId> -->
<artifactId>spring-security-test</artifactId> <!-- <artifactId>spring-security-test</artifactId> -->
<scope>test</scope> <!-- <scope>test</scope> -->
</dependency> <!-- </dependency> -->
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId> <artifactId>spring-boot-starter-webflux</artifactId>
@ -160,6 +172,25 @@
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>${selenium.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${selenium.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.2</version>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>simple-jndi</groupId> <groupId>simple-jndi</groupId>
<artifactId>simple-jndi</artifactId> <artifactId>simple-jndi</artifactId>

@ -54,10 +54,11 @@ public class MainUi extends UI {
@Override @Override
protected void init(VaadinRequest request) { protected void init(VaadinRequest request) {
LOGGER.debug("Starting Vaadin UI with " + getClass().getName()); LOGGER.debug("Starting Vaadin UI with {}", getClass().getName());
List<Person> persons = personDao.listAll(); List<Person> persons = personDao.listAll();
personGrid = new PersonGrid(groupDao); personGrid = new PersonGrid(groupDao);
personGrid.setId("main.person");
personGrid.setItems(persons); personGrid.setItems(persons);
personGrid.setCaption("Personen"); personGrid.setCaption("Personen");
personGrid.onClosedFunction(() -> detailClosed()); personGrid.onClosedFunction(() -> detailClosed());
@ -65,6 +66,7 @@ public class MainUi extends UI {
personGrid.onPersonEdit(p -> onPersonEdit(p)); personGrid.onPersonEdit(p -> onPersonEdit(p));
this.calendar = new CalendarComponent(); this.calendar = new CalendarComponent();
calendar.setId("main.calendar");
calendar.setHandler(this::onItemClick); calendar.setHandler(this::onItemClick);
contentLayout = new HorizontalLayout(); contentLayout = new HorizontalLayout();

@ -59,15 +59,18 @@ public class CalendarComponent extends CustomComponent {
public CalendarComponent() { public CalendarComponent() {
monthName = new Label(); monthName = new Label();
monthName.setId("calendar.month");
monthName.setStyleName("title_label"); monthName.setStyleName("title_label");
Button popupButton = new Button("Menu"); Button popupButton = new Button("Menu");
popupButton.setId("calendar.menu");
popupButton.addClickListener(ev -> openPopupMenu(ev)); popupButton.addClickListener(ev -> openPopupMenu(ev));
HorizontalLayout head = new HorizontalLayout(monthName, popupButton); HorizontalLayout head = new HorizontalLayout(monthName, popupButton);
dataProvider = new ClubEventProvider(); dataProvider = new ClubEventProvider();
calendar = new Calendar<>(dataProvider).withMonth(Month.from(LocalDateTime.now())); calendar = new Calendar<>(dataProvider).withMonth(Month.from(LocalDateTime.now()));
calendar.setId("calendar.calendar");
calendar.setCaption("Events"); calendar.setCaption("Events");
calendar.setSizeFull(); calendar.setSizeFull();
calendar.addListener(ev -> calendarEvent(ev)); calendar.addListener(ev -> calendarEvent(ev));

@ -61,14 +61,17 @@ public class PersonGrid extends CustomComponent {
public PersonGrid(GroupDao groupDao) { public PersonGrid(GroupDao groupDao) {
textTitle = new TextField(); textTitle = new TextField();
textTitle.setId("person.title");
textTitle.setStyleName("title_label"); textTitle.setStyleName("title_label");
textTitle.setCaption("Veranstaltung"); textTitle.setCaption("Veranstaltung");
textTitle.setEnabled(false); textTitle.setEnabled(false);
textTitle.setSizeFull(); textTitle.setSizeFull();
checkIncluded = new CheckBox("Nur gemeldete"); checkIncluded = new CheckBox("Nur gemeldete");
checkIncluded.setId("person.filter.checked");
checkIncluded.addValueChangeListener(ev -> onSelectedOnly(ev)); checkIncluded.addValueChangeListener(ev -> onSelectedOnly(ev));
comboGroups = new ComboBox<>("Gruppenfilter"); comboGroups = new ComboBox<>("Gruppenfilter");
comboGroups.setId("person.filter.groups");
comboGroups.setEmptySelectionAllowed(true); comboGroups.setEmptySelectionAllowed(true);
comboGroups.setEmptySelectionCaption("Alle"); comboGroups.setEmptySelectionCaption("Alle");
comboGroups.setItemCaptionGenerator(GroupDef::getName); comboGroups.setItemCaptionGenerator(GroupDef::getName);
@ -82,6 +85,7 @@ public class PersonGrid extends CustomComponent {
dataProvider = new ListDataProvider<Person>(new ArrayList<>()).withConfigurableFilter(); dataProvider = new ListDataProvider<Person>(new ArrayList<>()).withConfigurableFilter();
grid = new Grid<>(); grid = new Grid<>();
grid.setDataProvider(dataProvider); grid.setDataProvider(dataProvider);
grid.setId("person.grid");
grid.addColumn(Person::getPrename).setCaption("Vorname"); grid.addColumn(Person::getPrename).setCaption("Vorname");
grid.addColumn(Person::getSurname).setCaption("Nachname"); grid.addColumn(Person::getSurname).setCaption("Nachname");
grid.addColumn(Person::getBirth, b -> b != null ? birthFormat.format(b) : "").setCaption("Geburtstag"); grid.addColumn(Person::getBirth, b -> b != null ? birthFormat.format(b) : "").setCaption("Geburtstag");
@ -94,6 +98,7 @@ public class PersonGrid extends CustomComponent {
closedFunction.closed(); closedFunction.closed();
} }
}); });
close.setId("person.close");
VerticalLayout panel = new VerticalLayout(); VerticalLayout panel = new VerticalLayout();
panel.addComponents(textTitle, filters, grid, close); panel.addComponents(textTitle, filters, grid, close);

@ -1,25 +1,73 @@
package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.tests; 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.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.autoconfigure.web.reactive.AutoConfigureWebTestClient;
import org.springframework.boot.test.context.SpringBootTest; 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) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureWebTestClient @AutoConfigureWebTestClient
//@SpringApplicationConfiguration(classes = VaadinClubhelperApplication.class)
//@WebAppConfiguration
public class VaadinClubhelperApplicationTests { public class VaadinClubhelperApplicationTests {
@Autowired private static ChromeOptions options;
private WebTestClient webClient; // @Autowired
// private WebTestClient webClient;
@LocalServerPort
int port;
@Test private WebDriver driver;
public void contextLoads() {
@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…
Cancel
Save