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 @@
<version>${selenium.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-support</artifactId>
<version>${selenium.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
......
......@@ -83,7 +83,7 @@ public class Main extends SpringBootServletInitializer implements ApplicationRun
public static Path getApplicationSupportFolder()
{
if(System.getProperties().contains("test"))
if(System.getProperties().containsKey("testProfile"))
{
RunMode.currentRunMode = RunMode.TEST;
}
......
<#macro style name>
<#import "/spring.ftl" as s>
<#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>
<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>
</#macro>
......
......@@ -164,7 +164,7 @@
<p>${locale.getString("info.text.backup.reminder")}</p>
</div>
<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>
</div>
</div>
......
......@@ -41,7 +41,7 @@
</td>
<td class="import-text">${locale.getString("info.database.import.or")}</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>
</tr>
</#list>
......@@ -61,7 +61,7 @@
</div>
<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")}
</button>
</div>
......
......@@ -7,15 +7,18 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
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.boot.context.embedded.LocalServerPort;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
import java.io.File;
import java.net.URISyntaxException;
import java.util.List;
import static org.junit.Assert.assertEquals;
......@@ -24,12 +27,13 @@ import static org.junit.Assert.assertNotNull;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = Main.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@SeleniumTest
@Transactional
public class ImportTest
{
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
@Autowired
private WebDriver driver;
private final static String BASE_URL = "http://localhost:";
private final static String BASE_URL = "https://localhost:";
private String url;
@LocalServerPort
......@@ -44,7 +48,7 @@ public class ImportTest
@Test
public void requestImport() throws InterruptedException
{
driver.get(url + "/settings/database/requestImport");
driver.get(url);
// login
WebElement inputPassword = driver.findElement(By.id("login-password"));
......@@ -52,6 +56,18 @@ public class ImportTest
WebElement buttonLogin = driver.findElement(By.tagName("button"));
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
WebElement input = driver.findElement(By.id("inputDatabaseImport"));
assertNotNull(input);
......@@ -66,6 +82,18 @@ public class ImportTest
WebElement buttonUpload = driver.findElement(By.id("button-confirm-database-import"));
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
WebElement headlineImport = driver.findElement(By.className("headline"));
assertEquals(Localization.getString("info.title.database.import.dialog"), IntegrationTestHelper.getTextNode(headlineImport));
......@@ -77,9 +105,19 @@ public class ImportTest
WebElement sourceAccount1 = row1.findElement(By.className("account-source"));
assertEquals("DefaultAccount0815", IntegrationTestHelper.getTextNode(sourceAccount1));
List<WebElement> destinationAccounts = row1.findElements(By.cssSelector(".account-destination option"));
assertEquals(1, destinationAccounts.size());
System.out.println(destinationAccounts.get(0).getText());
// assertEquals("Default Account", IntegrationTestHelper.getTextNode(destinationAccounts.get(0)));
// match first account
row1.findElement(By.className("select-dropdown")).click();
WebElement accountToSelect = row1.findElement(By.xpath("//form/table/tbody/tr[1]/td[5]/div/div/ul/li/span[text()='DefaultAccount0815']"));
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
@Override
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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment