diff --git a/src/main/resources/templates/indexFunctions.ftl b/src/main/resources/templates/indexFunctions.ftl index c9b2888b5ca39dc0d7a476d3018655173ded89c8..c438cf124a6eb308cc67b4af1eb55e61ad700b7f 100644 --- a/src/main/resources/templates/indexFunctions.ftl +++ b/src/main/resources/templates/indexFunctions.ftl @@ -32,7 +32,7 @@ </#macro> <#macro firstUseBanner> - <div class="row"> + <div class="row" id="firstUseBanner"> <div class="col s12 center-align"> <div class="home-firstUseBanner-wrapper"> <div class="home-firstUseBanner text-color"> diff --git a/src/test/java/de/deadlocker8/budgetmaster/integration/helpers/IntegrationTestHelper.java b/src/test/java/de/deadlocker8/budgetmaster/integration/helpers/IntegrationTestHelper.java index 2b5217d66ae0f6228735742a428c69ec70215bca..66b275ba759677482b61a52863a7a18425c47e8a 100644 --- a/src/test/java/de/deadlocker8/budgetmaster/integration/helpers/IntegrationTestHelper.java +++ b/src/test/java/de/deadlocker8/budgetmaster/integration/helpers/IntegrationTestHelper.java @@ -3,6 +3,8 @@ package de.deadlocker8.budgetmaster.integration.helpers; import de.thecodelabs.utils.util.Localization; import org.junit.rules.TestName; import org.openqa.selenium.*; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; import java.io.File; import java.io.IOException; @@ -70,11 +72,14 @@ public class IntegrationTestHelper { try { + WebDriverWait wait = new WebDriverWait(driver, 2); + wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("modalWhatsNew"))); + WebElement buttonCloseReminder = driver.findElement(By.cssSelector("#modalWhatsNew #buttonCloseWhatsNew")); ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", buttonCloseReminder); buttonCloseReminder.click(); } - catch(NoSuchElementException ignored) + catch(NoSuchElementException | TimeoutException ignored) { } } diff --git a/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/FirstUseTest.java b/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/FirstUseTest.java new file mode 100644 index 0000000000000000000000000000000000000000..377659a5fd422509f6c6f3671dc4ac0a1bf96c67 --- /dev/null +++ b/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/FirstUseTest.java @@ -0,0 +1,105 @@ +package de.deadlocker8.budgetmaster.integration.selenium; + +import de.deadlocker8.budgetmaster.Main; +import de.deadlocker8.budgetmaster.authentication.UserService; +import de.deadlocker8.budgetmaster.integration.helpers.IntegrationTestHelper; +import de.deadlocker8.budgetmaster.integration.helpers.SeleniumTest; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TestName; +import org.junit.rules.TestWatcher; +import org.junit.runner.Description; +import org.junit.runner.RunWith; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.firefox.FirefoxOptions; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = Main.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) +@SeleniumTest +public class FirstUseTest +{ + private IntegrationTestHelper helper; + private WebDriver driver; + + @LocalServerPort + int port; + + @Rule + public TestName name = new TestName(); + + @Rule + public TestWatcher testWatcher = new TestWatcher() + { + @Override + protected void finished(Description description) + { + driver.quit(); + } + + @Override + protected void failed(Throwable e, Description description) + { + IntegrationTestHelper.saveScreenshots(driver, name, FirstUseTest.class); + } + }; + + @Before + public void prepare() + { + FirefoxOptions options = new FirefoxOptions(); + options.setHeadless(true); + driver = new FirefoxDriver(options); + + // prepare + helper = new IntegrationTestHelper(driver, port); + helper.start(); + helper.login(UserService.DEFAULT_PASSWORD); + helper.hideBackupReminder(); + helper.hideWhatsNewDialog(); + } + + @Test + public void test_firstUserBanner() + { + WebDriverWait wait = new WebDriverWait(driver, 5); + wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("firstUseBanner"))); + assertThat(driver.findElement(By.id("firstUseBanner")).isDisplayed()).isTrue(); + } + + @Test + public void test_firstUserBanner_dismiss() + { + WebDriverWait wait = new WebDriverWait(driver, 5); + wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("firstUseBanner"))); + + driver.findElements(By.className("home-firstUseBanner-clear")).get(0).click(); + + wait.until(ExpectedConditions.invisibilityOfElementLocated(By.id("firstUseBanner"))); + assertThat(driver.findElements(By.id("firstUseBanner"))).isEmpty(); + } + + @Test + public void test_firstUserBanner_click() + { + WebDriverWait wait = new WebDriverWait(driver, 5); + wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("firstUseBanner"))); + + driver.findElements(By.className("home-firstUseBanner")).get(0).click(); + + wait.until(ExpectedConditions.textToBePresentInElementLocated(By.cssSelector(".headline"), "First use guide")); + + assertThat(driver.getCurrentUrl()).endsWith("/firstUse"); + } +} \ No newline at end of file