-
Notifications
You must be signed in to change notification settings - Fork 258
fix: Replaced classLoader in DriverJar #1811
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
a7830eb
2b8f04d
3c925b1
04b40cf
999cef6
2b34498
ef25b16
3da9be6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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-classloader*.jar |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <parent> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-parent</artifactId> | ||
| <version>2.4.3</version> | ||
| </parent> | ||
| <groupId>com.microsoft.playwright</groupId> | ||
| <artifactId>test-spring-classloader</artifactId> | ||
| <version>1.50.0-SNAPSHOT</version> | ||
| <name>Test Playwright With Spring Boot</name> | ||
| <properties> | ||
| <spring.version>2.4.3</spring.version> | ||
| </properties> | ||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.microsoft.playwright</groupId> | ||
| <artifactId>playwright</artifactId> | ||
| <version>${project.version}</version> | ||
| </dependency> | ||
| </dependencies> | ||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-maven-plugin</artifactId> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| </project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| package com.microsoft.playwright.springboottest; | ||
|
|
||
| import com.microsoft.playwright.*; | ||
| import org.springframework.boot.CommandLineRunner; | ||
| import org.springframework.boot.SpringApplication; | ||
| import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
|
||
| import java.util.concurrent.CompletableFuture; | ||
|
|
||
| @SpringBootApplication | ||
| public class TestApp implements CommandLineRunner { | ||
|
|
||
| public static void main(String[] args) { | ||
| SpringApplication.run(TestApp.class, args); | ||
| } | ||
|
|
||
| public void run(String... args) { | ||
|
||
| // use CompletableFuture to run Playwright asynchronously | ||
| CompletableFuture<Void> voidCompletableFuture = CompletableFuture.runAsync(() -> { | ||
| try (Playwright playwright = Playwright.create()) { | ||
| System.out.println("Playwright classLoader test started, waiting for completion..."); | ||
| BrowserType browserType = getBrowserTypeFromEnv(playwright); | ||
| System.out.println("Running test with " + browserType.name()); | ||
| Browser browser = browserType.launch(); | ||
| BrowserContext context = browser.newContext(); | ||
| Page page = context.newPage(); | ||
| System.out.println(page.evaluate("'SUCCESS: did evaluate in page'")); | ||
| } catch (Exception e) { | ||
| System.out.println("FAILED: " + e.toString()); | ||
| for (StackTraceElement ste : e.getStackTrace()) { | ||
| System.out.println("\tat " + ste); | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| System.out.println("Playwright classLoader test is running asynchronously, main thread will wait for it to complete."); | ||
|
|
||
| voidCompletableFuture.join(); | ||
|
|
||
| System.out.println("Playwright classLoader test completed."); | ||
|
|
||
| } | ||
|
|
||
| static BrowserType getBrowserTypeFromEnv(Playwright playwright) { | ||
| String browserName = System.getenv("BROWSER"); | ||
|
|
||
| if (browserName == null) { | ||
| browserName = "chromium"; | ||
| } | ||
|
|
||
| switch (browserName) { | ||
| case "webkit": | ||
| return playwright.webkit(); | ||
| case "firefox": | ||
| return playwright.firefox(); | ||
| case "chromium": | ||
| return playwright.chromium(); | ||
| default: | ||
| throw new IllegalArgumentException("Unknown browser: " + browserName); | ||
| } | ||
| } | ||
|
|
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid the docker test failures let's just add
docker stop "${CONTAINER_ID}"to this (and the new) step to shutdown the container after the test has finished. Or better yet, since the container is the same in both steps, you can move its creation in a separate step and then use its CONTAINER_ID without relaunching, something likeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added example code and stop step