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

#538 - added basic selenium test for creation of new normal transactions

parent 7c54b090
No related branches found
No related tags found
No related merge requests found
Pipeline #3698 failed
package de.deadlocker8.budgetmaster.integration;
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.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;
import java.util.Arrays;
import java.util.Date;
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 NewTransactionTest
{
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, SearchTest.class);
}
};
@Before
public void prepare()
{
FirefoxOptions options = new FirefoxOptions();
options.setHeadless(false);
driver = new FirefoxDriver(options);
// prepare
helper = new IntegrationTestHelper(driver, port);
helper.start();
helper.login(UserService.DEFAULT_PASSWORD);
helper.hideBackupReminder();
String path = getClass().getClassLoader().getResource("SearchDatabase.json").getFile().replace("/", File.separator);
helper.uploadDatabase(path, Arrays.asList("DefaultAccount0815", "sfsdf"), Arrays.asList("DefaultAccount0815", "Account2"));
// open transactions page
driver.get(helper.getUrl() + "/transactions");
driver.findElement(By.id("button-new-transaction")).click();
}
@Test
public void newTransaction_normal_income()
{
// open new transaction page
driver.findElement(By.xpath("//div[contains(@class, 'new-transaction-button')]//a[contains(text(),'Transaction')]")).click();
String name = "My normal transaction";
String amount = "15.00";
String description = "Lorem Ipsum dolor sit amet";
// fill form
driver.findElement(By.id("transaction-name")).sendKeys(name);
driver.findElement(By.id("transaction-amount")).sendKeys(amount);
driver.findElement(By.id("transaction-description")).sendKeys(description);
// submit form
final WebElement buttonSubmit = driver.findElement(By.xpath("//button[@type='submit']"));
buttonSubmit.click();
WebDriverWait wait = new WebDriverWait(driver, 5);
wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".headline-date")));
// assert
assertThat(driver.getCurrentUrl()).endsWith("/transactions");
List<WebElement> transactionsRows = driver.findElements(By.cssSelector(".transaction-container .hide-on-med-and-down.transaction-row-top"));
assertThat(transactionsRows).hasSize(2);
final WebElement row = transactionsRows.get(0);
final List<WebElement> columns = row.findElements(By.className("col"));
assertThat(columns).hasSize(6);
// check columns
final String dateString = new SimpleDateFormat("dd.MM.").format(new Date());
assertTransactionColumns(columns, dateString, "N", "rgb(255, 255, 255)", false, name, description, amount);
}
private void assertTransactionColumns(List<WebElement> columns, String shortDate, String categoryLetter, String categoryColor, boolean repeatIconVisible, String name, String description, String amount)
{
// date
assertThat(columns.get(0)).hasFieldOrPropertyWithValue("text", shortDate);
// category
final WebElement categoryCircle = columns.get(1).findElement(By.className("category-circle"));
assertThat(categoryCircle.getCssValue("background-color")).isEqualTo(categoryColor);
assertThat(categoryCircle.findElement(By.tagName("span"))).hasFieldOrPropertyWithValue("text", categoryLetter);
// icon
final List<WebElement> icons = columns.get(2).findElements(By.tagName("i"));
assertThat(icons).hasSize(1);
assertThat(icons.get(0).isDisplayed()).isEqualTo(repeatIconVisible);
// name
assertThat(columns.get(3).findElement(By.className("transaction-text")).getText())
.isEqualTo(name);
//description
assertThat(columns.get(3).findElement(By.className("italic")).getText())
.isEqualTo(description);
// amount
assertThat(columns.get(4).getText()).contains(amount);
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment