Files
Athou_commafeed/commafeed-server/src/test/java/com/commafeed/e2e/AuthentificationIT.java

66 lines
2.7 KiB
Java
Raw Normal View History

2022-08-13 13:00:23 +02:00
package com.commafeed.e2e;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
2023-08-23 20:21:45 +02:00
import com.commafeed.CommaFeedDropwizardAppExtension;
2022-08-13 13:00:23 +02:00
import com.microsoft.playwright.Locator;
2024-06-12 11:35:05 +02:00
import com.microsoft.playwright.Page;
2022-08-13 13:00:23 +02:00
import com.microsoft.playwright.assertions.PlaywrightAssertions;
2024-06-12 11:35:05 +02:00
import com.microsoft.playwright.options.AriaRole;
2022-08-13 13:00:23 +02:00
import io.dropwizard.testing.junit5.DropwizardExtensionsSupport;
@ExtendWith(DropwizardExtensionsSupport.class)
class AuthentificationIT extends PlaywrightTestBase {
2023-08-23 20:21:45 +02:00
private static final CommaFeedDropwizardAppExtension EXT = new CommaFeedDropwizardAppExtension();
2022-08-13 13:00:23 +02:00
@Test
void loginFail() {
2023-05-04 21:27:02 +02:00
page.navigate(getLoginPageUrl());
2024-06-12 11:35:05 +02:00
page.getByPlaceholder("User Name or E-mail").fill("admin");
page.getByPlaceholder("Password").fill("wrong_password");
page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Log in")).click();
PlaywrightAssertions.assertThat(page.getByRole(AriaRole.ALERT)).containsText("wrong username or password");
2022-08-13 13:00:23 +02:00
}
@Test
void loginSuccess() {
2023-05-04 21:27:02 +02:00
page.navigate(getLoginPageUrl());
2022-08-13 13:00:23 +02:00
PlaywrightTestUtils.login(page);
PlaywrightAssertions.assertThat(page).hasURL("http://localhost:" + EXT.getLocalPort() + "/#/app/category/all");
}
@Test
void registerFailPasswordTooSimple() {
2023-05-04 21:27:02 +02:00
page.navigate(getLoginPageUrl());
2024-06-12 11:35:05 +02:00
page.getByText("Sign up!").click();
page.getByPlaceholder("User Name").fill("user");
page.getByPlaceholder("E-mail address").fill("user@domain.com");
page.getByPlaceholder("Password").fill("pass");
page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Sign up")).click();
2022-08-13 13:00:23 +02:00
2024-06-12 11:35:05 +02:00
Locator alert = page.getByRole(AriaRole.ALERT);
2022-08-13 13:00:23 +02:00
PlaywrightAssertions.assertThat(alert).containsText("Password must be 8 or more characters in length.");
PlaywrightAssertions.assertThat(alert).containsText("Password must contain 1 or more uppercase characters.");
PlaywrightAssertions.assertThat(alert).containsText("Password must contain 1 or more digit characters.");
PlaywrightAssertions.assertThat(alert).containsText("Password must contain 1 or more special characters.");
}
@Test
void registerSuccess() {
2023-05-04 21:27:02 +02:00
page.navigate(getLoginPageUrl());
2024-06-12 11:35:05 +02:00
page.getByText("Sign up!").click();
page.getByPlaceholder("User Name").fill("user");
page.getByPlaceholder("E-mail address").fill("user@domain.com");
page.getByPlaceholder("Password").fill("MyPassword1!");
page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Sign up")).click();
2022-08-13 13:00:23 +02:00
PlaywrightAssertions.assertThat(page).hasURL("http://localhost:" + EXT.getLocalPort() + "/#/app/category/all");
}
2023-05-04 21:27:02 +02:00
private String getLoginPageUrl() {
return "http://localhost:" + EXT.getLocalPort() + "/#/login";
}
2022-08-13 13:00:23 +02:00
}