diff --git a/commafeed-server/src/test/java/com/commafeed/e2e/AuthentificationIT.java b/commafeed-server/src/test/java/com/commafeed/e2e/AuthentificationIT.java index 3dde120c..56f12089 100644 --- a/commafeed-server/src/test/java/com/commafeed/e2e/AuthentificationIT.java +++ b/commafeed-server/src/test/java/com/commafeed/e2e/AuthentificationIT.java @@ -5,7 +5,9 @@ import org.junit.jupiter.api.extension.ExtendWith; import com.commafeed.CommaFeedDropwizardAppExtension; import com.microsoft.playwright.Locator; +import com.microsoft.playwright.Page; import com.microsoft.playwright.assertions.PlaywrightAssertions; +import com.microsoft.playwright.options.AriaRole; import io.dropwizard.testing.junit5.DropwizardExtensionsSupport; @@ -17,10 +19,10 @@ class AuthentificationIT extends PlaywrightTestBase { @Test void loginFail() { page.navigate(getLoginPageUrl()); - page.locator("[placeholder='User Name or E-mail']").fill("admin"); - page.locator("[placeholder='Password']").fill("wrong_password"); - page.locator("button:has-text('Log in')").click(); - PlaywrightAssertions.assertThat(page.locator("div[role='alert']")).containsText("wrong username or password"); + 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"); } @Test @@ -33,13 +35,13 @@ class AuthentificationIT extends PlaywrightTestBase { @Test void registerFailPasswordTooSimple() { page.navigate(getLoginPageUrl()); - page.locator("text=Sign up!").click(); - page.locator("[placeholder='User Name']").fill("user"); - page.locator("[placeholder='E-mail address']").fill("user@domain.com"); - page.locator("[placeholder='Password']").fill("pass"); - page.locator("button:has-text('Sign up')").click(); + 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(); - Locator alert = page.locator("div[role='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 contain 1 or more uppercase characters."); PlaywrightAssertions.assertThat(alert).containsText("Password must contain 1 or more digit characters."); @@ -49,11 +51,11 @@ class AuthentificationIT extends PlaywrightTestBase { @Test void registerSuccess() { page.navigate(getLoginPageUrl()); - page.locator("text=Sign up!").click(); - page.locator("[placeholder='User Name']").fill("user"); - page.locator("[placeholder='E-mail address']").fill("user@domain.com"); - page.locator("[placeholder='Password']").fill("MyPassword1!"); - page.locator("button:has-text('Sign up')").click(); + 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(); PlaywrightAssertions.assertThat(page).hasURL("http://localhost:" + EXT.getLocalPort() + "/#/app/category/all"); } diff --git a/commafeed-server/src/test/java/com/commafeed/e2e/PlaywrightTestUtils.java b/commafeed-server/src/test/java/com/commafeed/e2e/PlaywrightTestUtils.java index fc3d7705..d0f74b80 100644 --- a/commafeed-server/src/test/java/com/commafeed/e2e/PlaywrightTestUtils.java +++ b/commafeed-server/src/test/java/com/commafeed/e2e/PlaywrightTestUtils.java @@ -1,6 +1,8 @@ package com.commafeed.e2e; import com.microsoft.playwright.Page; +import com.microsoft.playwright.Page.GetByRoleOptions; +import com.microsoft.playwright.options.AriaRole; import lombok.experimental.UtilityClass; @@ -8,9 +10,9 @@ import lombok.experimental.UtilityClass; public class PlaywrightTestUtils { public static void login(Page page) { - page.locator("[placeholder='User Name or E-mail']").fill("admin"); - page.locator("[placeholder='Password']").fill("admin"); - page.locator("button:has-text('Log in')").click(); + page.getByPlaceholder("User Name or E-mail").fill("admin"); + page.getByPlaceholder("Password").fill("admin"); + page.getByRole(AriaRole.BUTTON, new GetByRoleOptions().setName("Log in")).click(); } } diff --git a/commafeed-server/src/test/java/com/commafeed/e2e/ReadingIT.java b/commafeed-server/src/test/java/com/commafeed/e2e/ReadingIT.java index 00df493d..0e0f2ce0 100644 --- a/commafeed-server/src/test/java/com/commafeed/e2e/ReadingIT.java +++ b/commafeed-server/src/test/java/com/commafeed/e2e/ReadingIT.java @@ -15,6 +15,7 @@ import org.mockserver.model.HttpResponse; import com.commafeed.CommaFeedDropwizardAppExtension; import com.microsoft.playwright.Locator; +import com.microsoft.playwright.Page; import com.microsoft.playwright.assertions.PlaywrightAssertions; import com.microsoft.playwright.options.AriaRole; @@ -40,34 +41,42 @@ class ReadingIT extends PlaywrightTestBase { void scenario() { // login page.navigate("http://localhost:" + EXT.getLocalPort()); - page.locator("button:has-text('Log in')").click(); + page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Log in")).click(); PlaywrightTestUtils.login(page); - PlaywrightAssertions.assertThat(page.locator("text=You don't have any subscriptions yet.")).hasCount(1); + + Locator header = page.getByRole(AriaRole.BANNER); + Locator sidebar = page.getByRole(AriaRole.NAVIGATION); + Locator main = page.getByRole(AriaRole.MAIN); + + PlaywrightAssertions.assertThat(main.getByText("You don't have any subscriptions yet.")).hasCount(1); // subscribe - page.locator("[aria-label='Subscribe']").click(); - page.locator("text=Feed URL *").fill("http://localhost:" + this.mockServerClient.getPort()); - page.locator("button:has-text('Next')").click(); - page.locator("button:has-text('Subscribe')").nth(2).click(); + header.getByRole(AriaRole.BUTTON, new Locator.GetByRoleOptions().setName("Subscribe")).click(); + main.getByText("Feed URL *").fill("http://localhost:" + this.mockServerClient.getPort()); + main.getByRole(AriaRole.BUTTON, new Locator.GetByRoleOptions().setName("Next")).click(); + main.getByRole(AriaRole.BUTTON, new Locator.GetByRoleOptions().setName("Subscribe").setExact(true)).click(); // click on subscription - page.getByRole(AriaRole.NAVIGATION).getByText(Pattern.compile("CommaFeed test feed\\d+")).click(); + sidebar.getByText(Pattern.compile("CommaFeed test feed\\d+")).click(); // we have two unread entries - Locator entries = page.locator("main >> .mantine-Paper-root"); - PlaywrightAssertions.assertThat(entries).hasCount(2); + PlaywrightAssertions.assertThat(main.locator(".mantine-Paper-root")).hasCount(2); // click on first entry - page.locator("text='Item 1'").click(); - PlaywrightAssertions.assertThat(page.locator("text=Item 1 description")).hasCount(1); - PlaywrightAssertions.assertThat(page.locator("text=Item 2 description")).hasCount(0); + main.getByText("Item 1").click(); + PlaywrightAssertions.assertThat(main.getByText("Item 1 description")).hasCount(1); + PlaywrightAssertions.assertThat(main.getByText("Item 2 description")).hasCount(0); + + // click on subscription + sidebar.getByText(Pattern.compile("CommaFeed test feed\\d+")).click(); + // only one unread entry now - PlaywrightAssertions.assertThat(page.locator("nav >> text=CommaFeed test feed1")).hasCount(1); + PlaywrightAssertions.assertThat(main.locator(".mantine-Paper-root")).hasCount(1); // click on second entry - page.locator("text=Item 2").click(); - PlaywrightAssertions.assertThat(page.locator("text=Item 1 description")).hasCount(0); - PlaywrightAssertions.assertThat(page.locator("text=Item 2 description")).hasCount(1); + main.getByText("Item 2").click(); + PlaywrightAssertions.assertThat(main.getByText("Item 1 description")).hasCount(0); + PlaywrightAssertions.assertThat(main.getByText("Item 2 description")).hasCount(1); } }