diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 4b4380e..44c0ef6 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -10,9 +10,9 @@ jobs: build: strategy: matrix: - os: [ ubuntu-latest, macos-latest ] + os: [ ubuntu-latest, macos-latest, windows-latest ] java: [ '8', '11', '17' ] - playwright: [ '1.18.0', '1.19.0', '1.20.0' ] + playwright: [ '1.18.0', '1.27.1' ] runs-on: ${{ matrix.os }} name: ${{matrix.os}} - Java ${{ matrix.java }} - Playwright ${{matrix.playwright}} steps: @@ -22,5 +22,5 @@ jobs: with: distribution: 'temurin' java-version: ${{ matrix.java }} - - run: mvn clean test "-Dplaywright.version=${{matrix.playwright}}" -DexcludedGroups=playwrightCreate,indirect --file pom.xml --no-transfer-progress - - run: mvn clean test "-Dplaywright.version=${{matrix.playwright}}" -Dgroups=playwrightCreate --file pom.xml --no-transfer-progress + - run: mvn clean test "-Dplaywright.version=${{matrix.playwright}}" "-DexcludedGroups=playwrightCreate,indirect" --file pom.xml --no-transfer-progress + - run: mvn clean test "-Dplaywright.version=${{matrix.playwright}}" -Dgroups=playwrightCreate -DexcludedGroups=flakey --file pom.xml --no-transfer-progress diff --git a/.idea/compiler.xml b/.idea/compiler.xml index be37ed1..599cefd 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -13,17 +13,17 @@ - - - - - + + + + + - + diff --git a/README.md b/README.md index 26ac012..4f8e077 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ the wiki for v1 docs. It is recommended to upgrade to v2.0. Migration help can io.github.uchagani junit-playwright - 2.2.3 + 3.0.1 ``` diff --git a/pom.xml b/pom.xml index a517c16..6e78344 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ io.github.uchagani junit-playwright - 2.2.5 + 3.0.1 junit-playwright junit-playwright allows you to easily run Playwright-Java tests in parallel @@ -21,10 +21,10 @@ 8 8 - 1.20.0 + 1.27.1 5.8.2 - 2022.1.7 + 2022.1.19 diff --git a/run-tests.sh b/run-tests.sh new file mode 100755 index 0000000..666c6a7 --- /dev/null +++ b/run-tests.sh @@ -0,0 +1,2 @@ +mvn clean test -DexcludedGroups=playwrightCreate,indirect +mvn clean test -Dgroups=playwrightCreate \ No newline at end of file diff --git a/src/main/java/io/github/uchagani/jp/PlaywrightTestWatcher.java b/src/main/java/io/github/uchagani/jp/PlaywrightTestWatcher.java index b3a9a3e..51dcd0a 100644 --- a/src/main/java/io/github/uchagani/jp/PlaywrightTestWatcher.java +++ b/src/main/java/io/github/uchagani/jp/PlaywrightTestWatcher.java @@ -7,6 +7,8 @@ import java.nio.file.Path; import java.nio.file.Paths; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import static io.github.uchagani.jp.APIRequestContextParameterResolver.closeAPIRequestContext; import static io.github.uchagani.jp.ExtensionUtils.getBrowserConfig; @@ -53,7 +55,10 @@ private void stopTrace(ExtensionContext extensionContext) { } private String getSafeTestName(ExtensionContext extensionContext) { - return String.format("%s.%s.zip", extensionContext.getRequiredTestClass().getName(), extensionContext.getRequiredTestMethod().getName()); + Pattern regex = Pattern.compile("\\[class:(.*)\\]\\/\\[method:(.*)\\]"); + Matcher matcher = regex.matcher(extensionContext.getUniqueId()); + matcher.find(); + return matcher.group(1) + "." + matcher.group(2) + ".zip"; } private void cleanup(ExtensionContext extensionContext) { diff --git a/src/test/java/io/github/uchagani/jp/PlaywrightTests.java b/src/test/java/io/github/uchagani/jp/PlaywrightTests.java index b73bcaa..dff17f7 100644 --- a/src/test/java/io/github/uchagani/jp/PlaywrightTests.java +++ b/src/test/java/io/github/uchagani/jp/PlaywrightTests.java @@ -22,6 +22,7 @@ void injectPlaywrightTestRunsSuccessfully() { .assertStatistics(stat -> stat.succeeded(1)); } + @Tag("flakey") @Test void injectPlaywrightWithOptionsTestRunsFails() { EngineTestKit diff --git a/src/test/java/io/github/uchagani/jp/TraceTestCase.java b/src/test/java/io/github/uchagani/jp/TraceTestCase.java index 93e18c8..5a70e3b 100644 --- a/src/test/java/io/github/uchagani/jp/TraceTestCase.java +++ b/src/test/java/io/github/uchagani/jp/TraceTestCase.java @@ -76,6 +76,18 @@ public void traceFile_onFail_isCreated(Page ignored) { fail("force fail"); } + @Test + @UseBrowserConfig(TraceBrowserConfigSaveOnlyOnFailure.class) + public void traceFile_onFail_isCreated(Page ignored, String foo) { + fail("force fail"); + } + + @Test + @UseBrowserConfig(TraceBrowserConfigSaveOnlyOnFailure.class) + public void traceFile_onFail_isCreated() { + fail("force fail"); + } + @Test @UseBrowserConfig(TraceBrowserConfigAlternateOutputDir.class) public void traceFile_inAlternateDir_isCreated(Page ignored) { diff --git a/src/test/java/io/github/uchagani/jp/TraceTests.java b/src/test/java/io/github/uchagani/jp/TraceTests.java index 4e7ff11..9bb2282 100644 --- a/src/test/java/io/github/uchagani/jp/TraceTests.java +++ b/src/test/java/io/github/uchagani/jp/TraceTests.java @@ -6,6 +6,7 @@ import org.junit.platform.testkit.engine.EngineTestKit; import java.lang.reflect.Method; +import java.lang.reflect.Parameter; import java.nio.file.Path; import java.util.Arrays; import java.util.List; @@ -30,14 +31,28 @@ void verifyTraceTestStats() { BrowserConfig config = getBrowserConfig(test.getAnnotation(UseBrowserConfig.class).value()); Path outputDir = config.getOutputDirectory(); + String testName = generateFileNameFromMethod(test); if (test.getName().endsWith("isCreated")) { - assertThat(outputDir).isDirectoryContaining(getTraceFileName(test.getName())); + assertThat(outputDir).isDirectoryContaining(getTraceFileName(testName)); } else if (test.getName().endsWith("isNotCreated")) { - assertThat(outputDir).isDirectoryNotContaining(getTraceFileName(test.getName())); + assertThat(outputDir).isDirectoryNotContaining(getTraceFileName(testName)); } } } + private String generateFileNameFromMethod(Method method) { + StringBuilder testName = new StringBuilder(method.getName()); + testName.append("("); + for(int i = 0; i < method.getParameterCount(); i++) { + if(i > 0) { + testName.append(", "); + } + testName.append(method.getParameters()[i].getType().getName()); + } + testName.append(")"); + return testName.toString(); + } + private String getTraceFileName(String testName) { return "glob:**" + TraceTestCase.class.getName() + "." + testName + ".zip"; }