diff --git a/.github/workflows/test_docker.yml b/.github/workflows/test_docker.yml index df1e84c72..34cba82ad 100644 --- a/.github/workflows/test_docker.yml +++ b/.github/workflows/test_docker.yml @@ -32,7 +32,19 @@ jobs: run: | ARCH="${{ matrix.runs-on == 'ubuntu-24.04-arm' && 'arm64' || 'amd64' }}" bash utils/docker/build.sh --$ARCH ${{ matrix.flavor }} playwright-java:localbuild-${{ matrix.flavor }} - - name: Test + - name: Start container run: | - CONTAINER_ID="$(docker run --rm -e CI --ipc=host -v $(pwd):/root/playwright --name playwright-docker-test -d -t playwright-java:localbuild-${{ matrix.flavor }} /bin/bash)" - docker exec "${CONTAINER_ID}" /root/playwright/tools/test-local-installation/create_project_and_run_tests.sh + CONTAINER_ID=$(docker run --rm -e CI --ipc=host -v "$(pwd)":/root/playwright --name playwright-docker-test -d -t playwright-java:localbuild-${{ matrix.flavor }} /bin/bash) + echo "CONTAINER_ID=$CONTAINER_ID" >> $GITHUB_ENV + + - name: Run test in container + run: | + docker exec "$CONTAINER_ID" /root/playwright/tools/test-local-installation/create_project_and_run_tests.sh + + - name: Test ClassLoader + run: | + docker exec "${CONTAINER_ID}" /root/playwright/tools/test-spring-boot-starter/package_and_run_async_test.sh + + - name: Stop container + run: | + docker stop "$CONTAINER_ID" 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..654ff6732 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 @@ -114,7 +114,7 @@ private FileSystem initFileSystem(URI uri) throws IOException { } public static URI getDriverResourceURI() throws URISyntaxException { - ClassLoader classloader = Thread.currentThread().getContextClassLoader(); + ClassLoader classloader = DriverJar.class.getClassLoader(); return classloader.getResource("driver/" + platformDir()).toURI(); } diff --git a/tools/test-spring-boot-starter/package_and_run_async_test.sh b/tools/test-spring-boot-starter/package_and_run_async_test.sh new file mode 100755 index 000000000..ac6875fce --- /dev/null +++ b/tools/test-spring-boot-starter/package_and_run_async_test.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +set -e +set +x + +cd "$(dirname "$0")" +mvn package -D skipTests --no-transfer-progress +java -jar target/test-spring-boot-starter*.jar --async diff --git a/tools/test-spring-boot-starter/src/main/java/com/microsoft/playwright/springboottest/TestApp.java b/tools/test-spring-boot-starter/src/main/java/com/microsoft/playwright/springboottest/TestApp.java index 35e669ec9..6a36d530f 100644 --- a/tools/test-spring-boot-starter/src/main/java/com/microsoft/playwright/springboottest/TestApp.java +++ b/tools/test-spring-boot-starter/src/main/java/com/microsoft/playwright/springboottest/TestApp.java @@ -5,6 +5,9 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import java.util.Arrays; +import java.util.concurrent.CompletableFuture; + @SpringBootApplication public class TestApp implements CommandLineRunner { @@ -14,6 +17,19 @@ public static void main(String[] args) { @Override public void run(String... args) { + if (Arrays.asList(args).contains("--async")) { + runAsync(); + } else { + runSync(); + } + } + + private void runAsync() { + CompletableFuture voidCompletableFuture = CompletableFuture.runAsync(this::runSync); + voidCompletableFuture.join(); + } + + private void runSync() { try (Playwright playwright = Playwright.create()) { BrowserType browserType = getBrowserTypeFromEnv(playwright); System.out.println("Running test with " + browserType.name());