fix playwright tests

This commit is contained in:
Athou
2025-06-30 08:08:01 +02:00
parent a744394faa
commit 57d895daf5
2 changed files with 16 additions and 13 deletions

View File

@@ -29,9 +29,7 @@ class AuthentificationIT {
void loginFail() { void loginFail() {
Page page = context.newPage(); Page page = context.newPage();
page.navigate(getLoginPageUrl()); page.navigate(getLoginPageUrl());
page.getByPlaceholder("User Name or E-mail").fill("admin"); PlaywrightTestUtils.login(page, "admin", "wrong_password");
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"); PlaywrightAssertions.assertThat(page.getByRole(AriaRole.ALERT)).containsText("wrong username or password");
} }
@@ -48,10 +46,7 @@ class AuthentificationIT {
Page page = context.newPage(); Page page = context.newPage();
page.navigate(getLoginPageUrl()); page.navigate(getLoginPageUrl());
page.getByText("Sign up!").click(); page.getByText("Sign up!").click();
page.getByPlaceholder("User Name").fill("user"); PlaywrightTestUtils.register(page, "user", "user@domain.com", "pass");
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();
Locator alert = page.getByRole(AriaRole.ALERT); Locator alert = page.getByRole(AriaRole.ALERT);
PlaywrightAssertions.assertThat(alert).containsText("Password must be 8 or more characters in length."); PlaywrightAssertions.assertThat(alert).containsText("Password must be 8 or more characters in length.");
@@ -65,10 +60,7 @@ class AuthentificationIT {
Page page = context.newPage(); Page page = context.newPage();
page.navigate(getLoginPageUrl()); page.navigate(getLoginPageUrl());
page.getByText("Sign up!").click(); page.getByText("Sign up!").click();
page.getByPlaceholder("User Name").fill("user"); PlaywrightTestUtils.register(page, "user", "user@domain.com", "MyPassword1!");
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();
PlaywrightAssertions.assertThat(page).hasURL("http://localhost:8085/#/app/category/all"); PlaywrightAssertions.assertThat(page).hasURL("http://localhost:8085/#/app/category/all");
} }

View File

@@ -10,9 +10,20 @@ import lombok.experimental.UtilityClass;
public class PlaywrightTestUtils { public class PlaywrightTestUtils {
public static void login(Page page) { public static void login(Page page) {
page.getByPlaceholder("User Name or E-mail").fill("admin"); login(page, "admin", "admin");
page.getByPlaceholder("Password").fill("admin"); }
public static void login(Page page, String username, String password) {
page.getByPlaceholder("User Name or E-mail").fill(username);
page.getByPlaceholder("Password").fill(password);
page.getByRole(AriaRole.BUTTON, new GetByRoleOptions().setName("Log in")).click(); page.getByRole(AriaRole.BUTTON, new GetByRoleOptions().setName("Log in")).click();
} }
public static void register(Page page, String username, String email, String password) {
page.getByPlaceholder("E-mail address").fill(email);
page.getByPlaceholder("User Name").fill(username);
page.getByPlaceholder("Password").fill(password);
page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Sign up")).click();
}
} }