Skip to content

Commit

Permalink
First test fails with initialization error sometimes (workaround) #48
Browse files Browse the repository at this point in the history
  • Loading branch information
Flaurite committed Oct 27, 2022
1 parent 9836025 commit 8393e6c
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/test/groovy/io/jmix/tests/extension/BrowserExtension.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ import org.junit.jupiter.api.extension.*
import org.openqa.selenium.Capabilities
import org.openqa.selenium.remote.LocalFileDetector
import org.openqa.selenium.remote.RemoteWebDriver
import org.rnorth.ducttape.timeouts.Timeouts
import org.rnorth.ducttape.unreliables.Unreliables
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.testcontainers.containers.BrowserWebDriverContainer

import java.util.concurrent.TimeUnit

abstract class BrowserExtension implements BeforeAllCallback, BeforeEachCallback, AfterEachCallback, AfterAllCallback {

public static final int VNC_RECORDER_PORT = 5900
Expand Down Expand Up @@ -39,19 +43,26 @@ abstract class BrowserExtension implements BeforeAllCallback, BeforeEachCallback
}

void startBrowser() {
// workaround, see https://github.com/jmix-framework/jmix-ui-tests/issues/48
browser = new BrowserWebDriverContainer()
.withCapabilities(capabilities)
.withEnv("SE_OPTS", "--session-retry-interval 1") as BrowserWebDriverContainer

browser.start()
RemoteWebDriver remoteWebDriver = browser.getWebDriver()
RemoteWebDriver remoteWebDriver = getWebDriver(30, 20, browser.seleniumAddress)
remoteWebDriver.setFileDetector(new LocalFileDetector())
WebDriverRunner.setWebDriver(remoteWebDriver)

printVncRecordedUrl()
}

// Workaround, see https://github.com/jmix-framework/jmix-ui-tests/issues/48
// CAUTION! Copied form BrowserWebDriverContainer#getWebDriver()
RemoteWebDriver getWebDriver(int retryTimeOut, int performTimeOut, URL seleniumAddress) {
Unreliables.retryUntilSuccess(retryTimeOut, TimeUnit.SECONDS, () -> {
return Timeouts.getWithTimeout(performTimeOut, TimeUnit.SECONDS, () -> {
return new RemoteWebDriver(seleniumAddress, capabilities);
});
});
}

void stopBrowser() {
WebDriverRunner.webDriver.manage().deleteAllCookies()
Selenide.closeWebDriver()
Expand Down

0 comments on commit 8393e6c

Please sign in to comment.