ARTEMIS-3600 Add console index page test

This commit is contained in:
Domenico Francesco Bruscino 2021-12-02 21:00:14 +01:00 committed by clebertsuconic
parent 72a4fff167
commit 8f41cf647f
5 changed files with 100 additions and 13 deletions

View File

@ -48,7 +48,6 @@ public abstract class ConsoleTest extends SmokeTestBase {
protected static final int DEFAULT_TIMEOUT = 10000; protected static final int DEFAULT_TIMEOUT = 10000;
protected static final String DEFAULT_SERVER_URL = "http://localhost:8161"; protected static final String DEFAULT_SERVER_URL = "http://localhost:8161";
protected static final String DEFAULT_CONTAINER_SERVER_URL = "http://host.testcontainers.internal:8161"; protected static final String DEFAULT_CONTAINER_SERVER_URL = "http://host.testcontainers.internal:8161";
protected static final String DEFAULT_CONSOLE_BRAND_IMAGE = "/activemq-branding/plugin/img/activemq.png";
protected WebDriver driver; protected WebDriver driver;
protected MutableCapabilities browserOptions; protected MutableCapabilities browserOptions;
@ -88,12 +87,22 @@ public abstract class ConsoleTest extends SmokeTestBase {
// [4] https://github.com/mozilla/geckodriver/ // [4] https://github.com/mozilla/geckodriver/
try { try {
if (ChromeOptions.class.equals(browserOptions.getClass()) && if (browserOptions instanceof ChromeOptions &&
System.getProperty("webdriver.chrome.driver") != null) { System.getProperty("webdriver.chrome.driver") != null) {
driver = new ChromeDriver((ChromeOptions)browserOptions); ChromeOptions chromeOptions = (ChromeOptions)browserOptions;
} else if (FirefoxOptions.class.equals(browserOptions.getClass()) && String arguments = System.getProperty("webdriver.chrome.driver.args");
if (arguments != null) {
chromeOptions.addArguments(arguments.split(","));
}
driver = new ChromeDriver(chromeOptions);
} else if (browserOptions instanceof FirefoxOptions &&
System.getProperty("webdriver.gecko.driver") != null) { System.getProperty("webdriver.gecko.driver") != null) {
driver = new FirefoxDriver((FirefoxOptions)browserOptions); FirefoxOptions firefoxOptions = (FirefoxOptions)browserOptions;
String arguments = System.getProperty("webdriver.gecko.driver.args");
if (arguments != null) {
firefoxOptions.addArguments(arguments.split(","));
}
driver = new FirefoxDriver(firefoxOptions);
} else { } else {
serverUrl = DEFAULT_CONTAINER_SERVER_URL; serverUrl = DEFAULT_CONTAINER_SERVER_URL;
Testcontainers.exposeHostPorts(8161); Testcontainers.exposeHostPorts(8161);
@ -111,7 +120,7 @@ public abstract class ConsoleTest extends SmokeTestBase {
loadWebDriverWait.until((Function<WebDriver, Object>) webDriver -> { loadWebDriverWait.until((Function<WebDriver, Object>) webDriver -> {
try { try {
webDriver.get(serverUrl + "/console"); webDriver.get(serverUrl);
return true; return true;
} catch (Exception ignore) { } catch (Exception ignore) {
return false; return false;

View File

@ -0,0 +1,41 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.activemq.artemis.tests.smoke.console;
import org.apache.activemq.artemis.tests.smoke.console.pages.IndexPage;
import org.junit.Test;
import org.openqa.selenium.MutableCapabilities;
public class IndexTest extends ConsoleTest {
protected static final String DEFAULT_CONSOLE_INDEX_LOGO_IMAGE = "/images/activemq-logo.png";
public IndexTest(MutableCapabilities browserOptions) {
super(browserOptions);
}
@Test
public void testIndexLogo() {
String expectedLogoImage = serverUrl + System.getProperty(
"artemis.console.index.logo.image", DEFAULT_CONSOLE_INDEX_LOGO_IMAGE);
driver.get(serverUrl);
IndexPage indexPage = new IndexPage(driver);
assertEquals(expectedLogoImage, indexPage.getLogoImage(DEFAULT_TIMEOUT));
}
}

View File

@ -18,30 +18,30 @@
package org.apache.activemq.artemis.tests.smoke.console; package org.apache.activemq.artemis.tests.smoke.console;
import org.apache.activemq.artemis.tests.smoke.console.pages.LoginPage; import org.apache.activemq.artemis.tests.smoke.console.pages.LoginPage;
import org.apache.activemq.artemis.tests.smoke.console.pages.StatusPage;
import org.junit.Test; import org.junit.Test;
import org.openqa.selenium.MutableCapabilities; import org.openqa.selenium.MutableCapabilities;
public class LoginTest extends ConsoleTest { public class LoginTest extends ConsoleTest {
private static final String DEFAULT_CONSOLE_LOGIN_BRAND_IMAGE = "/activemq-branding/plugin/img/activemq.png";
public LoginTest(MutableCapabilities browserOptions) { public LoginTest(MutableCapabilities browserOptions) {
super(browserOptions); super(browserOptions);
} }
@Test @Test
public void testLogin() { public void testLogin() {
driver.get(serverUrl + "/console");
LoginPage loginPage = new LoginPage(driver); LoginPage loginPage = new LoginPage(driver);
StatusPage statusPage = loginPage.loginValidUser( loginPage.loginValidUser(SERVER_ADMIN_USERNAME, SERVER_ADMIN_PASSWORD, DEFAULT_TIMEOUT);
SERVER_ADMIN_USERNAME, SERVER_ADMIN_PASSWORD, DEFAULT_TIMEOUT);
assertEquals(SERVER_ADMIN_USERNAME, statusPage.getUser());
} }
@Test @Test
public void testLoginBrand() { public void testLoginBrand() {
String expectedBrandImage = serverUrl + System.getProperty( String expectedBrandImage = serverUrl + System.getProperty(
"artemis.console.brand.image", DEFAULT_CONSOLE_BRAND_IMAGE); "artemis.console.login.brand.image", DEFAULT_CONSOLE_LOGIN_BRAND_IMAGE);
driver.get(serverUrl + "/console");
LoginPage loginPage = new LoginPage(driver); LoginPage loginPage = new LoginPage(driver);
assertEquals(expectedBrandImage, loginPage.getBrandImage(DEFAULT_TIMEOUT)); assertEquals(expectedBrandImage, loginPage.getBrandImage(DEFAULT_TIMEOUT));
} }

View File

@ -40,6 +40,7 @@ public class QueuesTest extends ConsoleTest {
@Test @Test
public void testDefaultQueues() throws Exception { public void testDefaultQueues() throws Exception {
driver.get(serverUrl + "/console");
LoginPage loginPage = new LoginPage(driver); LoginPage loginPage = new LoginPage(driver);
StatusPage statusPage = loginPage.loginValidUser( StatusPage statusPage = loginPage.loginValidUser(
SERVER_ADMIN_USERNAME, SERVER_ADMIN_PASSWORD, DEFAULT_TIMEOUT); SERVER_ADMIN_USERNAME, SERVER_ADMIN_PASSWORD, DEFAULT_TIMEOUT);
@ -58,6 +59,7 @@ public class QueuesTest extends ConsoleTest {
final String queueName = "TEST"; final String queueName = "TEST";
final String messageText = "TEST"; final String messageText = "TEST";
driver.get(serverUrl + "/console");
LoginPage loginPage = new LoginPage(driver); LoginPage loginPage = new LoginPage(driver);
StatusPage statusPage = loginPage.loginValidUser( StatusPage statusPage = loginPage.loginValidUser(
SERVER_ADMIN_USERNAME, SERVER_ADMIN_PASSWORD, DEFAULT_TIMEOUT); SERVER_ADMIN_USERNAME, SERVER_ADMIN_PASSWORD, DEFAULT_TIMEOUT);
@ -97,6 +99,6 @@ public class QueuesTest extends ConsoleTest {
QueuesPage afterQueuesPage = messagePage.getQueuesPage(DEFAULT_TIMEOUT); QueuesPage afterQueuesPage = messagePage.getQueuesPage(DEFAULT_TIMEOUT);
Wait.assertEquals(1, () -> afterQueuesPage.countQueue("DLQ")); Wait.assertEquals(1, () -> afterQueuesPage.countQueue("DLQ"));
Wait.assertEquals(0, () -> afterQueuesPage.countQueue(queueName)); Wait.assertEquals(0, () -> afterQueuesPage.getMessagesCount(queueName));
} }
} }

View File

@ -0,0 +1,35 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.activemq.artemis.tests.smoke.console.pages;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
public class IndexPage extends ConsolePage {
private By logoImageLocator = By.xpath("//div[@class='logo']/img");
public IndexPage(WebDriver driver) {
super(driver);
}
public String getLogoImage(int timeout) {
waitForElementToBeVisible(logoImageLocator, timeout);
return driver.findElement(logoImageLocator).getAttribute("src");
}
}