Repository navigation
[Bug]: Playwright-Junit lifecycle incompatible with maven retries 'surefire.rerunFailingTestsCount' #1751
Copy link
Copy link
Open
Labels
Description
Version
1.50.0
Steps to reproduce
- Have a basic Playwright test that fails
- Try running it with maven retries:
./mvnw test -Dtest=MyTest -Dsurefire.rerunFailingTestsCount=2
Expected behavior
System is able to retry the failing test, system can work with Playwright context (browser, page etc.)
Actual behavior
First attempt is a legit failure, subsequent rerun attempts have broken Playwright context
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.002 s <<< FAILURE! -- in fm.seller.onboardingweb.test.MyTest
[ERROR] fm.seller.onboardingweb.test.MyTest.test(Page) -- Time elapsed: 0.001 s <<< ERROR!
org.junit.jupiter.api.extension.ParameterResolutionException: Failed to resolve parameter [com.microsoft.playwright.Page page] in method [public void fm.seller.onboardingweb.test.MyTest.test(com.microsoft.playwright.Page)]: Playwright connection closed
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
Caused by: com.microsoft.playwright.PlaywrightException: Playwright connection closed
at com.microsoft.playwright.impl.PipeTransport.send(PipeTransport.java:50)
at com.microsoft.playwright.impl.Connection.internalSendMessage(Connection.java:168)
at com.microsoft.playwright.impl.Connection.sendMessageAsync(Connection.java:134)
at com.microsoft.playwright.impl.ChannelOwner.sendMessageAsync(ChannelOwner.java:109)
at com.microsoft.playwright.impl.SelectorsImpl.setTestIdAttributeName(SelectorsImpl.java:42)
at com.microsoft.playwright.impl.SharedSelectors.lambda$setTestIdAttribute$2(SharedSelectors.java:72)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at com.microsoft.playwright.impl.SharedSelectors.setTestIdAttribute(SharedSelectors.java:72)
at com.microsoft.playwright.impl.junit.ExtensionUtils.setTestIdAttribute(ExtensionUtils.java:53)
at com.microsoft.playwright.impl.junit.BrowserContextExtension.getOrCreateBrowserContext(BrowserContextExtension.java:60)
at com.microsoft.playwright.impl.junit.PageExtension.getOrCreatePage(PageExtension.java:51)
at com.microsoft.playwright.impl.junit.PageExtension.resolveParameter(PageExtension.java:35)
... 2 more
[ERROR] Errors:
[ERROR] fm.seller.onboardingweb.test.MyTest.test(Page)
[ERROR] Run 1: MyTest.test:13
[ERROR] Run 2: MyTest.test(Page) » ParameterResolution Failed to resolve parameter [com.microsoft.playwright.Page page] in method [public void fm.seller.onboardingweb.test.MyTest.test(com.microsoft.playwright.Page)]: Playwright connection closed
[ERROR] Run 3: MyTest.test(Page) » ParameterResolution Failed to resolve parameter [com.microsoft.playwright.Page page] in method [public void fm.seller.onboardingweb.test.MyTest.test(com.microsoft.playwright.Page)]: Playwright connection closed
Additional context
Minimal test:
@UsePlaywright(OptionsFactory.class)
public class MyTest {
@Test
public void test(Page page) {
page.navigate("https://google.com/");
assert false;
}
}
Environment
- OS name: "mac os x", version: "15.3", arch: "aarch64", family: "mac"
- Java version: 17.0.2, vendor: Oracle Corporation
- Apache Maven 3.8.5 (3599d3414f046de2324203b78ddcf9b5e4388aa0)
- playwright 1.50.0
- Junit 5.11.4
- surefire 3.5.2
Reactions are currently unavailable
Activity
[-][Bug]: Playwight-Junit lifecycle incompatible with maven retries 'surefire.rerunFailingTestsCount'[/-][+][Bug]: Playwright-Junit lifecycle incompatible with maven retries 'surefire.rerunFailingTestsCount'[/+]yury-s commentedon Feb 21, 2025
Please share a complete example. I was not able to reproduce it with a simple test.
uchagani (@uchagani) can you have a look?
uchagani commentedon Feb 21, 2025
I cannot reproduce this. Please provide a complete example. Here is mine that works as expected:
pom.xml
rtretyak commentedon Feb 21, 2025
pom:
test:
command:
mvn clean test -Dsurefire.rerunFailingTestsCount=1output:
rtretyak commentedon Feb 22, 2025
uchagani (@uchagani) I tried your project and I'm getting the same problem. The retry is not able to start properly:
Here is also my mvn version output:
And I also tried with this with the same result:
uchagani commentedon Feb 23, 2025
I'm not sure what could be causing this and I can't seem to reproduce it.
rtretyak commentedon Feb 23, 2025
I have also tried it on my home Windows PC which is completely independent from the previous environment and was able to reproduce it with your project.
Let me know if there is any other debug information I can provide you with...
uchagani commentedon Feb 23, 2025
Are you configuring your Java or maven in any specific way?
Can you check and post your settings.xml file (without any private info).
Are you running these tests from inside of an IDE or just the command line/terminal?
rtretyak commentedon Feb 23, 2025
No, nothing special. I tried with multiple different Javas as you can see above. Not doing anyhting special to them. 1 was installed with homebrew, other 2 just a default installation by IntelliJ IDEA
default one, just empty tags, no additional configurations
I'm running from terminal. Tried both in terminal inside IntelliJ and native terminal apps on windows/mac, same result.
rtretyak commentedon Mar 3, 2025
You can also reproduce it in the official playwright-java image..
docker run --rm -v "$(pwd):/app" -w /app mcr.microsoft.com/playwright/java:v1.50.0-noble mvn clean test -Dsurefire.rerunFailingTestsCount=1Develop-KIM commentedon Sep 16, 2026
I hit this too and dug into it.
PlaywrightExtensionkeeps thePlaywrightin a staticThreadLocal, and thePlaywrightRegistryin the root store closes it when the launcher finishes the first run, but theThreadLocalis never cleared. Surefire's rerun happens in the same JVM on the same thread, sogetOrCreatePlaywrighthands back the closed instance andBrowserExtensionfails onlaunch():Repro on 1.62.0 is one
@UsePlaywrighttest that always fails plusmvn test -Dsurefire.rerunFailingTestsCount=1. One thing to be aware of: since #1860 (1.57) the registry isAutoCloseablerather thanCloseableResource, and JUnit only closesAutoCloseablestore values from 5.13 on. With junit-jupiter 5.11 the firstPlaywrightis simply never closed, so the retry reuses it and the problem is invisible; with 5.14 it fails every time.The fix I have in mind is to only reuse the
ThreadLocalinstance when it belongs to the current run's registry and create a fresh one otherwise (clearing theThreadLocalfromclose()can't reach other threads). Happy to send a PR if that direction works for you.Develop-KIM commentedon Sep 16, 2026
Opened #1988 with the fix and a regression test. If you'd rather handle this differently I'm fine closing it.