diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2e93568..c28f949 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -51,7 +51,7 @@ jobs: needs: [check-code] timeout-minutes: 10 outputs: - upload_url: ${{ steps.create_release.outputs.upload_url }} + upload_url: ${{ steps.create-release.outputs.upload_url }} steps: - uses: actions/checkout@v4 @@ -88,7 +88,7 @@ jobs: git push origin --tags - name: Create Release - id: create_release + id: create-release uses: shogo82148/actions-create-release@4661dc54f7b4b564074e9fbf73884d960de569a3 # v1 with: tag_name: v${{ steps.version.outputs.release }} diff --git a/.gitignore b/.gitignore index 5c85054..14a1fb4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,16 +1,12 @@ # Maven target/ -pom.xml.tag -pom.xml.releaseBackup -pom.xml.versionsBackup -pom.xml.next -release.properties dependency-reduced-pom.xml -buildNumber.properties -.mvn/timing.properties -# https://github.com/takari/maven-wrapper#usage-without-binary-jar + +# Maven Wrapper .mvn/wrapper/maven-wrapper.jar +# Maven Flatten Plugin +.flattened-pom.xml # Compiled class file *.class @@ -18,20 +14,12 @@ buildNumber.properties # Log file *.log -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - # Package/Binary Files don't belong into a git repo *.jar *.war -*.nar *.ear *.zip *.tar.gz -*.rar *.dll *.exe *.bin @@ -39,27 +27,11 @@ buildNumber.properties # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* -# JRebel -**/resources/rebel.xml -**/resources/rebel-remote.xml - -# eclispe stuff for root -/.settings/ -/.classpath -/.project - - -# eclispe stuff for modules -/*/.metadata/ -/*/.apt_generated_tests/ -/*/.settings/ -/*/.classpath -/*/.project -/*/RemoteSystemsTempFiles/ - -#custom -.flattened-pom.xml -.tern-project +# Eclipse +.metadata +.settings +.classpath +.project # == IntelliJ == *.iml diff --git a/CHANGELOG.md b/CHANGELOG.md index 2fe2839..36652f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# 1.2.4 +* New option ``beforeRecordingSaveWaitTime`` in ``BrowserWebDriverContainer`` + * If not ``null``: Waits the amount of specified time before saving the recording + * This way no frames that may show the problem are accidentally lost + * Default value is set to ``70ms`` which is 1 full frame when recording at the default 15 FPS +* Only compute name for recording when required + # 1.2.3 * Make some constants externally accessible * Provide chromium image (Chrome doesn't work on ARM64) diff --git a/pom.xml b/pom.xml index 84a673b..bd29235 100644 --- a/pom.xml +++ b/pom.xml @@ -45,7 +45,7 @@ com.puppycrawl.tools checkstyle - 10.25.0 + 10.26.0 @@ -70,7 +70,7 @@ org.apache.maven.plugins maven-pmd-plugin - 3.26.0 + 3.27.0 true true diff --git a/testcontainers-selenium/pom.xml b/testcontainers-selenium/pom.xml index eb0a1a9..dbfcf74 100644 --- a/testcontainers-selenium/pom.xml +++ b/testcontainers-selenium/pom.xml @@ -56,7 +56,7 @@ org.testcontainers testcontainers - 1.21.1 + 1.21.2 @@ -90,7 +90,7 @@ org.junit.jupiter junit-jupiter - 5.13.1 + 5.13.2 test @@ -264,7 +264,7 @@ org.codehaus.mojo flatten-maven-plugin - 1.7.0 + 1.7.1 ossrh @@ -304,7 +304,7 @@ org.sonatype.central central-publishing-maven-plugin - 0.7.0 + 0.8.0 true sonatype-central-portal @@ -326,7 +326,7 @@ com.puppycrawl.tools checkstyle - 10.25.0 + 10.26.0 @@ -351,7 +351,7 @@ org.apache.maven.plugins maven-pmd-plugin - 3.26.0 + 3.27.0 true true diff --git a/testcontainers-selenium/src/main/java/software/xdev/testcontainers/selenium/containers/browser/BrowserWebDriverContainer.java b/testcontainers-selenium/src/main/java/software/xdev/testcontainers/selenium/containers/browser/BrowserWebDriverContainer.java index 465a699..671d796 100644 --- a/testcontainers-selenium/src/main/java/software/xdev/testcontainers/selenium/containers/browser/BrowserWebDriverContainer.java +++ b/testcontainers-selenium/src/main/java/software/xdev/testcontainers/selenium/containers/browser/BrowserWebDriverContainer.java @@ -35,6 +35,7 @@ import java.util.Optional; import java.util.concurrent.TimeUnit; import java.util.function.Function; +import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.IntStream; @@ -114,6 +115,8 @@ public class BrowserWebDriverContainer 67ms per Frame) + protected Duration beforeRecordingSaveWaitTime = Duration.ofMillis(70); public BrowserWebDriverContainer(final String dockerImageName) { @@ -211,6 +214,13 @@ public SELF withRecordingSaveTimeout(final Duration recordingSaveTimeout) this.recordingSaveTimeout = recordingSaveTimeout; return this.self(); } + + public SELF withBeforeRecordingSaveWaitTime(final Duration beforeRecordingSaveWaitTime) + { + this.beforeRecordingSaveWaitTime = beforeRecordingSaveWaitTime; + return this.self(); + } + // endregion // endregion @@ -441,38 +451,56 @@ public void stop() @Override public void afterTest(final TestDescription description, final Optional throwable) { - this.retainRecordingIfNeeded(description.getFilesystemFriendlyName(), throwable.isEmpty()); + this.retainRecordingIfNeeded(description::getFilesystemFriendlyName, throwable.isEmpty()); } - protected void retainRecordingIfNeeded(final String testName, final boolean succeeded) + protected void retainRecordingIfNeeded(final Supplier testNameSupplier, final boolean succeeded) { + // Should recording be retained? if(switch(this.recordingMode) { - case RECORD_ALL -> true; - case RECORD_FAILING -> !succeeded; - default -> false; + case RECORD_ALL -> false; + case RECORD_FAILING -> succeeded; + default -> true; }) + { + return; + } + + if(this.beforeRecordingSaveWaitTime != null) { try { - final Path recording = Timeouts.getWithTimeout( - (int)this.recordingSaveTimeout.toSeconds(), - TimeUnit.SECONDS, - () -> this.recordingContainer.saveRecordingToFile( - this.recordingDirectory, - this.testRecordingFileNameFactory.buildNameWithoutExtension(testName, succeeded)) - ); - LOG.info("Screen recordings for test {} will be stored at: {}", testName, recording); - } - catch(final org.rnorth.ducttape.TimeoutException te) - { - LOG.warn("Timed out while saving recording for test {}", testName, te); + Thread.sleep(this.beforeRecordingSaveWaitTime.toMillis()); } - catch(final Exception ex) + catch(final InterruptedException e) { - LOG.warn("Failed to save recording for test {}", testName, ex); + Thread.currentThread().interrupt(); + throw new IllegalStateException("Got interrupted", e); } } + + // Get testname only when required to improve performance + final String testName = testNameSupplier.get(); + try + { + final Path recording = Timeouts.getWithTimeout( + (int)this.recordingSaveTimeout.toSeconds(), + TimeUnit.SECONDS, + () -> this.recordingContainer.saveRecordingToFile( + this.recordingDirectory, + this.testRecordingFileNameFactory.buildNameWithoutExtension(testName, succeeded)) + ); + LOG.info("Screen recordings for test {} will be stored at: {}", testName, recording); + } + catch(final org.rnorth.ducttape.TimeoutException te) + { + LOG.warn("Timed out while saving recording for test {}", testName, te); + } + catch(final Exception ex) + { + LOG.warn("Failed to save recording for test {}", testName, ex); + } } @Override