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

#431 - added login and logout tests

parent aad5600d
Branches
Tags
No related merge requests found
......@@ -31,7 +31,7 @@
<table class="${redTextColor} login-message no-border-table">
<tr>
<td><i class="material-icons">warning</i></td>
<td>${locale.getString("warning.wrong.password")}</td>
<td id="loginMessage">${locale.getString("warning.wrong.password")}</td>
</tr>
</table>
</div>
......@@ -44,7 +44,7 @@
<table class="${greenTextColor} login-message no-border-table">
<tr>
<td><i class="material-icons">info_outline</i></td>
<td>${locale.getString("logout.success")}</td>
<td id="loginMessage">${locale.getString("logout.success")}</td>
</tr>
</table>
</div>
......
package de.deadlocker8.budgetmaster.integration;
import de.deadlocker8.budgetmaster.Main;
import de.deadlocker8.budgetmaster.authentication.UserService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openqa.selenium.WebDriver;
......@@ -11,14 +12,12 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = Main.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@SeleniumTest
@Transactional
public class ImportTest
{
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
......@@ -33,7 +32,7 @@ public class ImportTest
{
IntegrationTestHelper helper = new IntegrationTestHelper(driver, port);
helper.start();
helper.login();
helper.login(UserService.DEFAULT_PASSWORD);
helper.hideBackupReminder();
String path = getClass().getClassLoader().getResource("SearchDatabase.json").getFile().replace("/", File.separator);
......
package de.deadlocker8.budgetmaster.integration;
import de.deadlocker8.budgetmaster.authentication.UserService;
import de.thecodelabs.utils.util.Localization;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import java.io.File;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
class IntegrationTestHelper
{
......@@ -36,15 +33,20 @@ class IntegrationTestHelper
this.url = BASE_URL + port;
}
public String getUrl()
{
return url;
}
void start()
{
driver.get(url);
}
void login()
void login(String password)
{
WebElement inputPassword = driver.findElement(By.id("login-password"));
inputPassword.sendKeys(UserService.DEFAULT_PASSWORD);
inputPassword.sendKeys(password);
WebElement buttonLogin = driver.findElement(By.tagName("button"));
buttonLogin.click();
}
......
package de.deadlocker8.budgetmaster.integration;
import de.deadlocker8.budgetmaster.Main;
import de.deadlocker8.budgetmaster.authentication.UserService;
import de.thecodelabs.utils.util.Localization;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openqa.selenium.By;
......@@ -24,22 +24,16 @@ public class LoginControllerTest
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
@Autowired
private WebDriver driver;
private final static String BASE_URL = "https://localhost:";
private String url;
@LocalServerPort
int port;
@Before
public void before()
{
url = BASE_URL + port;
}
@Test
public void getLoginPage()
{
driver.get(url);
IntegrationTestHelper helper = new IntegrationTestHelper(driver, port);
helper.start();
WebElement input = driver.findElement(By.id("login-password"));
assertNotNull(input);
......@@ -49,4 +43,41 @@ public class LoginControllerTest
WebElement button = driver.findElement(By.tagName("button"));
assertEquals(Localization.getString("login.button"), IntegrationTestHelper.getTextNode(button));
}
@Test
public void wrongCredentials()
{
IntegrationTestHelper helper = new IntegrationTestHelper(driver, port);
helper.start();
helper.login("akhjfvbvahsdsa");
WebElement label = driver.findElement(By.id("loginMessage"));
assertEquals(Localization.getString("warning.wrong.password"), label.getText());
}
@Test
public void successLogin()
{
IntegrationTestHelper helper = new IntegrationTestHelper(driver, port);
helper.start();
helper.login(UserService.DEFAULT_PASSWORD);
WebElement label = driver.findElement(By.id("logo-home"));
String expected = helper.getUrl() + "/images/Logo_with_text_medium_res.png";
assertEquals(expected, label.getAttribute("src"));
}
@Test
public void logout()
{
IntegrationTestHelper helper = new IntegrationTestHelper(driver, port);
helper.start();
helper.login(UserService.DEFAULT_PASSWORD);
WebElement buttonLogout = driver.findElement(By.xpath("//body/ul/li/a[contains(text(), 'Logout')]"));
buttonLogout.click();
WebElement label = driver.findElement(By.id("loginMessage"));
assertEquals(Localization.getString("logout.success"), label.getText());
}
}
\ 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