diff --git a/src/test/java/de/deadlocker8/budgetmaster/integration/DateRepairTest.java b/src/test/java/de/deadlocker8/budgetmaster/integration/DateRepairTest.java index b665d072c97fa9092d98c3c33726d19a631238b5..81b76d44ab67909abb7040475e2f02c359929bcf 100644 --- a/src/test/java/de/deadlocker8/budgetmaster/integration/DateRepairTest.java +++ b/src/test/java/de/deadlocker8/budgetmaster/integration/DateRepairTest.java @@ -5,8 +5,7 @@ import de.deadlocker8.budgetmaster.integration.helpers.SeleniumTest; import de.deadlocker8.budgetmaster.tags.Tag; import de.deadlocker8.budgetmaster.transactions.Transaction; import de.deadlocker8.budgetmaster.transactions.TransactionRepository; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.jdbc.DataSourceBuilder; @@ -22,19 +21,17 @@ import org.springframework.transaction.annotation.Transactional; import javax.sql.DataSource; import java.io.IOException; -import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; import static org.assertj.core.api.Assertions.assertThat; -@RunWith(SpringRunner.class) @SpringBootTest(classes = Main.class) @Import(DateRepairTest.TestDatabaseConfiguration.class) @ActiveProfiles("test") @SeleniumTest @Transactional -public class DateRepairTest +class DateRepairTest { @TestConfiguration static class TestDatabaseConfiguration @@ -56,7 +53,7 @@ public class DateRepairTest private TransactionRepository transactionRepository; @Test - public void test_Repeating_WithTags() + void test_Repeating_WithTags() { final List<Transaction> transactions = transactionRepository.findAll(); assertThat(transactions).hasSize(8); @@ -69,7 +66,7 @@ public class DateRepairTest } @Test - public void test_Repeating() + void test_Repeating() { final List<Transaction> transactions = transactionRepository.findAll(); assertThat(transactions).hasSize(8); 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 4121b582dce4d9bb00c3650d31b0d0979ac4552f..13c628764ebc7e39a6f6ee0b63c7e3bb7e235065 100644 --- a/src/test/java/de/deadlocker8/budgetmaster/integration/helpers/IntegrationTestHelper.java +++ b/src/test/java/de/deadlocker8/budgetmaster/integration/helpers/IntegrationTestHelper.java @@ -3,7 +3,6 @@ package de.deadlocker8.budgetmaster.integration.helpers; import de.deadlocker8.budgetmaster.accounts.Account; import de.deadlocker8.budgetmaster.accounts.AccountState; 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; @@ -196,12 +195,10 @@ public class IntegrationTestHelper } } - public static void saveScreenshots(WebDriver webDriver, TestName testName, Class testClass) + public static void saveScreenshots(WebDriver webDriver, String methodName, String className) { File screenshot = ((TakesScreenshot) webDriver).getScreenshotAs(OutputType.FILE); - String className = testClass.getSimpleName(); - String methodName = testName.getMethodName(); final Path destination = Paths.get("screenshots", className + "_" + methodName + "_" + screenshot.getName()); try diff --git a/src/test/java/de/deadlocker8/budgetmaster/integration/helpers/SeleniumTestBase.java b/src/test/java/de/deadlocker8/budgetmaster/integration/helpers/SeleniumTestBase.java new file mode 100644 index 0000000000000000000000000000000000000000..5c3a9432f6591e7b5d7aaf9ed0ce09d977afa010 --- /dev/null +++ b/src/test/java/de/deadlocker8/budgetmaster/integration/helpers/SeleniumTestBase.java @@ -0,0 +1,30 @@ +package de.deadlocker8.budgetmaster.integration.helpers; + +import org.junit.jupiter.api.BeforeEach; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.firefox.FirefoxOptions; +import org.springframework.boot.web.server.LocalServerPort; + +public class SeleniumTestBase +{ + protected WebDriver driver; + + @LocalServerPort + protected int port; + + @BeforeEach + public final void init() + { + FirefoxOptions options = new FirefoxOptions(); + options.setHeadless(false); + options.addPreference("devtools.console.stdout.content", true); + driver = new FirefoxDriver(options); + driver.manage().window().maximize(); + } + + public WebDriver getDriver() + { + return driver; + } +} diff --git a/src/test/java/de/deadlocker8/budgetmaster/integration/helpers/SeleniumTestWatcher.java b/src/test/java/de/deadlocker8/budgetmaster/integration/helpers/SeleniumTestWatcher.java new file mode 100644 index 0000000000000000000000000000000000000000..f802c3c9deb5d3810011f9d0a02e80cbb99e1258 --- /dev/null +++ b/src/test/java/de/deadlocker8/budgetmaster/integration/helpers/SeleniumTestWatcher.java @@ -0,0 +1,36 @@ +package de.deadlocker8.budgetmaster.integration.helpers; + +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.api.extension.TestWatcher; +import org.openqa.selenium.WebDriver; + +public class SeleniumTestWatcher implements TestWatcher +{ + @Override + public void testSuccessful(ExtensionContext context) + { + final WebDriver driver = getDriver(context); + driver.quit(); + } + + @Override + public void testAborted(ExtensionContext context, Throwable cause) + { + final WebDriver driver = getDriver(context); + driver.quit(); + } + + @Override + public void testFailed(ExtensionContext context, Throwable cause) + { + final WebDriver driver = getDriver(context); + IntegrationTestHelper.saveScreenshots(driver, context.getRequiredTestMethod().getName(), context.getRequiredTestClass().getSimpleName()); + driver.quit(); + } + + private WebDriver getDriver(ExtensionContext context) + { + final SeleniumTestBase testInstance = (SeleniumTestBase) context.getRequiredTestInstance(); + return testInstance.getDriver(); + } +} diff --git a/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/AccountTest.java b/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/AccountTest.java index 0c2823b26545ed2ca28915d40b314b2eb7a9c9cd..f5175aeb060bcf1ab7e215d1826cbe6124722553 100644 --- a/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/AccountTest.java +++ b/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/AccountTest.java @@ -5,16 +5,13 @@ import de.deadlocker8.budgetmaster.accounts.Account; import de.deadlocker8.budgetmaster.accounts.AccountState; import de.deadlocker8.budgetmaster.accounts.AccountType; import de.deadlocker8.budgetmaster.authentication.UserService; -import de.deadlocker8.budgetmaster.integration.helpers.IntegrationTestHelper; -import de.deadlocker8.budgetmaster.integration.helpers.SeleniumTest; -import de.deadlocker8.budgetmaster.integration.helpers.TransactionTestHelper; -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 de.deadlocker8.budgetmaster.integration.helpers.*; +import de.deadlocker8.budgetmaster.search.Search; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.api.extension.TestWatcher; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; @@ -26,7 +23,6 @@ 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 java.io.File; import java.util.Arrays; @@ -35,46 +31,17 @@ import java.util.stream.Collectors; import static org.assertj.core.api.Assertions.assertThat; -@RunWith(SpringRunner.class) +@ExtendWith(SeleniumTestWatcher.class) @SpringBootTest(classes = Main.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) @SeleniumTest -public class AccountTest +class AccountTest extends SeleniumTestBase { 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, AccountTest.class); - } - }; - - @Before + @BeforeEach() public void prepare() { - FirefoxOptions options = new FirefoxOptions(); - options.setHeadless(false); - options.addPreference("devtools.console.stdout.content", true); - driver = new FirefoxDriver(options); - - // prepare helper = new IntegrationTestHelper(driver, port); helper.start(); helper.login(UserService.DEFAULT_PASSWORD); @@ -96,7 +63,7 @@ public class AccountTest } @Test - public void test_newAccount_cancel() + void test_newAccount_cancel() { driver.get(helper.getUrl() + "/accounts"); driver.findElement(By.id("button-new-account")).click(); @@ -117,7 +84,7 @@ public class AccountTest } @Test - public void test_newAccount() + void test_newAccount() { driver.get(helper.getUrl() + "/accounts"); driver.findElement(By.id("button-new-account")).click(); @@ -149,7 +116,7 @@ public class AccountTest } @Test - public void test_edit() + void test_edit() { driver.get(helper.getUrl() + "/accounts/2/edit"); @@ -158,7 +125,7 @@ public class AccountTest } @Test - public void test_readOnly_newTransaction_listOnlyReadableAccounts() + void test_readOnly_newTransaction_listOnlyReadableAccounts() { driver.get(helper.getUrl() + "/transactions"); driver.findElement(By.id("button-new-transaction")).click(); @@ -180,7 +147,7 @@ public class AccountTest } @Test - public void test_readOnly_preventTransactionDeleteAndEdit() + void test_readOnly_preventTransactionDeleteAndEdit() { // select "sfsdf" TransactionTestHelper.selectGlobalAccountByName(driver, "sfsdf"); @@ -226,7 +193,7 @@ public class AccountTest } @Test - public void test_readOnly_preventNewTransaction() + void test_readOnly_preventNewTransaction() { TransactionTestHelper.selectGlobalAccountByName(driver, "read only account"); diff --git a/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/CategorySelectTest.java b/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/CategorySelectTest.java index 6d3c9eee3ee11cc6425bf3df43fa3d6d5ca00338..e1324c9a3dc05da67eb72e9dcfccd2c5f63d9be2 100644 --- a/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/CategorySelectTest.java +++ b/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/CategorySelectTest.java @@ -6,25 +6,16 @@ import de.deadlocker8.budgetmaster.accounts.AccountType; 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 de.deadlocker8.budgetmaster.integration.helpers.SeleniumTestBase; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openqa.selenium.By; import org.openqa.selenium.Keys; -import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; -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 java.io.File; import java.util.Arrays; @@ -32,46 +23,16 @@ import java.util.List; 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 CategorySelectTest +class CategorySelectTest extends SeleniumTestBase { 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, CategorySelectTest.class); - } - }; - - @Before + @BeforeEach public void prepare() { - FirefoxOptions options = new FirefoxOptions(); - options.setHeadless(false); - options.addPreference("devtools.console.stdout.content", true); - driver = new FirefoxDriver(options); - - // prepare helper = new IntegrationTestHelper(driver, port); helper.start(); helper.login(UserService.DEFAULT_PASSWORD); @@ -99,7 +60,7 @@ public class CategorySelectTest } @Test - public void test_newTransaction_openWithEnter() + void test_newTransaction_openWithEnter() { // navigate to category select with tab traversal driver.findElement(By.tagName("body")).sendKeys(Keys.TAB); @@ -121,7 +82,7 @@ public class CategorySelectTest } @Test - public void test_newTransaction_goDownWithKey() + void test_newTransaction_goDownWithKey() { // open category select driver.findElement(By.cssSelector(".category-select-wrapper .custom-select-trigger")).click(); @@ -150,7 +111,7 @@ public class CategorySelectTest } @Test - public void test_newTransaction_goUpWithKey() + void test_newTransaction_goUpWithKey() { // open category select driver.findElement(By.cssSelector(".category-select-wrapper .custom-select-trigger")).click(); @@ -179,7 +140,7 @@ public class CategorySelectTest } @Test - public void test_newTransaction_confirmWithEnter() + void test_newTransaction_confirmWithEnter() { // open category select driver.findElement(By.cssSelector(".category-select-wrapper .custom-select-trigger")).click(); @@ -199,7 +160,7 @@ public class CategorySelectTest } @Test - public void test_newTransaction_jumpToCategoryByFirstLetter() + void test_newTransaction_jumpToCategoryByFirstLetter() { // open category select driver.findElement(By.cssSelector(".category-select-wrapper .custom-select-trigger")).click(); diff --git a/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/ChangeTransactionTypeTest.java b/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/ChangeTransactionTypeTest.java index c1c1781a0c8138d60cb32cc7c89e9840cd657281..b8e5c4721177e137bffc0eef746c36a7ff6af137 100644 --- a/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/ChangeTransactionTypeTest.java +++ b/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/ChangeTransactionTypeTest.java @@ -4,29 +4,18 @@ import de.deadlocker8.budgetmaster.Main; import de.deadlocker8.budgetmaster.accounts.Account; import de.deadlocker8.budgetmaster.accounts.AccountType; import de.deadlocker8.budgetmaster.authentication.UserService; -import de.deadlocker8.budgetmaster.integration.helpers.IntegrationTestHelper; -import de.deadlocker8.budgetmaster.integration.helpers.SeleniumTest; -import de.deadlocker8.budgetmaster.integration.helpers.TransactionTestHelper; -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 de.deadlocker8.budgetmaster.integration.helpers.*; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.openqa.selenium.By; import org.openqa.selenium.NoSuchElementException; -import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; -import org.openqa.selenium.firefox.FirefoxDriver; -import org.openqa.selenium.firefox.FirefoxOptions; import org.openqa.selenium.interactions.Actions; 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 java.io.File; import java.util.Arrays; @@ -35,36 +24,13 @@ import java.util.List; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -@RunWith(SpringRunner.class) +@ExtendWith(SeleniumTestWatcher.class) @SpringBootTest(classes = Main.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) @SeleniumTest -public class ChangeTransactionTypeTest +class ChangeTransactionTypeTest extends SeleniumTestBase { 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, ChangeTransactionTypeTest.class); - } - }; private void openTransferTypeModal(int transactionID) { @@ -85,15 +51,9 @@ public class ChangeTransactionTypeTest assertThat(driver.findElement(By.id("modalChangeTransactionType")).isDisplayed()).isTrue(); } - @Before + @BeforeEach public void prepare() { - FirefoxOptions options = new FirefoxOptions(); - options.setHeadless(false); - options.addPreference("devtools.console.stdout.content", true); - driver = new FirefoxDriver(options); - - // prepare helper = new IntegrationTestHelper(driver, port); helper.start(); helper.login(UserService.DEFAULT_PASSWORD); @@ -108,7 +68,7 @@ public class ChangeTransactionTypeTest } @Test - public void test_availableOptions_normal() + void test_availableOptions_normal() { openTransferTypeModal(2); @@ -119,7 +79,7 @@ public class ChangeTransactionTypeTest } @Test - public void test_availableOptions_recurring() + void test_availableOptions_recurring() { openTransferTypeModal(6); @@ -130,7 +90,7 @@ public class ChangeTransactionTypeTest } @Test - public void test_availableOptions_transfer() + void test_availableOptions_transfer() { openTransferTypeModal(3); @@ -141,7 +101,7 @@ public class ChangeTransactionTypeTest } @Test - public void test_normal_to_transfer() + void test_normal_to_transfer() { openTransferTypeModal(2); TransactionTestHelper.selectOptionFromDropdown(driver, By.cssSelector("#modalChangeTransactionType .select-wrapper"), "Transfer"); @@ -167,7 +127,7 @@ public class ChangeTransactionTypeTest } @Test - public void test_recurring_to_normal() + void test_recurring_to_normal() { openTransferTypeModal(6); TransactionTestHelper.selectOptionFromDropdown(driver, By.cssSelector("#modalChangeTransactionType .select-wrapper"), "Transaction"); @@ -191,7 +151,7 @@ public class ChangeTransactionTypeTest } @Test - public void test_transfer_to_recurring() + void test_transfer_to_recurring() { openTransferTypeModal(3); TransactionTestHelper.selectOptionFromDropdown(driver, By.cssSelector("#modalChangeTransactionType .select-wrapper"), "Recurring"); diff --git a/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/FirstUseTest.java b/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/FirstUseTest.java index a9b00fec9b9b8e4d0f34f22b95d15b0999294705..7f3c6456807532d0729c9ebc42a64db95e0b9625 100644 --- a/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/FirstUseTest.java +++ b/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/FirstUseTest.java @@ -4,66 +4,30 @@ 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 de.deadlocker8.budgetmaster.integration.helpers.SeleniumTestBase; +import de.deadlocker8.budgetmaster.integration.helpers.SeleniumTestWatcher; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; 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) +@ExtendWith(SeleniumTestWatcher.class) @SpringBootTest(classes = Main.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) @SeleniumTest -public class FirstUseTest +class FirstUseTest extends SeleniumTestBase { 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 + @BeforeEach public void prepare() { - FirefoxOptions options = new FirefoxOptions(); - options.setHeadless(false); - options.addPreference("devtools.console.stdout.content", true); - driver = new FirefoxDriver(options); - - // prepare helper = new IntegrationTestHelper(driver, port); helper.start(); helper.login(UserService.DEFAULT_PASSWORD); @@ -72,7 +36,7 @@ public class FirstUseTest } @Test - public void test_firstUserBanner() + void test_firstUserBanner() { WebDriverWait wait = new WebDriverWait(driver, 5); wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("hint-1"))); @@ -80,7 +44,7 @@ public class FirstUseTest } @Test - public void test_firstUserBanner_dismiss() + void test_firstUserBanner_dismiss() { WebDriverWait wait = new WebDriverWait(driver, 5); wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("hint-1"))); @@ -92,7 +56,7 @@ public class FirstUseTest } @Test - public void test_firstUserBanner_click() + void test_firstUserBanner_click() { WebDriverWait wait = new WebDriverWait(driver, 5); wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("hint-1"))); diff --git a/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/HotkeyTest.java b/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/HotkeyTest.java index 63051b0143b3e682c7fdf508b19ab9cf8e091511..dd5b33d5e0a04e737ffab1031ad0977828099ba0 100644 --- a/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/HotkeyTest.java +++ b/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/HotkeyTest.java @@ -4,79 +4,39 @@ import de.deadlocker8.budgetmaster.Main; import de.deadlocker8.budgetmaster.accounts.Account; import de.deadlocker8.budgetmaster.accounts.AccountType; import de.deadlocker8.budgetmaster.authentication.UserService; -import de.deadlocker8.budgetmaster.integration.helpers.IntegrationTestHelper; -import de.deadlocker8.budgetmaster.integration.helpers.SeleniumTest; -import de.deadlocker8.budgetmaster.integration.helpers.TransactionTestHelper; +import de.deadlocker8.budgetmaster.integration.helpers.*; import de.thecodelabs.utils.util.OS; -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.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.openqa.selenium.By; import org.openqa.selenium.Keys; -import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; -import org.openqa.selenium.firefox.FirefoxDriver; -import org.openqa.selenium.firefox.FirefoxOptions; import org.openqa.selenium.interactions.Action; import org.openqa.selenium.interactions.Actions; 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 java.io.File; import java.util.Arrays; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assume.assumeTrue; +import static org.junit.jupiter.api.Assumptions.assumeTrue; -@RunWith(SpringRunner.class) +@ExtendWith(SeleniumTestWatcher.class) @SpringBootTest(classes = Main.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) @SeleniumTest -public class HotkeyTest +class HotkeyTest extends SeleniumTestBase { 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, HotkeyTest.class); - } - }; - - @Before + @BeforeEach public void prepare() { - FirefoxOptions options = new FirefoxOptions(); - options.setHeadless(false); - options.addPreference("devtools.console.stdout.content", true); - driver = new FirefoxDriver(options); - - // prepare helper = new IntegrationTestHelper(driver, port); helper.start(); helper.login(UserService.DEFAULT_PASSWORD); @@ -87,10 +47,11 @@ public class HotkeyTest final Account account1 = new Account("DefaultAccount0815", AccountType.CUSTOM); final Account account2 = new Account("Account2", AccountType.CUSTOM); - helper.uploadDatabase(path, Arrays.asList("DefaultAccount0815", "sfsdf"), List.of(account1, account2)); } + helper.uploadDatabase(path, Arrays.asList("DefaultAccount0815", "sfsdf"), List.of(account1, account2)); + } @Test - public void hotkey_newTransaction_normal() + void hotkey_newTransaction_normal() { driver.findElement(By.tagName("body")).sendKeys("n"); @@ -101,7 +62,7 @@ public class HotkeyTest } @Test - public void hotkey_newTransaction_recurring() + void hotkey_newTransaction_recurring() { driver.findElement(By.tagName("body")).sendKeys("r"); @@ -123,7 +84,7 @@ public class HotkeyTest } @Test - public void hotkey_newTransaction_transactionFromTemplate() + void hotkey_newTransaction_transactionFromTemplate() { driver.findElement(By.tagName("body")).sendKeys("v"); @@ -134,7 +95,7 @@ public class HotkeyTest } @Test - public void hotkey_filter() + void hotkey_filter() { driver.findElement(By.tagName("body")).sendKeys("f"); @@ -146,7 +107,7 @@ public class HotkeyTest } @Test - public void hotkey_search() + void hotkey_search() { driver.findElement(By.tagName("body")).sendKeys("s"); @@ -154,7 +115,7 @@ public class HotkeyTest } @Test - public void hotkey_saveTransaction() + void hotkey_saveTransaction() { assumeTrue(OS.isWindows()); diff --git a/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/ImportTest.java b/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/ImportTest.java index ae4b6db07f5c39745c49398af2cfefb1e5b51575..b3eff6b6c0582c2d88c99fe626dec9de8d409efc 100644 --- a/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/ImportTest.java +++ b/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/ImportTest.java @@ -6,66 +6,25 @@ import de.deadlocker8.budgetmaster.accounts.AccountType; 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.WebDriver; -import org.openqa.selenium.firefox.FirefoxDriver; -import org.openqa.selenium.firefox.FirefoxOptions; +import de.deadlocker8.budgetmaster.integration.helpers.SeleniumTestBase; +import de.deadlocker8.budgetmaster.integration.helpers.SeleniumTestWatcher; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; 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 java.io.File; import java.util.Arrays; import java.util.List; -@RunWith(SpringRunner.class) +@ExtendWith(SeleniumTestWatcher.class) @SpringBootTest(classes = Main.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) @SeleniumTest -public class ImportTest +class ImportTest extends SeleniumTestBase { - 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, ImportTest.class); - } - }; - - @Before - public void prepare() - { - FirefoxOptions options = new FirefoxOptions(); - options.setHeadless(false); - options.addPreference("devtools.console.stdout.content", true); - driver = new FirefoxDriver(options); - } - @Test - public void requestImport() + void requestImport() { IntegrationTestHelper helper = new IntegrationTestHelper(driver, port); helper.start(); diff --git a/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/LoginControllerTest.java b/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/LoginControllerTest.java index 463b4c075f53976e5bd0b5ca16036a4a912677dc..9708909b8d05efec2e0af05bc9f292e4fb037241 100644 --- a/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/LoginControllerTest.java +++ b/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/LoginControllerTest.java @@ -4,69 +4,27 @@ 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 de.deadlocker8.budgetmaster.integration.helpers.SeleniumTestBase; +import de.deadlocker8.budgetmaster.integration.helpers.SeleniumTestWatcher; import de.thecodelabs.utils.util.Localization; -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.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; -import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; -import org.openqa.selenium.firefox.FirefoxDriver; -import org.openqa.selenium.firefox.FirefoxOptions; 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) +@ExtendWith(SeleniumTestWatcher.class) @SpringBootTest(classes = Main.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) @SeleniumTest -public class LoginControllerTest +class LoginControllerTest extends SeleniumTestBase { - 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, LoginControllerTest.class); - } - }; - - @Before - public void prepare() - { - FirefoxOptions options = new FirefoxOptions(); - options.setHeadless(false); - options.addPreference("devtools.console.stdout.content", true); - driver = new FirefoxDriver(options); - } - @Test - public void getLoginPage() + void getLoginPage() { IntegrationTestHelper helper = new IntegrationTestHelper(driver, port); helper.start(); @@ -82,7 +40,7 @@ public class LoginControllerTest } @Test - public void wrongCredentials() + void wrongCredentials() { IntegrationTestHelper helper = new IntegrationTestHelper(driver, port); helper.start(); @@ -93,7 +51,7 @@ public class LoginControllerTest } @Test - public void successLogin() + void successLogin() { IntegrationTestHelper helper = new IntegrationTestHelper(driver, port); helper.start(); @@ -107,7 +65,7 @@ public class LoginControllerTest } @Test - public void logout() + void logout() { IntegrationTestHelper helper = new IntegrationTestHelper(driver, port); helper.start(); diff --git a/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/NewTransactionFromTemplateTest.java b/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/NewTransactionFromTemplateTest.java index 18a81336ea89d6f97de8a48f6d2d46aa76ec385c..86f50db823ed146ff57ce4ab2a84e0a75604962c 100644 --- a/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/NewTransactionFromTemplateTest.java +++ b/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/NewTransactionFromTemplateTest.java @@ -6,14 +6,14 @@ import de.deadlocker8.budgetmaster.accounts.AccountType; import de.deadlocker8.budgetmaster.authentication.UserService; import de.deadlocker8.budgetmaster.integration.helpers.IntegrationTestHelper; import de.deadlocker8.budgetmaster.integration.helpers.SeleniumTest; +import de.deadlocker8.budgetmaster.integration.helpers.SeleniumTestBase; +import de.deadlocker8.budgetmaster.integration.helpers.SeleniumTestWatcher; import de.thecodelabs.utils.util.Localization; -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.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.api.extension.TestWatcher; import org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; @@ -25,7 +25,6 @@ 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 java.io.File; import java.util.Arrays; @@ -33,46 +32,17 @@ import java.util.List; import static org.assertj.core.api.Assertions.assertThat; -@RunWith(SpringRunner.class) +@ExtendWith(SeleniumTestWatcher.class) @SpringBootTest(classes = Main.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) @SeleniumTest -public class NewTransactionFromTemplateTest +class NewTransactionFromTemplateTest extends SeleniumTestBase { 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, NewTransactionFromTemplateTest.class); - } - }; - - @Before + @BeforeEach public void prepare() { - FirefoxOptions options = new FirefoxOptions(); - options.setHeadless(false); - options.addPreference("devtools.console.stdout.content", true); - driver = new FirefoxDriver(options); - - // prepare helper = new IntegrationTestHelper(driver, port); helper.start(); helper.login(UserService.DEFAULT_PASSWORD); @@ -90,7 +60,7 @@ public class NewTransactionFromTemplateTest } @Test - public void test_newTransactionFromTemplate_FullTemplate() + void test_newTransactionFromTemplate_FullTemplate() { WebDriverWait wait = new WebDriverWait(driver, 5); final By locator = By.xpath("//div[contains(@class, 'new-transaction-button')]//a[contains(text(),'From template')]"); @@ -121,7 +91,7 @@ public class NewTransactionFromTemplateTest } @Test - public void test_newTransactionFromTemplate_OnlyIncome() + void test_newTransactionFromTemplate_OnlyIncome() { WebDriverWait wait = new WebDriverWait(driver, 5); final By locator = By.xpath("//div[contains(@class, 'new-transaction-button')]//a[contains(text(),'From template')]"); @@ -142,7 +112,7 @@ public class NewTransactionFromTemplateTest } @Test - public void test_selectTemplateHotkeys_initialSelect() + void test_selectTemplateHotkeys_initialSelect() { driver.get(helper.getUrl() + "/templates"); @@ -158,7 +128,7 @@ public class NewTransactionFromTemplateTest } @Test - public void test_selectTemplateHotkeys_keyDown() + void test_selectTemplateHotkeys_keyDown() { driver.get(helper.getUrl() + "/templates"); @@ -177,7 +147,7 @@ public class NewTransactionFromTemplateTest } @Test - public void test_selectTemplateHotkeys_keyDown_goBackToTopFromLastItem() + void test_selectTemplateHotkeys_keyDown_goBackToTopFromLastItem() { driver.get(helper.getUrl() + "/templates"); @@ -197,7 +167,7 @@ public class NewTransactionFromTemplateTest } @Test - public void test_selectTemplateHotkeys_keyUp_goBackToBottomFromFirstItem() + void test_selectTemplateHotkeys_keyUp_goBackToBottomFromFirstItem() { driver.get(helper.getUrl() + "/templates"); @@ -216,7 +186,7 @@ public class NewTransactionFromTemplateTest } @Test - public void test_selectTemplateHotkeys_keyUp() + void test_selectTemplateHotkeys_keyUp() { driver.get(helper.getUrl() + "/templates"); @@ -236,7 +206,7 @@ public class NewTransactionFromTemplateTest } @Test - public void test_selectTemplateHotkeys_confirmSelection() + void test_selectTemplateHotkeys_confirmSelection() { driver.get(helper.getUrl() + "/templates"); @@ -255,7 +225,7 @@ public class NewTransactionFromTemplateTest } @Test - public void test_selectTemplateHotkeys_searchContainsSelection() + void test_selectTemplateHotkeys_searchContainsSelection() { driver.get(helper.getUrl() + "/templates"); @@ -278,7 +248,7 @@ public class NewTransactionFromTemplateTest } @Test - public void test_selectTemplateHotkeys_searchNotContainsSelection() + void test_selectTemplateHotkeys_searchNotContainsSelection() { driver.get(helper.getUrl() + "/templates"); @@ -300,7 +270,7 @@ public class NewTransactionFromTemplateTest } @Test - public void test_selectTemplateHotkeys_dontBlockEnterInGlobalSearch() + void test_selectTemplateHotkeys_dontBlockEnterInGlobalSearch() { driver.get(helper.getUrl() + "/templates"); diff --git a/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/NewTransactionNormalTest.java b/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/NewTransactionNormalTest.java index f33006b57631d9ebd0e2b3b5c417be28b2925b84..452e5c946628fd6839a543ebc108203fd85986ff 100644 --- a/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/NewTransactionNormalTest.java +++ b/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/NewTransactionNormalTest.java @@ -4,28 +4,17 @@ import de.deadlocker8.budgetmaster.Main; import de.deadlocker8.budgetmaster.accounts.Account; import de.deadlocker8.budgetmaster.accounts.AccountType; import de.deadlocker8.budgetmaster.authentication.UserService; -import de.deadlocker8.budgetmaster.integration.helpers.IntegrationTestHelper; -import de.deadlocker8.budgetmaster.integration.helpers.SeleniumTest; -import de.deadlocker8.budgetmaster.integration.helpers.TransactionTestHelper; -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 de.deadlocker8.budgetmaster.integration.helpers.*; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; -import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; -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 java.io.File; import java.text.SimpleDateFormat; @@ -35,46 +24,17 @@ import java.util.List; import static org.assertj.core.api.Assertions.assertThat; -@RunWith(SpringRunner.class) +@ExtendWith(SeleniumTestWatcher.class) @SpringBootTest(classes = Main.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) @SeleniumTest -public class NewTransactionNormalTest +class NewTransactionNormalTest extends SeleniumTestBase { 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, NewTransactionNormalTest.class); - } - }; - - @Before + @BeforeEach public void prepare() { - FirefoxOptions options = new FirefoxOptions(); - options.setHeadless(false); - options.addPreference("devtools.console.stdout.content", true); - driver = new FirefoxDriver(options); - - // prepare helper = new IntegrationTestHelper(driver, port); helper.start(); helper.login(UserService.DEFAULT_PASSWORD); @@ -100,7 +60,7 @@ public class NewTransactionNormalTest } @Test - public void test_newTransaction_cancel() + void test_newTransaction_cancel() { // click cancel button WebElement cancelButton = driver.findElement(By.id("button-cancel-save-transaction")); @@ -118,7 +78,7 @@ public class NewTransactionNormalTest } @Test - public void test_newTransaction_income() + void test_newTransaction_income() { String name = "My normal transaction"; String amount = "15.00"; @@ -154,7 +114,7 @@ public class NewTransactionNormalTest } @Test - public void test_newTransaction_expenditure() + void test_newTransaction_expenditure() { String name = "My normal transaction"; String amount = "15.00"; @@ -190,7 +150,7 @@ public class NewTransactionNormalTest } @Test - public void test_edit() + void test_edit() { driver.get(helper.getUrl() + "/transactions/2/edit"); diff --git a/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/NewTransactionRecurringTest.java b/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/NewTransactionRecurringTest.java index ceae4906c8751425cceb15153ec3e738bf41be8d..4e668a69f1a0c166e8b49d4ae2175ec1f7160d80 100644 --- a/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/NewTransactionRecurringTest.java +++ b/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/NewTransactionRecurringTest.java @@ -4,28 +4,17 @@ import de.deadlocker8.budgetmaster.Main; import de.deadlocker8.budgetmaster.accounts.Account; import de.deadlocker8.budgetmaster.accounts.AccountType; import de.deadlocker8.budgetmaster.authentication.UserService; -import de.deadlocker8.budgetmaster.integration.helpers.IntegrationTestHelper; -import de.deadlocker8.budgetmaster.integration.helpers.SeleniumTest; -import de.deadlocker8.budgetmaster.integration.helpers.TransactionTestHelper; -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 de.deadlocker8.budgetmaster.integration.helpers.*; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; -import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; -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 java.io.File; import java.text.SimpleDateFormat; @@ -35,46 +24,17 @@ import java.util.List; import static org.assertj.core.api.Assertions.assertThat; -@RunWith(SpringRunner.class) +@ExtendWith(SeleniumTestWatcher.class) @SpringBootTest(classes = Main.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) @SeleniumTest -public class NewTransactionRecurringTest +class NewTransactionRecurringTest extends SeleniumTestBase { 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, NewTransactionRecurringTest.class); - } - }; - - @Before + @BeforeEach public void prepare() { - FirefoxOptions options = new FirefoxOptions(); - options.setHeadless(false); - options.addPreference("devtools.console.stdout.content", true); - driver = new FirefoxDriver(options); - - // prepare helper = new IntegrationTestHelper(driver, port); helper.start(); helper.login(UserService.DEFAULT_PASSWORD); @@ -100,7 +60,7 @@ public class NewTransactionRecurringTest } @Test - public void test_newTransaction_cancel() + void test_newTransaction_cancel() { // click cancel button WebElement cancelButton = driver.findElement(By.id("button-cancel-save-transaction")); @@ -118,7 +78,7 @@ public class NewTransactionRecurringTest } @Test - public void test_newTransaction_income() + void test_newTransaction_income() { String name = "My recurring transaction"; String amount = "15.00"; @@ -182,7 +142,7 @@ public class NewTransactionRecurringTest } @Test - public void test_newTransaction_expenditure() + void test_newTransaction_expenditure() { String name = "My recurring transaction"; String amount = "15.00"; @@ -246,7 +206,7 @@ public class NewTransactionRecurringTest } @Test - public void test_edit() + void test_edit() { driver.get(helper.getUrl() + "/transactions/6/edit"); diff --git a/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/NewTransactionTransferTest.java b/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/NewTransactionTransferTest.java index 41502ef56953ffca750b1e3bf9cafaf2838bac05..141bad3f8ed1cedeb4f42aebf2b6642a763017d5 100644 --- a/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/NewTransactionTransferTest.java +++ b/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/NewTransactionTransferTest.java @@ -4,25 +4,18 @@ import de.deadlocker8.budgetmaster.Main; import de.deadlocker8.budgetmaster.accounts.Account; import de.deadlocker8.budgetmaster.accounts.AccountType; import de.deadlocker8.budgetmaster.authentication.UserService; -import de.deadlocker8.budgetmaster.integration.helpers.IntegrationTestHelper; -import de.deadlocker8.budgetmaster.integration.helpers.SeleniumTest; -import de.deadlocker8.budgetmaster.integration.helpers.TransactionTestHelper; -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.*; -import org.openqa.selenium.firefox.FirefoxDriver; -import org.openqa.selenium.firefox.FirefoxOptions; +import de.deadlocker8.budgetmaster.integration.helpers.*; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.openqa.selenium.By; +import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.NoSuchElementException; +import org.openqa.selenium.WebElement; 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 java.io.File; import java.text.SimpleDateFormat; @@ -33,46 +26,17 @@ import java.util.List; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -@RunWith(SpringRunner.class) +@ExtendWith(SeleniumTestWatcher.class) @SpringBootTest(classes = Main.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) @SeleniumTest -public class NewTransactionTransferTest +class NewTransactionTransferTest extends SeleniumTestBase { 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, NewTransactionTransferTest.class); - } - }; - - @Before + @BeforeEach public void prepare() { - FirefoxOptions options = new FirefoxOptions(); - options.setHeadless(false); - options.addPreference("devtools.console.stdout.content", true); - driver = new FirefoxDriver(options); - - // prepare helper = new IntegrationTestHelper(driver, port); helper.start(); helper.login(UserService.DEFAULT_PASSWORD); @@ -98,7 +62,7 @@ public class NewTransactionTransferTest } @Test - public void test_newTransaction_cancel() + void test_newTransaction_cancel() { // click cancel button WebElement cancelButton = driver.findElement(By.id("button-cancel-save-transaction")); @@ -116,7 +80,7 @@ public class NewTransactionTransferTest } @Test - public void test_newTransaction_transfer() + void test_newTransaction_transfer() { String name = "My transfer transaction"; String amount = "15.00"; @@ -151,7 +115,7 @@ public class NewTransactionTransferTest } @Test - public void test_edit() + void test_edit() { driver.get(helper.getUrl() + "/transactions/3/edit"); diff --git a/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/SearchTest.java b/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/SearchTest.java index 20ab063d90686442717d09e19decac96c99fd2e5..e64b6e2f7e3803702e87aabfa933e42daaade27d 100644 --- a/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/SearchTest.java +++ b/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/SearchTest.java @@ -6,14 +6,14 @@ import de.deadlocker8.budgetmaster.accounts.AccountType; import de.deadlocker8.budgetmaster.authentication.UserService; import de.deadlocker8.budgetmaster.integration.helpers.IntegrationTestHelper; import de.deadlocker8.budgetmaster.integration.helpers.SeleniumTest; +import de.deadlocker8.budgetmaster.integration.helpers.SeleniumTestBase; +import de.deadlocker8.budgetmaster.integration.helpers.SeleniumTestWatcher; import de.thecodelabs.utils.util.Localization; -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.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.api.extension.TestWatcher; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; @@ -23,7 +23,6 @@ import org.openqa.selenium.firefox.FirefoxOptions; 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 java.io.File; import java.util.Arrays; @@ -32,46 +31,15 @@ import java.util.List; import static org.assertj.core.api.Assertions.assertThat; -@RunWith(SpringRunner.class) +@ExtendWith(SeleniumTestWatcher.class) @SpringBootTest(classes = Main.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) @SeleniumTest -public class SearchTest +class SearchTest extends SeleniumTestBase { - 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, SearchTest.class); - } - }; - - @Before + @BeforeEach public void prepare() { - FirefoxOptions options = new FirefoxOptions(); - options.setHeadless(false); - options.addPreference("devtools.console.stdout.content", true); - driver = new FirefoxDriver(options); - driver.manage().window().maximize(); - - // prepare IntegrationTestHelper helper = new IntegrationTestHelper(driver, port); helper.start(); helper.login(UserService.DEFAULT_PASSWORD); @@ -90,7 +58,7 @@ public class SearchTest } @Test - public void searchFromNavbar() + void searchFromNavbar() { // headline WebElement headline = driver.findElement(By.className("headline")); @@ -109,7 +77,7 @@ public class SearchTest } @Test - public void pagination() + void pagination() { // === PAGE 1 === List<WebElement> pages = driver.findElements(By.cssSelector(".pagination li")); @@ -149,7 +117,7 @@ public class SearchTest } @Test - public void checkboxes() + void checkboxes() { // deselect some checkboxes (use JavascriptExecutor here as the checkbox is covered by a span) JavascriptExecutor executor = (JavascriptExecutor) driver; @@ -171,7 +139,7 @@ public class SearchTest } @Test - public void highlight() + void highlight() { driver.findElement(By.cssSelector(".main-card .search-result .hide-on-med-and-down .buttonHighlight")).click(); diff --git a/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/WhatsNewTest.java b/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/WhatsNewTest.java index 9c5731e6d747abd04b6997e30c04056618d4c3b1..fc447467a636cddd6557c1880aa3abbe17974387 100644 --- a/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/WhatsNewTest.java +++ b/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/WhatsNewTest.java @@ -4,66 +4,30 @@ 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 de.deadlocker8.budgetmaster.integration.helpers.SeleniumTestBase; +import de.deadlocker8.budgetmaster.integration.helpers.SeleniumTestWatcher; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; 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) +@ExtendWith(SeleniumTestWatcher.class) @SpringBootTest(classes = Main.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) @SeleniumTest -public class WhatsNewTest +class WhatsNewTest extends SeleniumTestBase { 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, WhatsNewTest.class); - } - }; - - @Before + @BeforeEach public void prepare() { - FirefoxOptions options = new FirefoxOptions(); - options.setHeadless(false); - options.addPreference("devtools.console.stdout.content", true); - driver = new FirefoxDriver(options); - - // prepare helper = new IntegrationTestHelper(driver, port); helper.start(); helper.login(UserService.DEFAULT_PASSWORD); @@ -71,7 +35,7 @@ public class WhatsNewTest } @Test - public void test_whats_new_dialog() + void test_whats_new_dialog() { WebDriverWait wait = new WebDriverWait(driver, 5); wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("modalWhatsNew"))); diff --git a/src/test/java/de/deadlocker8/budgetmaster/unit/TransactionServiceDatabaseTest.java b/src/test/java/de/deadlocker8/budgetmaster/unit/TransactionServiceDatabaseTest.java index 6bbc70088de6c1f125eca15ef1125129c95a8617..0c6f2eb8993914e4fca354d1e78777b087b6e519 100644 --- a/src/test/java/de/deadlocker8/budgetmaster/unit/TransactionServiceDatabaseTest.java +++ b/src/test/java/de/deadlocker8/budgetmaster/unit/TransactionServiceDatabaseTest.java @@ -9,8 +9,7 @@ import de.deadlocker8.budgetmaster.transactions.Transaction; import de.deadlocker8.budgetmaster.transactions.TransactionService; import org.joda.time.DateTime; import org.joda.time.format.DateTimeFormat; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.jdbc.DataSourceBuilder; @@ -21,7 +20,6 @@ import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Primary; import org.springframework.core.io.Resource; import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.transaction.annotation.Transactional; import javax.sql.DataSource; @@ -30,13 +28,12 @@ import java.util.List; import static org.assertj.core.api.Assertions.assertThat; -@RunWith(SpringRunner.class) @SpringBootTest(classes = Main.class) @Import(TransactionServiceDatabaseTest.TestDatabaseConfiguration.class) @ActiveProfiles("test") @SeleniumTest @Transactional -public class TransactionServiceDatabaseTest +class TransactionServiceDatabaseTest { @TestConfiguration static class TestDatabaseConfiguration @@ -61,7 +58,7 @@ public class TransactionServiceDatabaseTest private AccountService accountService; @Test - public void test_deleteAll() + void test_deleteAll() { transactionService.deleteAll(); @@ -69,7 +66,7 @@ public class TransactionServiceDatabaseTest } @Test - public void test_getTransactionsForAccount_specificAccount() + void test_getTransactionsForAccount_specificAccount() { DateTime date1 = DateTime.parse("2020-04-30", DateTimeFormat.forPattern("yyyy-MM-dd")); FilterConfiguration filterConfiguration = new FilterConfiguration(true, true, true, true, true, null, null, ""); @@ -83,7 +80,7 @@ public class TransactionServiceDatabaseTest } @Test - public void test_getTransactionsForAccount_all() + void test_getTransactionsForAccount_all() { DateTime date1 = DateTime.parse("2020-04-30", DateTimeFormat.forPattern("yyyy-MM-dd")); FilterConfiguration filterConfiguration = new FilterConfiguration(true, true, true, true, true, null, null, ""); @@ -93,7 +90,7 @@ public class TransactionServiceDatabaseTest } @Test - public void test_getTransactionsForAccountUntilDate() + void test_getTransactionsForAccountUntilDate() { DateTime date1 = DateTime.parse("2020-04-30", DateTimeFormat.forPattern("yyyy-MM-dd")); DateTime date2 = DateTime.parse("2020-05-20", DateTimeFormat.forPattern("yyyy-MM-dd")); @@ -104,7 +101,7 @@ public class TransactionServiceDatabaseTest } @Test - public void test_getTransactionsForMonthAndYear() + void test_getTransactionsForMonthAndYear() { FilterConfiguration filterConfiguration = new FilterConfiguration(true, true, true, true, true, null, null, "");