Skip to content
Snippets Groups Projects
Commit bc9b711d authored by Robert Goldmann's avatar Robert Goldmann
Browse files

#432 - finished test for uploading a database

parent 104e2933
No related branches found
No related tags found
No related merge requests found
...@@ -195,6 +195,12 @@ ...@@ -195,6 +195,12 @@
<version>${selenium.version}</version> <version>${selenium.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-support</artifactId>
<version>${selenium.version}</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
...@@ -83,7 +83,7 @@ public class Main extends SpringBootServletInitializer implements ApplicationRun ...@@ -83,7 +83,7 @@ public class Main extends SpringBootServletInitializer implements ApplicationRun
public static Path getApplicationSupportFolder() public static Path getApplicationSupportFolder()
{ {
if(System.getProperties().contains("test")) if(System.getProperties().containsKey("testProfile"))
{ {
RunMode.currentRunMode = RunMode.TEST; RunMode.currentRunMode = RunMode.TEST;
} }
......
<#macro style name> <#macro style name>
<#import "/spring.ftl" as s> <#import "/spring.ftl" as s>
<#if helpers.getSettings().isUseDarkTheme()> <#if helpers.getSettings().isUseDarkTheme()>
<link type="text/css" rel="stylesheet" href=<@s.url '${"/css/dark/" + name + ".css"}'/>/> <link type="text/css" rel="stylesheet" href="<@s.url '${"/css/dark/" + name + ".css"}'/>"/>
<#else> <#else>
<link type="text/css" rel="stylesheet" href=<@s.url '${"/css/" + name + ".css"}'/>/> <link type="text/css" rel="stylesheet" href="<@s.url '${"/css/" + name + ".css"}'/>"/>
</#if> </#if>
</#macro> </#macro>
......
...@@ -164,7 +164,7 @@ ...@@ -164,7 +164,7 @@
<p>${locale.getString("info.text.backup.reminder")}</p> <p>${locale.getString("info.text.backup.reminder")}</p>
</div> </div>
<div class="modal-footer background-color"> <div class="modal-footer background-color">
<a href="<@s.url '/backupReminder/cancel'/>" class="modal-action modal-close waves-effect waves-light red btn-flat white-text">${locale.getString("cancel")}</a> <a href="<@s.url '/backupReminder/cancel'/>" id="buttonCloseReminder" class="modal-action modal-close waves-effect waves-light red btn-flat white-text">${locale.getString("cancel")}</a>
<a href="<@s.url '/backupReminder/settings'/>" class="modal-action modal-close waves-effectwaves-light green btn-flat white-text">${locale.getString("info.button.backup.reminder")}</a> <a href="<@s.url '/backupReminder/settings'/>" class="modal-action modal-close waves-effectwaves-light green btn-flat white-text">${locale.getString("info.button.backup.reminder")}</a>
</div> </div>
</div> </div>
......
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
</td> </td>
<td class="import-text">${locale.getString("info.database.import.or")}</td> <td class="import-text">${locale.getString("info.database.import.or")}</td>
<td> <td>
<a href="<@s.url '/accounts/newAccount'/>" class="btn waves-effect waves-light budgetmaster-blue"><i class="material-icons left">add</i>${locale.getString("title.account.new")}</a> <a href="<@s.url '/accounts/newAccount'/>" class="btn waves-effect waves-light budgetmaster-blue button-new-account"><i class="material-icons left">add</i>${locale.getString("title.account.new")}</a>
</td> </td>
</tr> </tr>
</#list> </#list>
...@@ -61,7 +61,7 @@ ...@@ -61,7 +61,7 @@
</div> </div>
<div class="col m6 l4 left-align"> <div class="col m6 l4 left-align">
<button class="btn waves-effect waves-light budgetmaster-blue" type="submit" name="action"> <button class="btn waves-effect waves-light budgetmaster-blue" type="submit" name="action" id="buttonImport">
<i class="material-icons left">unarchive</i>${locale.getString("settings.database.import")} <i class="material-icons left">unarchive</i>${locale.getString("settings.database.import")}
</button> </button>
</div> </div>
......
...@@ -7,15 +7,18 @@ import org.junit.Before; ...@@ -7,15 +7,18 @@ import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.openqa.selenium.By; import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement; import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.embedded.LocalServerPort; import org.springframework.boot.context.embedded.LocalServerPort;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
import java.io.File; import java.io.File;
import java.net.URISyntaxException;
import java.util.List; import java.util.List;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
...@@ -24,12 +27,13 @@ import static org.junit.Assert.assertNotNull; ...@@ -24,12 +27,13 @@ import static org.junit.Assert.assertNotNull;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = Main.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @SpringBootTest(classes = Main.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@SeleniumTest @SeleniumTest
@Transactional
public class ImportTest public class ImportTest
{ {
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
@Autowired @Autowired
private WebDriver driver; private WebDriver driver;
private final static String BASE_URL = "http://localhost:"; private final static String BASE_URL = "https://localhost:";
private String url; private String url;
@LocalServerPort @LocalServerPort
...@@ -44,7 +48,7 @@ public class ImportTest ...@@ -44,7 +48,7 @@ public class ImportTest
@Test @Test
public void requestImport() throws InterruptedException public void requestImport() throws InterruptedException
{ {
driver.get(url + "/settings/database/requestImport"); driver.get(url);
// login // login
WebElement inputPassword = driver.findElement(By.id("login-password")); WebElement inputPassword = driver.findElement(By.id("login-password"));
...@@ -52,6 +56,18 @@ public class ImportTest ...@@ -52,6 +56,18 @@ public class ImportTest
WebElement buttonLogin = driver.findElement(By.tagName("button")); WebElement buttonLogin = driver.findElement(By.tagName("button"));
buttonLogin.click(); buttonLogin.click();
// hide backup reminder if present
try
{
WebElement buttonCloseReminder = driver.findElement(By.cssSelector("#modalBackupReminder #buttonCloseReminder"));
buttonCloseReminder.click();
}
catch(NoSuchElementException ignored)
{
}
driver.get(url + "/settings/database/requestImport");
// upload database // upload database
WebElement input = driver.findElement(By.id("inputDatabaseImport")); WebElement input = driver.findElement(By.id("inputDatabaseImport"));
assertNotNull(input); assertNotNull(input);
...@@ -66,6 +82,18 @@ public class ImportTest ...@@ -66,6 +82,18 @@ public class ImportTest
WebElement buttonUpload = driver.findElement(By.id("button-confirm-database-import")); WebElement buttonUpload = driver.findElement(By.id("button-confirm-database-import"));
buttonUpload.click(); buttonUpload.click();
// create new account
driver.findElement(By.className("button-new-account")).click();
WebElement inputAccountName = driver.findElement(By.id("account-name"));
inputAccountName.sendKeys("DefaultAccount0815");
driver.findElement(By.tagName("button")).click();
// create second account
driver.findElement(By.className("button-new-account")).click();
inputAccountName = driver.findElement(By.id("account-name"));
inputAccountName.sendKeys("Account2");
driver.findElement(By.tagName("button")).click();
// account matching // account matching
WebElement headlineImport = driver.findElement(By.className("headline")); WebElement headlineImport = driver.findElement(By.className("headline"));
assertEquals(Localization.getString("info.title.database.import.dialog"), IntegrationTestHelper.getTextNode(headlineImport)); assertEquals(Localization.getString("info.title.database.import.dialog"), IntegrationTestHelper.getTextNode(headlineImport));
...@@ -77,9 +105,19 @@ public class ImportTest ...@@ -77,9 +105,19 @@ public class ImportTest
WebElement sourceAccount1 = row1.findElement(By.className("account-source")); WebElement sourceAccount1 = row1.findElement(By.className("account-source"));
assertEquals("DefaultAccount0815", IntegrationTestHelper.getTextNode(sourceAccount1)); assertEquals("DefaultAccount0815", IntegrationTestHelper.getTextNode(sourceAccount1));
List<WebElement> destinationAccounts = row1.findElements(By.cssSelector(".account-destination option")); // match first account
assertEquals(1, destinationAccounts.size()); row1.findElement(By.className("select-dropdown")).click();
System.out.println(destinationAccounts.get(0).getText()); WebElement accountToSelect = row1.findElement(By.xpath("//form/table/tbody/tr[1]/td[5]/div/div/ul/li/span[text()='DefaultAccount0815']"));
// assertEquals("Default Account", IntegrationTestHelper.getTextNode(destinationAccounts.get(0))); accountToSelect.click();
// match second account
tableRows.get(1).findElement(By.className("select-dropdown")).click();
accountToSelect = row1.findElement(By.xpath("//form/table/tbody/tr[2]/td[5]/div/div/ul/li/span[text()='Account2']"));
accountToSelect.click();
// confirm import
driver.findElement(By.id("buttonImport")).click();
assertEquals(Localization.getString("menu.settings"), IntegrationTestHelper.getTextNode(driver.findElement(By.className("headline"))));
} }
} }
\ No newline at end of file
...@@ -31,9 +31,9 @@ public class SeleniumTestExecutionListener extends AbstractTestExecutionListener ...@@ -31,9 +31,9 @@ public class SeleniumTestExecutionListener extends AbstractTestExecutionListener
@Override @Override
public void prepareTestInstance(TestContext testContext) public void prepareTestInstance(TestContext testContext)
{ {
if(!System.getProperties().contains("test")) if(!System.getProperties().containsKey("testProfile"))
{ {
throw new RuntimeException("Test profile not activated. Skipping tests. (Set -Dtest=true in your VM arguments)"); throw new RuntimeException("Test profile not activated. Skipping tests. (Set -DtestProfile=true in your VM arguments)");
} }
if(webDriver != null) if(webDriver != null)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment