From 80a09bd9a0d2f13bec0bc98cbd4dfbedf24c0b6b Mon Sep 17 00:00:00 2001 From: Athou Date: Thu, 26 Jun 2025 21:30:29 +0200 Subject: [PATCH] use quarkus-playwright to simplify tests --- commafeed-server/pom.xml | 12 ++++----- .../com/commafeed/e2e/AuthentificationIT.java | 24 ++++++++---------- .../com/commafeed/e2e/DocumentationIT.java | 25 ++++++------------- .../java/com/commafeed/e2e/ReadingIT.java | 16 ++++++------ 4 files changed, 32 insertions(+), 45 deletions(-) diff --git a/commafeed-server/pom.xml b/commafeed-server/pom.xml index 2f2246fd..33340911 100644 --- a/commafeed-server/pom.xml +++ b/commafeed-server/pom.xml @@ -503,6 +503,12 @@ quarkus-junit5-mockito test + + io.quarkiverse.playwright + quarkus-playwright + 2.1.1 + test + org.mock-server mockserver-junit-jupiter @@ -519,12 +525,6 @@ awaitility test - - com.microsoft.playwright - playwright - 1.52.0 - test - org.reflections reflections 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 af9698fc..499ce1ab 100644 --- a/commafeed-server/src/test/java/com/commafeed/e2e/AuthentificationIT.java +++ b/commafeed-server/src/test/java/com/commafeed/e2e/AuthentificationIT.java @@ -1,38 +1,33 @@ package com.commafeed.e2e; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import com.microsoft.playwright.Browser; +import com.microsoft.playwright.BrowserContext; import com.microsoft.playwright.Locator; import com.microsoft.playwright.Page; -import com.microsoft.playwright.Playwright; import com.microsoft.playwright.assertions.PlaywrightAssertions; import com.microsoft.playwright.options.AriaRole; +import io.quarkiverse.playwright.InjectPlaywright; +import io.quarkiverse.playwright.WithPlaywright; import io.quarkus.test.junit.QuarkusTest; @QuarkusTest +@WithPlaywright class AuthentificationIT { - private final Playwright playwright = Playwright.create(); - private final Browser browser = playwright.chromium().launch(); - - private Page page; - - @BeforeEach - void init() { - page = browser.newContext().newPage(); - } + @InjectPlaywright + private BrowserContext context; @AfterEach void cleanup() { - playwright.close(); + context.clearCookies(); } @Test void loginFail() { + Page page = context.newPage(); page.navigate(getLoginPageUrl()); page.getByPlaceholder("User Name or E-mail").fill("admin"); page.getByPlaceholder("Password").fill("wrong_password"); @@ -42,6 +37,7 @@ class AuthentificationIT { @Test void loginSuccess() { + Page page = context.newPage(); page.navigate(getLoginPageUrl()); PlaywrightTestUtils.login(page); PlaywrightAssertions.assertThat(page).hasURL("http://localhost:8085/#/app/category/all"); @@ -49,6 +45,7 @@ class AuthentificationIT { @Test void registerFailPasswordTooSimple() { + Page page = context.newPage(); page.navigate(getLoginPageUrl()); page.getByText("Sign up!").click(); page.getByPlaceholder("User Name").fill("user"); @@ -65,6 +62,7 @@ class AuthentificationIT { @Test void registerSuccess() { + Page page = context.newPage(); page.navigate(getLoginPageUrl()); page.getByText("Sign up!").click(); page.getByPlaceholder("User Name").fill("user"); diff --git a/commafeed-server/src/test/java/com/commafeed/e2e/DocumentationIT.java b/commafeed-server/src/test/java/com/commafeed/e2e/DocumentationIT.java index a4dc1b75..5c7b3c0e 100644 --- a/commafeed-server/src/test/java/com/commafeed/e2e/DocumentationIT.java +++ b/commafeed-server/src/test/java/com/commafeed/e2e/DocumentationIT.java @@ -1,36 +1,25 @@ package com.commafeed.e2e; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import com.microsoft.playwright.Browser; +import com.microsoft.playwright.BrowserContext; import com.microsoft.playwright.Page; -import com.microsoft.playwright.Playwright; import com.microsoft.playwright.assertions.PlaywrightAssertions; +import io.quarkiverse.playwright.InjectPlaywright; +import io.quarkiverse.playwright.WithPlaywright; import io.quarkus.test.junit.QuarkusTest; @QuarkusTest +@WithPlaywright class DocumentationIT { - private final Playwright playwright = Playwright.create(); - private final Browser browser = playwright.chromium().launch(); - - private Page page; - - @BeforeEach - void init() { - page = browser.newContext().newPage(); - } - - @AfterEach - void cleanup() { - playwright.close(); - } + @InjectPlaywright + private BrowserContext context; @Test void documentationAvailable() { + Page page = context.newPage(); page.navigate("http://localhost:8085/#/api"); PlaywrightAssertions.assertThat(page.getByText("Download OpenAPI specification:")).isVisible(); } 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 56b6f9bf..6e22c40c 100644 --- a/commafeed-server/src/test/java/com/commafeed/e2e/ReadingIT.java +++ b/commafeed-server/src/test/java/com/commafeed/e2e/ReadingIT.java @@ -17,28 +17,28 @@ import org.mockserver.model.HttpRequest; import org.mockserver.model.HttpResponse; import com.commafeed.frontend.model.Entries; -import com.microsoft.playwright.Browser; +import com.microsoft.playwright.BrowserContext; import com.microsoft.playwright.Locator; import com.microsoft.playwright.Page; -import com.microsoft.playwright.Playwright; import com.microsoft.playwright.assertions.PlaywrightAssertions; import com.microsoft.playwright.options.AriaRole; +import io.quarkiverse.playwright.InjectPlaywright; +import io.quarkiverse.playwright.WithPlaywright; import io.quarkus.test.junit.QuarkusTest; import io.restassured.RestAssured; @QuarkusTest +@WithPlaywright class ReadingIT { - private final Playwright playwright = Playwright.create(); - private final Browser browser = playwright.chromium().launch(); + @InjectPlaywright + private BrowserContext context; - private Page page; private MockServerClient mockServerClient; @BeforeEach void init() throws IOException { - this.page = browser.newContext().newPage(); this.mockServerClient = ClientAndServer.startClientAndServer(0); this.mockServerClient.when(HttpRequest.request().withMethod("GET")) .respond(HttpResponse.response() @@ -50,13 +50,13 @@ class ReadingIT { @AfterEach void cleanup() { - playwright.close(); - RestAssured.reset(); } @Test void scenario() { + Page page = context.newPage(); + // login page.navigate("http://localhost:8085"); page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Log in")).click();