From 86cff6706f85990b9bf9b66edbf6b3d5c5241fdb Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Sat, 15 Mar 2025 22:09:06 +0100 Subject: [PATCH 1/9] test: cleanup test run warnings --- .../microsoft/playwright/impl/driver/jar/DriverJar.java | 6 ++++-- .../microsoft/playwright/impl/driver/jar/TestInstall.java | 1 + playwright/pom.xml | 4 ++++ .../src/test/java/com/microsoft/playwright/Server.java | 2 +- .../playwright/TestBrowserContextCredentials.java | 1 - .../java/com/microsoft/playwright/TestGlobalFetch.java | 2 +- pom.xml | 7 +++++++ 7 files changed, 18 insertions(+), 5 deletions(-) diff --git a/driver-bundle/src/main/java/com/microsoft/playwright/impl/driver/jar/DriverJar.java b/driver-bundle/src/main/java/com/microsoft/playwright/impl/driver/jar/DriverJar.java index 3fe7537d8..05135799b 100644 --- a/driver-bundle/src/main/java/com/microsoft/playwright/impl/driver/jar/DriverJar.java +++ b/driver-bundle/src/main/java/com/microsoft/playwright/impl/driver/jar/DriverJar.java @@ -87,8 +87,10 @@ private void installBrowsers(Map env) throws IOException, Interr } ProcessBuilder pb = createProcessBuilder(); pb.command().add("install"); - pb.redirectError(ProcessBuilder.Redirect.INHERIT); - pb.redirectOutput(ProcessBuilder.Redirect.INHERIT); + if (System.getenv("PW_JAVA_INTERNAL_SILENT_INSTALL") != null) { + pb.redirectError(ProcessBuilder.Redirect.INHERIT); + pb.redirectOutput(ProcessBuilder.Redirect.INHERIT); + } Process p = pb.start(); boolean result = p.waitFor(10, TimeUnit.MINUTES); if (!result) { diff --git a/driver-bundle/src/test/java/com/microsoft/playwright/impl/driver/jar/TestInstall.java b/driver-bundle/src/test/java/com/microsoft/playwright/impl/driver/jar/TestInstall.java index 953549bf1..2586193c7 100644 --- a/driver-bundle/src/test/java/com/microsoft/playwright/impl/driver/jar/TestInstall.java +++ b/driver-bundle/src/test/java/com/microsoft/playwright/impl/driver/jar/TestInstall.java @@ -74,6 +74,7 @@ void shouldThrowWhenBrowserPathIsInvalid(@TempDir Path tmpDir) throws NoSuchFiel // Make sure the browsers are not installed yet by pointing at an empty dir. env.put("PLAYWRIGHT_BROWSERS_PATH", tmpDir.toString()); env.put("PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD", "false"); + env.put("PW_JAVA_INTERNAL_SILENT_INSTALL", "true"); RuntimeException exception = assertThrows(RuntimeException.class, () -> Driver.createAndInstall(env, true)); String message = exception.getMessage(); diff --git a/playwright/pom.xml b/playwright/pom.xml index 179095ecb..7785e62ca 100644 --- a/playwright/pom.xml +++ b/playwright/pom.xml @@ -57,6 +57,10 @@ org.java-websocket Java-WebSocket + + org.slf4j + slf4j-simple + org.junit.jupiter junit-jupiter-engine diff --git a/playwright/src/test/java/com/microsoft/playwright/Server.java b/playwright/src/test/java/com/microsoft/playwright/Server.java index 5d42d0830..beeea69d8 100644 --- a/playwright/src/test/java/com/microsoft/playwright/Server.java +++ b/playwright/src/test/java/com/microsoft/playwright/Server.java @@ -218,7 +218,7 @@ public void handle(HttpExchange exchange) throws IOException { } long contentLength = body.size(); // -1 means no body, 0 means chunked encoding. - exchange.sendResponseHeaders(200, contentLength == 0 ? -1 : contentLength); + exchange.sendResponseHeaders(200, (contentLength == 0 || exchange.getRequestMethod().equals("HEAD")) ? -1 : contentLength); if (contentLength > 0) { exchange.getResponseBody().write(body.toByteArray()); } diff --git a/playwright/src/test/java/com/microsoft/playwright/TestBrowserContextCredentials.java b/playwright/src/test/java/com/microsoft/playwright/TestBrowserContextCredentials.java index ce556273e..addf6e549 100644 --- a/playwright/src/test/java/com/microsoft/playwright/TestBrowserContextCredentials.java +++ b/playwright/src/test/java/com/microsoft/playwright/TestBrowserContextCredentials.java @@ -33,7 +33,6 @@ static boolean isChromiumHeadedLike() { @Test @DisabledIf(value="isChromiumHeadedLike", disabledReason="fail") void shouldFailWithoutCredentials() { - System.out.println("channel2 " + getBrowserChannelFromEnv()); server.setAuth("/empty.html", "user", "pass"); Response response = page.navigate(server.EMPTY_PAGE); assertEquals(401, response.status()); diff --git a/playwright/src/test/java/com/microsoft/playwright/TestGlobalFetch.java b/playwright/src/test/java/com/microsoft/playwright/TestGlobalFetch.java index 1993d2aa5..e681d70a6 100644 --- a/playwright/src/test/java/com/microsoft/playwright/TestGlobalFetch.java +++ b/playwright/src/test/java/com/microsoft/playwright/TestGlobalFetch.java @@ -337,7 +337,7 @@ void shouldReturnBodyForFailingRequests() { for (String method : new String[] {"head", "put", "trace"}) { server.setRoute("/empty.html", exchange -> { exchange.getResponseHeaders().set("Content-type", "text/plain"); - exchange.sendResponseHeaders(404, 10); + exchange.sendResponseHeaders(404, exchange.getRequestMethod().equals("HEAD") ? -1 : 10); try (Writer writer = new OutputStreamWriter(exchange.getResponseBody())) { writer.write("Not found."); } diff --git a/pom.xml b/pom.xml index bb697a5e0..14deed34b 100644 --- a/pom.xml +++ b/pom.xml @@ -48,6 +48,7 @@ 5.12.0 UTF-8 1.6.0 + 2.0.17 1.3.0 @@ -91,6 +92,12 @@ ${websocket.version} test + + org.slf4j + slf4j-simple + ${slf4j.version} + test + org.junit.jupiter junit-jupiter-api From 3e15aaae45f1b7cdd851fbcd966505bf8410e469 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Sat, 15 Mar 2025 22:09:31 +0100 Subject: [PATCH 2/9] devops: bump GitHub Action workflows and bump timeouts --- .github/workflows/test.yml | 16 ++++++++-------- .github/workflows/test_cli.yml | 2 +- .github/workflows/verify_api.yml | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 291d3886f..90d93bcb5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,9 +20,9 @@ jobs: browser: [chromium, firefox, webkit] runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up JDK 1.8 - uses: actions/setup-java@v2 + uses: actions/setup-java@v4 with: distribution: zulu java-version: 8 @@ -52,7 +52,7 @@ jobs: java -jar target/test-spring-boot*.jar stable: - timeout-minutes: 30 + timeout-minutes: 60 strategy: fail-fast: false matrix: @@ -65,13 +65,13 @@ jobs: browser-channel: msedge runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Install Media Pack if: matrix.os == 'windows-latest' shell: powershell run: Install-WindowsFeature Server-Media-Foundation - name: Set up JDK 1.8 - uses: actions/setup-java@v2 + uses: actions/setup-java@v4 with: distribution: zulu java-version: 8 @@ -93,16 +93,16 @@ jobs: BROWSER_CHANNEL: ${{ matrix.browser-channel }} Java_21: - timeout-minutes: 30 + timeout-minutes: 60 strategy: fail-fast: false matrix: browser: [chromium, firefox, webkit] runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up JDK 21 - uses: actions/setup-java@v2 + uses: actions/setup-java@v4 with: distribution: adopt java-version: 21 diff --git a/.github/workflows/test_cli.yml b/.github/workflows/test_cli.yml index d04887be9..f5e8d70c9 100644 --- a/.github/workflows/test_cli.yml +++ b/.github/workflows/test_cli.yml @@ -13,7 +13,7 @@ jobs: timeout-minutes: 30 runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Cache Maven packages uses: actions/cache@v4 with: diff --git a/.github/workflows/verify_api.yml b/.github/workflows/verify_api.yml index 554fabe01..dbbcfb15d 100644 --- a/.github/workflows/verify_api.yml +++ b/.github/workflows/verify_api.yml @@ -19,7 +19,7 @@ jobs: timeout-minutes: 30 runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Download drivers run: scripts/download_driver.sh - name: Regenerate APIs From 6bb305179534ad9eb423fa8f36a1e98c960b8d9b Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Sat, 15 Mar 2025 23:14:27 +0100 Subject: [PATCH 3/9] Update test.yml --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 90d93bcb5..3b75727ea 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,7 +12,7 @@ env: PW_MAX_RETRIES: 3 jobs: dev: - timeout-minutes: 30 + timeout-minutes: 60 strategy: fail-fast: false matrix: From 8e98e3fbeae9c91a977a75c821f755dd49039965 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Sun, 16 Mar 2025 09:42:19 +0100 Subject: [PATCH 4/9] disable parallelism --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 14deed34b..c5db02219 100644 --- a/pom.xml +++ b/pom.xml @@ -158,7 +158,7 @@ - junit.jupiter.execution.parallel.enabled = true + junit.jupiter.execution.parallel.enabled = false junit.jupiter.execution.parallel.mode.default = same_thread junit.jupiter.execution.parallel.mode.classes.default = concurrent junit.jupiter.execution.parallel.config.strategy=dynamic From fafef05ae4aad2871d06325c788edca3646c8b13 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Mon, 17 Mar 2025 19:17:28 +0100 Subject: [PATCH 5/9] with debug logs --- .github/workflows/test.yml | 2 ++ .../playwright/TestBrowserContextHar.java | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3b75727ea..d5033124c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,6 +19,8 @@ jobs: os: [ubuntu-latest, windows-latest, macos-latest] browser: [chromium, firefox, webkit] runs-on: ${{ matrix.os }} + env: + DEBUG: pw:api steps: - uses: actions/checkout@v4 - name: Set up JDK 1.8 diff --git a/playwright/src/test/java/com/microsoft/playwright/TestBrowserContextHar.java b/playwright/src/test/java/com/microsoft/playwright/TestBrowserContextHar.java index d46aec960..33201cb30 100644 --- a/playwright/src/test/java/com/microsoft/playwright/TestBrowserContextHar.java +++ b/playwright/src/test/java/com/microsoft/playwright/TestBrowserContextHar.java @@ -20,7 +20,11 @@ import com.microsoft.playwright.options.HarMode; import com.microsoft.playwright.options.HarNotFound; import com.microsoft.playwright.options.RouteFromHarUpdateContentPolicy; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; import org.junit.jupiter.api.condition.DisabledIf; import org.junit.jupiter.api.io.TempDir; @@ -44,6 +48,16 @@ import static org.junit.jupiter.api.Assertions.*; public class TestBrowserContextHar extends TestBase { + @BeforeEach + void BeforeEach(TestInfo testInfo) { + System.out.println("BeforeEach::displayName = " + testInfo.getDisplayName()); + } + + @AfterEach + void AfterEach(TestInfo testInfo) { + System.out.println("AfterEach::displayName = " + testInfo.getDisplayName()); + } + @Test void shouldContextRouteFromHARMatchingTheMethodAndFollowingRedirects() { Path path = Paths.get("src/test/resources/har-fulfill.har"); From b7898de85752004f57a2dc3f8ce750c9dc9cd47d Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Mon, 17 Mar 2025 19:34:07 +0100 Subject: [PATCH 6/9] test --- .../microsoft/playwright/TestBrowserContextHar.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/playwright/src/test/java/com/microsoft/playwright/TestBrowserContextHar.java b/playwright/src/test/java/com/microsoft/playwright/TestBrowserContextHar.java index 33201cb30..6602ee560 100644 --- a/playwright/src/test/java/com/microsoft/playwright/TestBrowserContextHar.java +++ b/playwright/src/test/java/com/microsoft/playwright/TestBrowserContextHar.java @@ -218,15 +218,25 @@ void shouldChangeDocumentURLAfterRedirectedNavigationOnClick() { @Test void shouldGoBackToRedirectedNavigation() { Path path = Paths.get("src/test/resources/har-redirect.har"); + System.err.println("shouldGoBackToRedirectedNavigation#1"); context.routeFromHAR(path, new BrowserContext.RouteFromHAROptions().setUrl(Pattern.compile(".*theverge.*"))); + System.err.println("shouldGoBackToRedirectedNavigation#2"); Page page = context.newPage(); + System.err.println("shouldGoBackToRedirectedNavigation#3"); page.navigate("https://theverge.com/"); + System.err.println("shouldGoBackToRedirectedNavigation#4"); page.navigate(server.EMPTY_PAGE); + System.err.println("shouldGoBackToRedirectedNavigation#5"); assertThat(page).hasURL(server.EMPTY_PAGE); + System.err.println("shouldGoBackToRedirectedNavigation#6"); Response response = page.goBack(); + System.err.println("shouldGoBackToRedirectedNavigation#7"); assertThat(page).hasURL("https://www.theverge.com/"); + System.err.println("shouldGoBackToRedirectedNavigation#8"); assertEquals("https://www.theverge.com/", response.request().url()); + System.err.println("shouldGoBackToRedirectedNavigation#9"); assertEquals("https://www.theverge.com/", page.evaluate("location.href")); + System.err.println("shouldGoBackToRedirectedNavigation#10"); } @Test From d355c002547f323fceaefbcedccbd9530099a268 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Mon, 17 Mar 2025 21:29:40 +0100 Subject: [PATCH 7/9] test --- .github/workflows/test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d5033124c..302667702 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -100,6 +100,8 @@ jobs: fail-fast: false matrix: browser: [chromium, firefox, webkit] + env: + DEBUG: pw:api runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 From 91f7b8ca513df6d5ae4df058cc898f11ddc17bd2 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Mon, 17 Mar 2025 21:29:56 +0100 Subject: [PATCH 8/9] test --- .github/workflows/test.yml | 85 +------------------------------------- 1 file changed, 1 insertion(+), 84 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 302667702..a168305f3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,95 +11,12 @@ on: env: PW_MAX_RETRIES: 3 jobs: - dev: - timeout-minutes: 60 - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest, windows-latest, macos-latest] - browser: [chromium, firefox, webkit] - runs-on: ${{ matrix.os }} - env: - DEBUG: pw:api - steps: - - uses: actions/checkout@v4 - - name: Set up JDK 1.8 - uses: actions/setup-java@v4 - with: - distribution: zulu - java-version: 8 - - name: Download drivers - shell: bash - run: scripts/download_driver.sh - - name: Build & Install - run: mvn -B install -D skipTests --no-transfer-progress - - name: Install browsers - run: mvn exec:java -e -D exec.mainClass=com.microsoft.playwright.CLI -D exec.args="install --with-deps" -f playwright/pom.xml --no-transfer-progress - - name: Run tests - run: mvn test --no-transfer-progress --fail-at-end -D org.slf4j.simpleLogger.showDateTime=true -D org.slf4j.simpleLogger.dateTimeFormat=HH:mm:ss - env: - BROWSER: ${{ matrix.browser }} - - name: Run tracing tests w/ sources - run: mvn test --no-transfer-progress --fail-at-end --projects=playwright -D test=*TestTracing* -D org.slf4j.simpleLogger.showDateTime=true -D org.slf4j.simpleLogger.dateTimeFormat=HH:mm:ss - env: - BROWSER: ${{ matrix.browser }} - PLAYWRIGHT_JAVA_SRC: src/test/java - - name: Test Spring Boot Starter - shell: bash - env: - BROWSER: ${{ matrix.browser }} - run: | - cd tools/test-spring-boot-starter - mvn package -D skipTests --no-transfer-progress - java -jar target/test-spring-boot*.jar - - stable: - timeout-minutes: 60 - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest, windows-latest, macos-latest] - browser-channel: [chrome] - include: - - os: windows-latest - browser-channel: msedge - - os: macos-latest - browser-channel: msedge - runs-on: ${{ matrix.os }} - steps: - - uses: actions/checkout@v4 - - name: Install Media Pack - if: matrix.os == 'windows-latest' - shell: powershell - run: Install-WindowsFeature Server-Media-Foundation - - name: Set up JDK 1.8 - uses: actions/setup-java@v4 - with: - distribution: zulu - java-version: 8 - - name: Download drivers - shell: bash - run: scripts/download_driver.sh - - name: Build & Install - run: mvn -B install -D skipTests --no-transfer-progress - - name: Install browsers - run: mvn exec:java -e -D exec.mainClass=com.microsoft.playwright.CLI -D exec.args="install --with-deps" -f playwright/pom.xml --no-transfer-progress - - name: Install MS Edge - if: matrix.browser-channel == 'msedge' && matrix.os == 'macos-latest' - shell: bash - run: mvn exec:java -e -D exec.mainClass=com.microsoft.playwright.CLI -D exec.args="install msedge" -f playwright/pom.xml - - name: Run tests - run: mvn test --no-transfer-progress --fail-at-end -D org.slf4j.simpleLogger.showDateTime=true -D org.slf4j.simpleLogger.dateTimeFormat=HH:mm:ss - env: - BROWSER: chromium - BROWSER_CHANNEL: ${{ matrix.browser-channel }} - Java_21: timeout-minutes: 60 strategy: fail-fast: false matrix: - browser: [chromium, firefox, webkit] + browser: [webkit,webkit,webkit,webkit,webkit,webkit,webkit] env: DEBUG: pw:api runs-on: ubuntu-latest From 25e478fb021c8a1653f261298b23685e6949e663 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Mon, 17 Mar 2025 22:02:07 +0100 Subject: [PATCH 9/9] test --- .github/workflows/test.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a168305f3..27d10d231 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,8 +17,6 @@ jobs: fail-fast: false matrix: browser: [webkit,webkit,webkit,webkit,webkit,webkit,webkit] - env: - DEBUG: pw:api runs-on: ubuntu-latest steps: - uses: actions/checkout@v4