Skip to content

Commit d26dd0b

Browse files
authored
fix: Replaced classLoader in DriverJar (#1811)
1 parent 0cf8c4e commit d26dd0b

File tree

4 files changed

+40
-4
lines changed

4 files changed

+40
-4
lines changed

.github/workflows/test_docker.yml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,19 @@ jobs:
3232
run: |
3333
ARCH="${{ matrix.runs-on == 'ubuntu-24.04-arm' && 'arm64' || 'amd64' }}"
3434
bash utils/docker/build.sh --$ARCH ${{ matrix.flavor }} playwright-java:localbuild-${{ matrix.flavor }}
35-
- name: Test
35+
- name: Start container
3636
run: |
37-
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)"
38-
docker exec "${CONTAINER_ID}" /root/playwright/tools/test-local-installation/create_project_and_run_tests.sh
37+
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)
38+
echo "CONTAINER_ID=$CONTAINER_ID" >> $GITHUB_ENV
39+
40+
- name: Run test in container
41+
run: |
42+
docker exec "$CONTAINER_ID" /root/playwright/tools/test-local-installation/create_project_and_run_tests.sh
43+
44+
- name: Test ClassLoader
45+
run: |
46+
docker exec "${CONTAINER_ID}" /root/playwright/tools/test-spring-boot-starter/package_and_run_async_test.sh
47+
48+
- name: Stop container
49+
run: |
50+
docker stop "$CONTAINER_ID"

driver-bundle/src/main/java/com/microsoft/playwright/impl/driver/jar/DriverJar.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ private FileSystem initFileSystem(URI uri) throws IOException {
114114
}
115115

116116
public static URI getDriverResourceURI() throws URISyntaxException {
117-
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
117+
ClassLoader classloader = DriverJar.class.getClassLoader();
118118
return classloader.getResource("driver/" + platformDir()).toURI();
119119
}
120120

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
set -e
4+
set +x
5+
6+
cd "$(dirname "$0")"
7+
mvn package -D skipTests --no-transfer-progress
8+
java -jar target/test-spring-boot-starter*.jar --async

tools/test-spring-boot-starter/src/main/java/com/microsoft/playwright/springboottest/TestApp.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
import org.springframework.boot.SpringApplication;
66
import org.springframework.boot.autoconfigure.SpringBootApplication;
77

8+
import java.util.Arrays;
9+
import java.util.concurrent.CompletableFuture;
10+
811
@SpringBootApplication
912
public class TestApp implements CommandLineRunner {
1013

@@ -14,6 +17,19 @@ public static void main(String[] args) {
1417

1518
@Override
1619
public void run(String... args) {
20+
if (Arrays.asList(args).contains("--async")) {
21+
runAsync();
22+
} else {
23+
runSync();
24+
}
25+
}
26+
27+
private void runAsync() {
28+
CompletableFuture<Void> voidCompletableFuture = CompletableFuture.runAsync(this::runSync);
29+
voidCompletableFuture.join();
30+
}
31+
32+
private void runSync() {
1733
try (Playwright playwright = Playwright.create()) {
1834
BrowserType browserType = getBrowserTypeFromEnv(playwright);
1935
System.out.println("Running test with " + browserType.name());

0 commit comments

Comments
 (0)