diff --git a/tests/pom.xml b/tests/pom.xml
index 05c5fedce8..640b9fca21 100644
--- a/tests/pom.xml
+++ b/tests/pom.xml
@@ -23,6 +23,8 @@
../app/target/apicurio-registry-app-${project.version}-runner
+ 5.7.0
+ 1.7.0
1.3.0.Final
4.9.0
2.3.0
@@ -85,16 +87,19 @@
org.junit.jupiter
junit-jupiter
+ ${junit.version}
test
org.junit.jupiter
junit-jupiter-api
+ ${junit.version}
provided
org.junit.platform
junit-platform-launcher
+ ${junit.platform-launcher.version}
compile
diff --git a/tests/src/test/java/io/apicurio/tests/selenium/SeleniumChromeExtension.java b/tests/src/test/java/io/apicurio/tests/selenium/SeleniumChromeExtension.java
index f8aa5f2f4d..044e48adce 100644
--- a/tests/src/test/java/io/apicurio/tests/selenium/SeleniumChromeExtension.java
+++ b/tests/src/test/java/io/apicurio/tests/selenium/SeleniumChromeExtension.java
@@ -15,12 +15,19 @@
*/
package io.apicurio.tests.selenium;
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.net.URL;
+
import org.junit.jupiter.api.extension.AfterAllCallback;
import org.junit.jupiter.api.extension.AfterTestExecutionCallback;
import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.BeforeTestExecutionCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
+import org.openqa.selenium.Capabilities;
+import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeOptions;
+import org.openqa.selenium.remote.RemoteWebDriver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.Testcontainers;
@@ -67,23 +74,78 @@ public void beforeTestExecution(ExtensionContext extensionContext) throws Except
}
}
- private void deployChrome() {
+ private void deployChrome() throws Exception {
LOGGER.info("Deploying chrome browser");
- if (!TestUtils.isExternalRegistry()) {
+ String uiUrl;
+ WebDriver driver;
+ if (TestUtils.isExternalRegistry()) {
+ // we are supposing that if registry is deployed externally selenium will be as well
+ driver = getRemoteChromeDriver();
+ String registrySeleniumHost = System.getenv().getOrDefault("REGISTRY_SELENIUM_HOST", TestUtils.getRegistryHost());
+ String registrySeleniumPort = System.getenv().getOrDefault("REGISTRY_SELENIUM_PORT", Integer.toString(TestUtils.getRegistryPort()));
+ uiUrl = String.format("http://%s:%s/ui", registrySeleniumHost, registrySeleniumPort);
+ } else {
Testcontainers.exposeHostPorts(TestUtils.getRegistryPort());
- }
- chrome = new BrowserWebDriverContainer()
+ uiUrl = TestUtils.getRegistryUIUrl().replace("localhost", "host.testcontainers.internal");
+ chrome = new BrowserWebDriverContainer()
.withCapabilities(new ChromeOptions());
- chrome.start();
- SeleniumProvider.getInstance().setupDriver(chrome.getWebDriver());
- SeleniumProvider.getInstance().setUiUrl(TestUtils.getRegistryUIUrl().replace("localhost", "host.testcontainers.internal"));
+ chrome.start();
+ driver = chrome.getWebDriver();
+ }
+ SeleniumProvider.getInstance().setupDriver(driver);
+ SeleniumProvider.getInstance().setUiUrl(uiUrl);
deployed = true;
}
private void deleteChrome() {
SeleniumProvider.getInstance().tearDownDrivers();
LOGGER.info("Stopping chrome browser");
- chrome.stop();
+ if (!TestUtils.isExternalRegistry()) {
+ chrome.stop();
+ }
deployed = false;
}
+
+ public static RemoteWebDriver getRemoteChromeDriver() throws Exception {
+ String seleniumHost = System.getenv().getOrDefault("SELENIUM_HOST", "localhost");
+ String seleniumPort = System.getenv().getOrDefault("SELENIUM_PORT", "80");
+ ChromeOptions options = new ChromeOptions();
+ options.setAcceptInsecureCerts(true);
+ options.addArguments("test-type", "--headless", "--no-sandbox", "--disable-dev-shm-usage", "--disable-extensions");
+ return getRemoteDriver(seleniumHost, seleniumPort, options);
+ }
+
+ private static RemoteWebDriver getRemoteDriver(String host, String port, Capabilities options) throws Exception {
+ int attempts = 60;
+ URL hubUrl = new URL(String.format("http://%s:%s/wd/hub", host, port));
+ LOGGER.info("Using remote selenium " + hubUrl);
+ for (int i = 0; i < attempts; i++) {
+ try {
+ testReachable(hubUrl);
+ return new RemoteWebDriver(hubUrl, options);
+ } catch (IOException e) {
+ if (i == attempts - 1) {
+ LOGGER.warn("Cannot connect to hub", e);
+ } else {
+ LOGGER.warn("Cannot connect to hub: {}", e.getMessage());
+ }
+ }
+ Thread.sleep(2000);
+ }
+ throw new IllegalStateException("Selenium webdriver cannot connect to selenium container");
+ }
+
+ private static void testReachable(URL url) throws IOException {
+ LOGGER.info("Trying to connect to {}", url.toString());
+ HttpURLConnection urlConnection = null;
+ try {
+ urlConnection = (HttpURLConnection) url.openConnection();
+ urlConnection.getContent();
+ LOGGER.info("Client is able to connect to the selenium hub");
+ } finally {
+ if (urlConnection != null) {
+ urlConnection.disconnect();
+ }
+ }
+ }
}
diff --git a/tests/src/test/java/io/apicurio/tests/ui/DeleteArtifactIT.java b/tests/src/test/java/io/apicurio/tests/ui/DeleteArtifactIT.java
index 755c0e6338..8d2396b782 100644
--- a/tests/src/test/java/io/apicurio/tests/ui/DeleteArtifactIT.java
+++ b/tests/src/test/java/io/apicurio/tests/ui/DeleteArtifactIT.java
@@ -19,6 +19,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import java.time.Duration;
import java.util.List;
import org.junit.jupiter.api.AfterEach;
@@ -73,7 +74,7 @@ void testDeleteArtifacts(RegistryService service) throws Exception {
page.deleteArtifact(artifactId1);
- TestUtils.waitFor("Artifacts list updated", Constants.POLL_INTERVAL, Constants.TIMEOUT_GLOBAL, () -> {
+ TestUtils.waitFor("Artifacts list updated", Constants.POLL_INTERVAL, Duration.ofSeconds(60).toMillis(), () -> {
try {
return page.getArtifactsList().size() == 1;
} catch (Exception e) {
@@ -86,7 +87,7 @@ void testDeleteArtifacts(RegistryService service) throws Exception {
page.deleteArtifact(artifactId2);
- TestUtils.waitFor("Artifacts list updated", Constants.POLL_INTERVAL, Constants.TIMEOUT_GLOBAL, () -> {
+ TestUtils.waitFor("Artifacts list updated", Constants.POLL_INTERVAL, Duration.ofSeconds(60).toMillis(), () -> {
try {
return page.getArtifactsList().size() == 0;
} catch (Exception e) {
diff --git a/utils/tests/src/main/java/io/apicurio/registry/utils/tests/TestUtils.java b/utils/tests/src/main/java/io/apicurio/registry/utils/tests/TestUtils.java
index e2441d57d9..04ae7379da 100644
--- a/utils/tests/src/main/java/io/apicurio/registry/utils/tests/TestUtils.java
+++ b/utils/tests/src/main/java/io/apicurio/registry/utils/tests/TestUtils.java
@@ -233,7 +233,7 @@ public static void retry(RunnableExc runnable) throws Exception {
}
public static T retry(Callable callable) throws Exception {
- return retry(callable, "Action #" + System.currentTimeMillis(), 5);
+ return retry(callable, "Action #" + System.currentTimeMillis(), 15);
}
public static void retry(RunnableExc runnable, String name, int maxRetries) throws Exception {