ARTEMIS-3694 Support remote servers for console smoke tests
This commit is contained in:
parent
101c0d2cd0
commit
b0f131f080
|
@ -44,12 +44,14 @@ which eliminates all the setup and class variables which are provided by `Single
|
||||||
The broker has a web console based on [hawtio](https://github.com/hawtio/hawtio) and the `smoke-tests` are used to test it.
|
The broker has a web console based on [hawtio](https://github.com/hawtio/hawtio) and the `smoke-tests` are used to test it.
|
||||||
For instance, the [ConsoleTest](https://github.com/apache/activemq-artemis/blob/main/tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/console/ConsoleTest.java)
|
For instance, the [ConsoleTest](https://github.com/apache/activemq-artemis/blob/main/tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/console/ConsoleTest.java)
|
||||||
checks the web console using the [selenium framework](https://github.com/SeleniumHQ/selenium).
|
checks the web console using the [selenium framework](https://github.com/SeleniumHQ/selenium).
|
||||||
The tests can be executed using the local browsers or the [webdriver testcontainers](https://www.testcontainers.org/modules/webdriver_containers).
|
The tests can be executed using a remote server, local browsers or [testcontainers](https://www.testcontainers.org/modules/webdriver_containers).
|
||||||
|
To use a remote server set the `webdriver.remote.server` property with the URL
|
||||||
|
of the server, ie -Dwebdriver.remote.server=http://localhost:4444/wd/hub
|
||||||
To use your local Google Chrome browser download the [WebDriver for Chrome](https://chromedriver.chromium.org/) and set
|
To use your local Google Chrome browser download the [WebDriver for Chrome](https://chromedriver.chromium.org/) and set
|
||||||
the `webdriver.chrome.driver` property with the WebDriver path, ie `-Dwebdriver.chrome.driver=/home/artemis/chromedriver_linux64/chromedriver`.
|
the `webdriver.chrome.driver` property with the WebDriver path, ie `-Dwebdriver.chrome.driver=/home/artemis/chromedriver_linux64/chromedriver`.
|
||||||
To use your local Firefox browser download the [WebDriver for Firefox](https://github.com/mozilla/geckodriver/) and set
|
To use your local Firefox browser download the [WebDriver for Firefox](https://github.com/mozilla/geckodriver/) and set
|
||||||
the `webdriver.gecko.driver` property with the WebDriver path, ie `-Dwebdriver.gecko.driver=/home/artemis/geckodriver-linux64/geckodriver`.
|
the `webdriver.gecko.driver` property with the WebDriver path, ie `-Dwebdriver.gecko.driver=/home/artemis/geckodriver-linux64/geckodriver`.
|
||||||
To use the [webdriver testcontainers](https://www.testcontainers.org/modules/webdriver_containers) install docker.
|
To use [testcontainers](https://www.testcontainers.org/modules/webdriver_containers) install docker.
|
||||||
|
|
||||||
## Keys for writing good tests
|
## Keys for writing good tests
|
||||||
|
|
||||||
|
|
|
@ -17,9 +17,11 @@
|
||||||
|
|
||||||
package org.apache.activemq.artemis.tests.smoke.console;
|
package org.apache.activemq.artemis.tests.smoke.console;
|
||||||
|
|
||||||
|
import java.net.URL;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
import org.apache.activemq.artemis.tests.smoke.common.SmokeTestBase;
|
import org.apache.activemq.artemis.tests.smoke.common.SmokeTestBase;
|
||||||
|
@ -35,6 +37,7 @@ import org.openqa.selenium.chrome.ChromeDriver;
|
||||||
import org.openqa.selenium.chrome.ChromeOptions;
|
import org.openqa.selenium.chrome.ChromeOptions;
|
||||||
import org.openqa.selenium.firefox.FirefoxDriver;
|
import org.openqa.selenium.firefox.FirefoxDriver;
|
||||||
import org.openqa.selenium.firefox.FirefoxOptions;
|
import org.openqa.selenium.firefox.FirefoxOptions;
|
||||||
|
import org.openqa.selenium.remote.RemoteWebDriver;
|
||||||
import org.openqa.selenium.support.ui.WebDriverWait;
|
import org.openqa.selenium.support.ui.WebDriverWait;
|
||||||
import org.testcontainers.Testcontainers;
|
import org.testcontainers.Testcontainers;
|
||||||
import org.testcontainers.containers.BrowserWebDriverContainer;
|
import org.testcontainers.containers.BrowserWebDriverContainer;
|
||||||
|
@ -72,14 +75,16 @@ public abstract class ConsoleTest extends SmokeTestBase {
|
||||||
|
|
||||||
|
|
||||||
// The ConsoleTest checks the web console using the selenium framework[1].
|
// The ConsoleTest checks the web console using the selenium framework[1].
|
||||||
// The tests can be executed using the local browsers or the webdriver testcontainers[2].
|
// The tests can be executed using a remote server, local browsers or testcontainers[2].
|
||||||
|
// To use a remote server set the `webdriver.remote.server` property with the URL
|
||||||
|
// of the server, ie -Dwebdriver.remote.server=http://localhost:4444/wd/hub
|
||||||
// To use your local Google Chrome browser download the WebDriver for Chrome[3] and set
|
// To use your local Google Chrome browser download the WebDriver for Chrome[3] and set
|
||||||
// the `webdriver.chrome.driver` property with the WebDriver path, ie
|
// the `webdriver.chrome.driver` property with the WebDriver path, ie
|
||||||
// -Dwebdriver.chrome.driver=/home/developer/chromedriver_linux64/chromedriver
|
// -Dwebdriver.chrome.driver=/home/developer/chromedriver_linux64/chromedriver
|
||||||
// To use your local Firefox browser download the WebDriver for Firefox[4] and set
|
// To use your local Firefox browser download the WebDriver for Firefox[4] and set
|
||||||
// the `webdriver.gecko.driver` property with the WebDriver path, ie
|
// the `webdriver.gecko.driver` property with the WebDriver path, ie
|
||||||
// -Dwebdriver.gecko.driver=/home/developer/geckodriver-v0.28.0-linux64/geckodriver
|
// -Dwebdriver.gecko.driver=/home/developer/geckodriver-v0.28.0-linux64/geckodriver
|
||||||
// To use the webdriver testcontainers[2] install docker.
|
// To use the testcontainers[2] install docker.
|
||||||
//
|
//
|
||||||
// [1] https://github.com/SeleniumHQ/selenium
|
// [1] https://github.com/SeleniumHQ/selenium
|
||||||
// [2] https://www.testcontainers.org/modules/webdriver_containers
|
// [2] https://www.testcontainers.org/modules/webdriver_containers
|
||||||
|
@ -87,22 +92,41 @@ public abstract class ConsoleTest extends SmokeTestBase {
|
||||||
// [4] https://github.com/mozilla/geckodriver/
|
// [4] https://github.com/mozilla/geckodriver/
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (browserOptions instanceof ChromeOptions &&
|
String webdriverName;
|
||||||
System.getProperty("webdriver.chrome.driver") != null) {
|
String webdriverLocation;
|
||||||
ChromeOptions chromeOptions = (ChromeOptions)browserOptions;
|
String webdriverArguments;
|
||||||
String arguments = System.getProperty("webdriver.chrome.driver.args");
|
String webdriverRemoteServer;
|
||||||
if (arguments != null) {
|
Function<MutableCapabilities, WebDriver> webDriverConstructor;
|
||||||
chromeOptions.addArguments(arguments.split(","));
|
BiConsumer<MutableCapabilities, String[]> webdriverArgumentsSetter;
|
||||||
}
|
|
||||||
driver = new ChromeDriver(chromeOptions);
|
if (browserOptions instanceof ChromeOptions) {
|
||||||
} else if (browserOptions instanceof FirefoxOptions &&
|
webdriverName = "chrome";
|
||||||
System.getProperty("webdriver.gecko.driver") != null) {
|
webDriverConstructor = browserOptions -> new ChromeDriver((ChromeOptions)browserOptions);
|
||||||
FirefoxOptions firefoxOptions = (FirefoxOptions)browserOptions;
|
webdriverArgumentsSetter = (browserOptions, arguments) -> ((ChromeOptions) browserOptions).addArguments(arguments);
|
||||||
String arguments = System.getProperty("webdriver.gecko.driver.args");
|
} else if (browserOptions instanceof FirefoxOptions) {
|
||||||
if (arguments != null) {
|
webdriverName = "gecko";
|
||||||
firefoxOptions.addArguments(arguments.split(","));
|
webDriverConstructor = browserOptions -> new FirefoxDriver((FirefoxOptions)browserOptions);
|
||||||
}
|
webdriverArgumentsSetter = (browserOptions, arguments) -> ((FirefoxOptions) browserOptions).addArguments(arguments);
|
||||||
driver = new FirefoxDriver(firefoxOptions);
|
} else {
|
||||||
|
throw new IllegalStateException("Unexpected browserOptions: " + browserOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
webdriverArguments = System.getProperty("webdriver." + webdriverName + ".driver.args");
|
||||||
|
if (webdriverArguments != null) {
|
||||||
|
webdriverArgumentsSetter.accept(browserOptions, webdriverArguments.split(","));
|
||||||
|
}
|
||||||
|
|
||||||
|
webdriverLocation = System.getProperty("webdriver." + webdriverName + ".driver");
|
||||||
|
|
||||||
|
webdriverRemoteServer = System.getProperty("webdriver." + webdriverName + ".remote.server");
|
||||||
|
if (webdriverRemoteServer == null) {
|
||||||
|
webdriverRemoteServer = System.getProperty("webdriver.remote.server");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (webdriverRemoteServer != null) {
|
||||||
|
driver = new RemoteWebDriver(new URL(webdriverRemoteServer), browserOptions);
|
||||||
|
} else if (webdriverLocation != null) {
|
||||||
|
driver = webDriverConstructor.apply(browserOptions);
|
||||||
} else {
|
} else {
|
||||||
serverUrl = DEFAULT_CONTAINER_SERVER_URL;
|
serverUrl = DEFAULT_CONTAINER_SERVER_URL;
|
||||||
Testcontainers.exposeHostPorts(8161);
|
Testcontainers.exposeHostPorts(8161);
|
||||||
|
|
Loading…
Reference in New Issue