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

View File

@@ -10,9 +10,20 @@ import lombok.experimental.UtilityClass;
public class PlaywrightTestUtils {
public static void login(Page page) {
page.getByPlaceholder("User Name or E-mail").fill("admin");
page.getByPlaceholder("Password").fill("admin");
login(page, "admin", "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();
}
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();
}
}