From 94e2378fdbc2c13de97c9bc9d93b5b1a83a077d5 Mon Sep 17 00:00:00 2001 From: Ondrej Kotek Date: Fri, 26 Jan 2024 19:56:47 +0100 Subject: [PATCH] Hardening against intermittent failures --- .../java/org/jboss/hal/testsuite/Console.java | 18 +++++++++++++----- .../jboss/hal/testsuite/CrudOperations.java | 11 ++++++++++- .../java/org/jboss/hal/testsuite/Random.java | 4 ++-- .../hal/testsuite/fragment/EmptyState.java | 3 +++ .../hal/testsuite/fragment/FormFragment.java | 7 +++++++ .../hal/testsuite/fragment/TableFragment.java | 3 +++ .../fragment/VerticalNavigationFragment.java | 1 - .../org/jboss/hal/testsuite/page/BasePage.java | 4 ++++ .../configuration/elytron/JDBCRealmTest.java | 4 +++- .../undertow/SessionOperationsTest.java | 13 ++++++++----- .../security/domain/SingleSignOnAddTest.java | 6 +++--- .../listener/AJPListenerConfigurationTest.java | 8 ++++---- .../servlet/container/CrawlerTest.java | 10 +++++----- .../servlet/container/WebSocketsTest.java | 16 ++++++++-------- .../testsuite/test/runtime/OpenPortsTest.java | 3 +++ .../test/runtime/ServerStatusTest.java | 15 ++++++++++++--- 16 files changed, 88 insertions(+), 38 deletions(-) diff --git a/common/src/main/java/org/jboss/hal/testsuite/Console.java b/common/src/main/java/org/jboss/hal/testsuite/Console.java index e9c6c924..480859f8 100644 --- a/common/src/main/java/org/jboss/hal/testsuite/Console.java +++ b/common/src/main/java/org/jboss/hal/testsuite/Console.java @@ -41,6 +41,7 @@ import org.jboss.hal.testsuite.util.Library; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.StaleElementReferenceException; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; @@ -127,11 +128,18 @@ public void verify(PlaceRequest placeRequest) { /** Waits until all notifications are gone. */ public void waitNoNotification() { List dismissibleNotifications = By.cssSelector(DOT + alertDismissable).findElements(browser); - for (WebElement notification : dismissibleNotifications) { - WebElement button = notification.findElement(By.cssSelector("button.close")); - if (button != null) { - button.click(); + for (int remainingExpected = dismissibleNotifications.size(); !dismissibleNotifications.isEmpty() + && remainingExpected > 0; remainingExpected--) { + + try { + WebElement button = dismissibleNotifications.get(0).findElement(By.cssSelector("button.close")); + if (button != null) { + button.click(); + } + } catch (StaleElementReferenceException ex) { + // Ignore the exception, the notification may be gone before clicking } + dismissibleNotifications = By.cssSelector(DOT + alertDismissable).findElements(browser); } waitModel().until().element(By.cssSelector(DOT + toastNotificationsListPf + ":empty")).is().present(); } @@ -152,7 +160,7 @@ public boolean verifyNoError() { } private void verifyNotification(String css) { - waitModel().until() // use waitModel() since it might take some time until the notification is visible + waitModel().until() // use waitModel() since the notification might take some time until the notification is visible .element(By.cssSelector(DOT + toastNotificationsListPf + " ." + css)) .is().visible(); } diff --git a/common/src/main/java/org/jboss/hal/testsuite/CrudOperations.java b/common/src/main/java/org/jboss/hal/testsuite/CrudOperations.java index 4a2ecff0..2f4db592 100644 --- a/common/src/main/java/org/jboss/hal/testsuite/CrudOperations.java +++ b/common/src/main/java/org/jboss/hal/testsuite/CrudOperations.java @@ -23,11 +23,14 @@ import org.jboss.hal.testsuite.creaper.ManagementClientProvider; import org.jboss.hal.testsuite.creaper.ResourceVerifier; import org.jboss.hal.testsuite.fragment.AddResourceDialogFragment; +import org.jboss.hal.testsuite.fragment.EmptyState; import org.jboss.hal.testsuite.fragment.FormFragment; import org.jboss.hal.testsuite.fragment.TableFragment; +import org.openqa.selenium.TimeoutException; import org.wildfly.extras.creaper.core.online.OnlineManagementClient; import org.wildfly.extras.creaper.core.online.operations.Address; +import static org.jboss.arquillian.graphene.Graphene.waitGui; import static org.jboss.hal.dmr.ModelDescriptionConstants.NAME; /** Methods useful to test and verify CRUD operations in application views. */ @@ -76,7 +79,13 @@ public void createSingleton(Address address, FormFragment form, Consumer initialValues, VerifyChanges verifyChanges) throws Exception { - form.emptyState().mainAction(); + try { + EmptyState emptyState = form.emptyState(); + waitGui().until().element(emptyState.getRoot()).is().visible(); + emptyState.mainAction(); + } catch (TimeoutException ex) { + form.emptyState().mainAction(); + } if (initialValues != null) { AddResourceDialogFragment dialog = console.addResourceDialog(); initialValues.accept(dialog.getForm()); // use the form of add resource dialog! diff --git a/common/src/main/java/org/jboss/hal/testsuite/Random.java b/common/src/main/java/org/jboss/hal/testsuite/Random.java index 9e1c5e0f..eaf37751 100644 --- a/common/src/main/java/org/jboss/hal/testsuite/Random.java +++ b/common/src/main/java/org/jboss/hal/testsuite/Random.java @@ -51,9 +51,9 @@ public static String jndiName(String name) { return JNDI_PREFIX + name; } - /** Returns a random integer between 0 and 99 */ + /** Returns a random integer between 1 and 99 */ public static int number() { - return RandomUtils.nextInt(0, 100); + return RandomUtils.nextInt(1, 100); } /** Returns a random double between 0.001 and 99.999 */ diff --git a/common/src/main/java/org/jboss/hal/testsuite/fragment/EmptyState.java b/common/src/main/java/org/jboss/hal/testsuite/fragment/EmptyState.java index 45f37901..927c211a 100644 --- a/common/src/main/java/org/jboss/hal/testsuite/fragment/EmptyState.java +++ b/common/src/main/java/org/jboss/hal/testsuite/fragment/EmptyState.java @@ -16,9 +16,11 @@ package org.jboss.hal.testsuite.fragment; import org.jboss.arquillian.graphene.fragment.Root; +import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; +import static org.jboss.arquillian.graphene.Graphene.waitModel; import static org.jboss.hal.resources.CSS.blankSlatePfMainAction; import static org.jboss.hal.resources.CSS.btnPrimary; @@ -30,6 +32,7 @@ public class EmptyState { /** Clicks on the main action */ public void mainAction() { + waitModel().until().element(root, By.cssSelector("." + blankSlatePfMainAction + " button." + btnPrimary)).is().visible(); primaryButton.click(); } diff --git a/common/src/main/java/org/jboss/hal/testsuite/fragment/FormFragment.java b/common/src/main/java/org/jboss/hal/testsuite/fragment/FormFragment.java index 2765dbf3..fd870ed4 100644 --- a/common/src/main/java/org/jboss/hal/testsuite/fragment/FormFragment.java +++ b/common/src/main/java/org/jboss/hal/testsuite/fragment/FormFragment.java @@ -26,12 +26,14 @@ import org.openqa.selenium.By; import org.openqa.selenium.ElementClickInterceptedException; import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.Keys; import org.openqa.selenium.TimeoutException; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebDriverException; import org.openqa.selenium.WebElement; import org.openqa.selenium.interactions.Actions; import org.openqa.selenium.support.FindBy; +import org.openqa.selenium.support.ui.ExpectedConditions; import static org.jboss.arquillian.graphene.Graphene.createPageFragment; import static org.jboss.arquillian.graphene.Graphene.waitGui; @@ -168,6 +170,11 @@ public void text(String name, String value) { waitGui().until().element(inputElement).value().equalTo(""); inputElement.sendKeys(value); waitGui().until().element(inputElement).value().equalTo(value); + + // get rid of any open auto suggestions popup, which might interfere with save or cancel buttons + inputElement.sendKeys(Keys.TAB); + waitGui().until(ExpectedConditions.invisibilityOfAllElements(ByJQuery + .selector(DOT + autocompleteSuggestions).findElements(browser))); } public void textByLabel(String labelContent, String value) { diff --git a/common/src/main/java/org/jboss/hal/testsuite/fragment/TableFragment.java b/common/src/main/java/org/jboss/hal/testsuite/fragment/TableFragment.java index cb59956a..9267d57c 100644 --- a/common/src/main/java/org/jboss/hal/testsuite/fragment/TableFragment.java +++ b/common/src/main/java/org/jboss/hal/testsuite/fragment/TableFragment.java @@ -28,6 +28,7 @@ import org.openqa.selenium.support.FindBy; import static org.jboss.arquillian.graphene.Graphene.waitGui; +import static org.jboss.arquillian.graphene.Graphene.waitModel; import static org.jboss.hal.resources.CSS.columnAction; import static org.jboss.hal.resources.CSS.halTableButtons; import static org.jboss.hal.testsuite.Selectors.contains; @@ -91,6 +92,7 @@ public WebElement button(String text) { */ public void select(String value) { By selector = ByJQuery.selector("td" + contains(value)); + waitModel().until().element(root, selector).is().present(); goToPageWithElement(selector); WebElement rowElement = root.findElement(selector); @@ -120,6 +122,7 @@ public void select(String value) { /** Clicks on the <action> column in the row which contains "<value>". */ public void action(String value, String action) { By selector = ByJQuery.selector("td" + contains(value) + " ~ td button." + columnAction + contains(action)); + waitModel().until().element(root, selector).is().present(); goToPageWithElement(selector); root.findElement(selector).click(); } diff --git a/common/src/main/java/org/jboss/hal/testsuite/fragment/VerticalNavigationFragment.java b/common/src/main/java/org/jboss/hal/testsuite/fragment/VerticalNavigationFragment.java index 80ddc29e..b6861f2a 100644 --- a/common/src/main/java/org/jboss/hal/testsuite/fragment/VerticalNavigationFragment.java +++ b/common/src/main/java/org/jboss/hal/testsuite/fragment/VerticalNavigationFragment.java @@ -38,7 +38,6 @@ public void selectPrimary(String id) { public void selectSecondary(String primaryId, String secondaryId) { WebElement primaryMenuItem = root.findElement(By.cssSelector("#" + primaryId + " > a")); new Actions(browser).moveToElement(primaryMenuItem).perform(); - primaryMenuItem.click(); waitGui().until().element(By.id(primaryId + "-secondary")).is().visible(); selectItem(secondaryId); } diff --git a/common/src/main/java/org/jboss/hal/testsuite/page/BasePage.java b/common/src/main/java/org/jboss/hal/testsuite/page/BasePage.java index a861d521..b60e99d5 100644 --- a/common/src/main/java/org/jboss/hal/testsuite/page/BasePage.java +++ b/common/src/main/java/org/jboss/hal/testsuite/page/BasePage.java @@ -56,5 +56,9 @@ public void navigate(Map params) { public void navigateAgain(String name, String value) { browser.navigate().refresh(); navigate(name, value); + if (!console.verifyNoError()) { + browser.navigate().refresh(); + navigate(name, value); + } } } diff --git a/tests-configuration-elytron/src/test/java/org/jboss/hal/testsuite/test/configuration/elytron/JDBCRealmTest.java b/tests-configuration-elytron/src/test/java/org/jboss/hal/testsuite/test/configuration/elytron/JDBCRealmTest.java index 55f68e09..619db8e6 100644 --- a/tests-configuration-elytron/src/test/java/org/jboss/hal/testsuite/test/configuration/elytron/JDBCRealmTest.java +++ b/tests-configuration-elytron/src/test/java/org/jboss/hal/testsuite/test/configuration/elytron/JDBCRealmTest.java @@ -97,6 +97,7 @@ import static org.jboss.hal.testsuite.fixtures.ElytronFixtures.SQL_UPDATE2; import static org.jboss.hal.testsuite.fixtures.ElytronFixtures.datasourceAddress; import static org.jboss.hal.testsuite.fixtures.ElytronFixtures.jdbcRealmAddress; + @RunWith(Arquillian.class) public class JDBCRealmTest { @@ -628,9 +629,10 @@ public void principalQueryModularCryptMapperUpdate() throws Exception { TableFragment table = page.getPrincipalQueryTable(); FormFragment form = page.getPrincipalQueryMcryptForm(); table.bind(form); + jdbcTable.filter(JDBC_RLM_UPDATE); jdbcTable.action(JDBC_RLM_UPDATE, PQ_LABEL); waitGui().until().element(table.getRoot()).is().visible(); - table.select(SQL_MCM_UPD); + table.filterAndSelect(SQL_MCM_UPD); page.getPrincipalQueryTabs().select(MCRYPT_MAPPER_TAB); long number = 23; ModelNode mapper = new ModelNode(); diff --git a/tests-configuration-undertow/src/test/java/org/jboss/hal/testsuite/test/configuration/undertow/SessionOperationsTest.java b/tests-configuration-undertow/src/test/java/org/jboss/hal/testsuite/test/configuration/undertow/SessionOperationsTest.java index 9ca35932..7a77270b 100644 --- a/tests-configuration-undertow/src/test/java/org/jboss/hal/testsuite/test/configuration/undertow/SessionOperationsTest.java +++ b/tests-configuration-undertow/src/test/java/org/jboss/hal/testsuite/test/configuration/undertow/SessionOperationsTest.java @@ -203,8 +203,10 @@ public void verifyAttributes() throws IOException { @Test public void verifyCreationTime() throws IOException { navigateToDeploymentRuntime(); - long creationTimeInMillis = System.currentTimeMillis(); + long creationTimeInMillisBefore = System.currentTimeMillis(); deploymentBrowser.get(DEPLOYMENT_URL); + long creationTimeInMillisAfter = System.currentTimeMillis(); + long creationTimeInMillis = ((creationTimeInMillisAfter - creationTimeInMillisBefore) / 2) + creationTimeInMillisBefore; reloadSessions(); String sessionId = getSessionsFromModel().get(0); page.getSessionsTable().select(sessionId); @@ -223,15 +225,16 @@ public void verifyLastAccessedTime() throws IOException, InterruptedException { reloadSessions(); String sessionId = getSessionsFromModel().get(0); page.getSessionsTable().select(sessionId); - long start = System.currentTimeMillis(); - long end = start + TimeUnit.MINUTES.toMillis(1); - TimeUnit.MINUTES.sleep(1); + TimeUnit.SECONDS.sleep(5); + long accessTimeBefore = System.currentTimeMillis(); deploymentBrowser.findElement(By.cssSelector("input[value=\"Increment\"")).click(); + long accessTimeAfter = System.currentTimeMillis(); + long accessTime = ((accessTimeAfter - accessTimeBefore) / 2) + accessTimeBefore; reloadSessions(); List selectedRowColumns = page.getSessionsTable().getRoot().findElements(By.cssSelector("tr.selected > td")); String lastAccessedTime = selectedRowColumns.get(2).getText(); Calendar lastAccessedTimeCalendar = Calendar.getInstance(); - lastAccessedTimeCalendar.setTimeInMillis(end); + lastAccessedTimeCalendar.setTimeInMillis(accessTime); Assert.assertEquals("Last accessed time should be matching", DATE_FORMAT.format(lastAccessedTimeCalendar.getTime()), lastAccessedTime); invalidateSession(sessionId); } diff --git a/tests-configuration-undertow/src/test/java/org/jboss/hal/testsuite/test/configuration/undertow/application/security/domain/SingleSignOnAddTest.java b/tests-configuration-undertow/src/test/java/org/jboss/hal/testsuite/test/configuration/undertow/application/security/domain/SingleSignOnAddTest.java index 11cea801..a541fbda 100644 --- a/tests-configuration-undertow/src/test/java/org/jboss/hal/testsuite/test/configuration/undertow/application/security/domain/SingleSignOnAddTest.java +++ b/tests-configuration-undertow/src/test/java/org/jboss/hal/testsuite/test/configuration/undertow/application/security/domain/SingleSignOnAddTest.java @@ -50,13 +50,13 @@ public class SingleSignOnAddTest { @BeforeClass public static void setUp() throws IOException { operations.add(httpAuthenticationFactoryAddress(HTTP_AUTH_CREATE), - Values.of(HTTP_SERVER_MECH_FACTORY, "global").and(SECURITY_DOMAIN, "ApplicationDomain")); + Values.of(HTTP_SERVER_MECH_FACTORY, "global").and(SECURITY_DOMAIN, "ApplicationDomain")).assertSuccess(); operations.add(applicationSecurityDomain(APPLICATION_SECURITY_DOMAIN_TO_BE_TESTED2), - Values.of(ApplicationSecurityDomainFixtures.HTTP_AUTHENTICATION_FACTORY, HTTP_AUTH_CREATE)); + Values.of(ApplicationSecurityDomainFixtures.HTTP_AUTHENTICATION_FACTORY, HTTP_AUTH_CREATE)).assertSuccess(); operations.add(ElytronFixtures.keyStoreAddress(KEY_STORE_TO_BE_ADDED), Values.of(TYPE, ElytronFixtures.JKS) .and(ElytronFixtures.CREDENTIAL_REFERENCE, new ModelNodeGenerator.ModelNodePropertiesBuilder() - .addProperty(ElytronFixtures.CREDENTIAL_REFERENCE_CLEAR_TEXT, Random.name()).build())); + .addProperty(ElytronFixtures.CREDENTIAL_REFERENCE_CLEAR_TEXT, Random.name()).build())).assertSuccess(); } @AfterClass diff --git a/tests-configuration-undertow/src/test/java/org/jboss/hal/testsuite/test/configuration/undertow/server/listener/AJPListenerConfigurationTest.java b/tests-configuration-undertow/src/test/java/org/jboss/hal/testsuite/test/configuration/undertow/server/listener/AJPListenerConfigurationTest.java index f18d4c62..08885972 100644 --- a/tests-configuration-undertow/src/test/java/org/jboss/hal/testsuite/test/configuration/undertow/server/listener/AJPListenerConfigurationTest.java +++ b/tests-configuration-undertow/src/test/java/org/jboss/hal/testsuite/test/configuration/undertow/server/listener/AJPListenerConfigurationTest.java @@ -69,14 +69,14 @@ public class AJPListenerConfigurationTest { @BeforeClass public static void setUp() throws IOException, CommandFailedException { - operations.add(IOFixtures.bufferPoolAddress(BUFFER_POOL_TO_BE_EDITED)); - operations.add(IOFixtures.workerAddress(WORKER_TO_BE_EDITED)); - operations.add(serverAddress(UNDERTOW_SERVER_TO_BE_TESTED)); + operations.add(IOFixtures.bufferPoolAddress(BUFFER_POOL_TO_BE_EDITED)).assertSuccess(); + operations.add(IOFixtures.workerAddress(WORKER_TO_BE_EDITED)).assertSuccess(); + operations.add(serverAddress(UNDERTOW_SERVER_TO_BE_TESTED)).assertSuccess(); client.apply(new AddLocalSocketBinding(SOCKET_BINDING)); client.apply(new AddLocalSocketBinding(SOCKET_BINDING_TO_BE_EDITED)); client.apply(new AddLocalSocketBinding(SOCKET_REDIRECT_TO_BE_EDITED)); operations.add(serverAddress(UNDERTOW_SERVER_TO_BE_TESTED).and("ajp-listener", AJP_LISTENER_TO_BE_EDITED), - Values.of("socket-binding", SOCKET_BINDING.toLowerCase() + "ref")); + Values.of("socket-binding", SOCKET_BINDING.toLowerCase() + "ref")).assertSuccess(); } @AfterClass diff --git a/tests-configuration-undertow/src/test/java/org/jboss/hal/testsuite/test/configuration/undertow/servlet/container/CrawlerTest.java b/tests-configuration-undertow/src/test/java/org/jboss/hal/testsuite/test/configuration/undertow/servlet/container/CrawlerTest.java index 3eec0857..fada55ef 100644 --- a/tests-configuration-undertow/src/test/java/org/jboss/hal/testsuite/test/configuration/undertow/servlet/container/CrawlerTest.java +++ b/tests-configuration-undertow/src/test/java/org/jboss/hal/testsuite/test/configuration/undertow/servlet/container/CrawlerTest.java @@ -57,11 +57,11 @@ private static Address crawlerAddress(String servletContainer) { @BeforeClass public static void setUp() throws IOException { - operations.add(UndertowFixtures.servletContainerAddress(SERVLET_CONTAINER_EDIT)); - operations.add(SERVLET_CONTAINER_EDIT_CRAWLER_ADDRESS); - operations.add(UndertowFixtures.servletContainerAddress(SERVLET_CONTAINER_CRAWLER_CREATE)); - operations.add(UndertowFixtures.servletContainerAddress(SERVLET_CONTAINER_CRAWLER_REMOVE)); - operations.add(crawlerAddress(SERVLET_CONTAINER_CRAWLER_REMOVE)); + operations.add(UndertowFixtures.servletContainerAddress(SERVLET_CONTAINER_EDIT)).assertSuccess(); + operations.add(SERVLET_CONTAINER_EDIT_CRAWLER_ADDRESS).assertSuccess(); + operations.add(UndertowFixtures.servletContainerAddress(SERVLET_CONTAINER_CRAWLER_CREATE)).assertSuccess(); + operations.add(UndertowFixtures.servletContainerAddress(SERVLET_CONTAINER_CRAWLER_REMOVE)).assertSuccess(); + operations.add(crawlerAddress(SERVLET_CONTAINER_CRAWLER_REMOVE)).assertSuccess(); } @AfterClass diff --git a/tests-configuration-undertow/src/test/java/org/jboss/hal/testsuite/test/configuration/undertow/servlet/container/WebSocketsTest.java b/tests-configuration-undertow/src/test/java/org/jboss/hal/testsuite/test/configuration/undertow/servlet/container/WebSocketsTest.java index 9d6b0c08..275f0796 100644 --- a/tests-configuration-undertow/src/test/java/org/jboss/hal/testsuite/test/configuration/undertow/servlet/container/WebSocketsTest.java +++ b/tests-configuration-undertow/src/test/java/org/jboss/hal/testsuite/test/configuration/undertow/servlet/container/WebSocketsTest.java @@ -68,13 +68,13 @@ private static Address webSocketsAddress(String servletContainer) { @BeforeClass public static void setUp() throws IOException { - operations.add(UndertowFixtures.servletContainerAddress(SERVLET_CONTAINER_EDIT)); - operations.add(SERVLET_CONTAINER_EDIT_WEB_SOCKETS_ADDRESS); - operations.add(UndertowFixtures.servletContainerAddress(SERVLET_CONTAINER_WEB_SOCKETS_CREATE)); - operations.add(UndertowFixtures.servletContainerAddress(SERVLET_CONTAINER_WEB_SOCKETS_REMOVE)); - operations.add(webSocketsAddress(SERVLET_CONTAINER_WEB_SOCKETS_REMOVE)); - operations.add(IOFixtures.bufferPoolAddress(BUFFER_POOL_TO_BE_EDITED)); - operations.add(IOFixtures.workerAddress(WORKER_TO_BE_EDITED)); + operations.add(UndertowFixtures.servletContainerAddress(SERVLET_CONTAINER_EDIT)).assertSuccess(); + operations.add(SERVLET_CONTAINER_EDIT_WEB_SOCKETS_ADDRESS).assertSuccess(); + operations.add(UndertowFixtures.servletContainerAddress(SERVLET_CONTAINER_WEB_SOCKETS_CREATE)).assertSuccess(); + operations.add(UndertowFixtures.servletContainerAddress(SERVLET_CONTAINER_WEB_SOCKETS_REMOVE)).assertSuccess(); + operations.add(webSocketsAddress(SERVLET_CONTAINER_WEB_SOCKETS_REMOVE)).assertSuccess(); + operations.add(IOFixtures.bufferPoolAddress(BUFFER_POOL_TO_BE_EDITED)).assertSuccess(); + operations.add(IOFixtures.workerAddress(WORKER_TO_BE_EDITED)).assertSuccess(); } @AfterClass @@ -117,7 +117,7 @@ public void editBufferPool() throws Exception { public void editDeflaterLevel() throws Exception { navigateToWebSocketsForm(SERVLET_CONTAINER_EDIT); crudOperations.update(SERVLET_CONTAINER_EDIT_WEB_SOCKETS_ADDRESS, page.getWebSocketsForm(), "deflater-level", - Random.number(0, 10)); + Random.number(0, 9)); } @Test diff --git a/tests-hal-runtime/src/test/java/org/jboss/hal/testsuite/test/runtime/OpenPortsTest.java b/tests-hal-runtime/src/test/java/org/jboss/hal/testsuite/test/runtime/OpenPortsTest.java index b663a6ab..96627d6e 100644 --- a/tests-hal-runtime/src/test/java/org/jboss/hal/testsuite/test/runtime/OpenPortsTest.java +++ b/tests-hal-runtime/src/test/java/org/jboss/hal/testsuite/test/runtime/OpenPortsTest.java @@ -36,6 +36,7 @@ import org.junit.Test; import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; +import org.openqa.selenium.By; import org.wildfly.extras.creaper.core.online.ModelNodeResult; import org.wildfly.extras.creaper.core.online.OnlineManagementClient; import org.wildfly.extras.creaper.core.online.operations.Address; @@ -43,6 +44,7 @@ import org.wildfly.extras.creaper.core.online.operations.Values; import static java.util.stream.Collectors.toList; +import static org.jboss.arquillian.graphene.Graphene.waitGui; import static org.jboss.hal.dmr.ModelDescriptionConstants.*; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertFalse; @@ -70,6 +72,7 @@ public void setUp() throws Exception { FinderFragment finder = console.finder(NameTokens.RUNTIME); finder.column(Ids.STANDALONE_SERVER_COLUMN) .selectItem(Ids.hostServer(Ids.STANDALONE_HOST, serverEnvironmentUtils.getServerHostName())); + waitGui().until().element(By.id("open-ports")).is().present(); preview = finder.preview(ServerPreviewFragment.class); } diff --git a/tests-hal-runtime/src/test/java/org/jboss/hal/testsuite/test/runtime/ServerStatusTest.java b/tests-hal-runtime/src/test/java/org/jboss/hal/testsuite/test/runtime/ServerStatusTest.java index f93bcc3f..13cfb776 100644 --- a/tests-hal-runtime/src/test/java/org/jboss/hal/testsuite/test/runtime/ServerStatusTest.java +++ b/tests-hal-runtime/src/test/java/org/jboss/hal/testsuite/test/runtime/ServerStatusTest.java @@ -87,15 +87,24 @@ public void setUp() throws Exception { @Test public void memory() { - assertUsage(preview.getHeapUsed(), "heap used", heapUsed, 20); + assertHeapUsed(preview.getHeapUsed(), "heap used", heapUsed, 60); assertUsage(preview.getHeapCommitted(), "heap committed", heapCommitted, 10); assertUsage(preview.getNonHeapUsed(), "non-heap used", nonHeapUsed, 10); assertUsage(preview.getNonHeapCommitted(), "non-heap committed", nonHeapCommitted, 10); - assertUsage(preview.getThreads(), "threads", daemons, 5); + assertUsage(preview.getThreads(), "threads", daemons, 30); } private void assertUsage(WebElement element, String message, long expected, long delta) { long actual = Long.parseLong(element.getAttribute("aria-valuenow")); - assertTrue(message, Math.abs(expected - actual) <= delta); + String detailedMessage = String.format("'" + message + "' not match (expected: %d, actual: %d, max. delta: %d)", + expected, actual, delta); + assertTrue(detailedMessage, Math.abs(expected - actual) <= delta); + } + + private void assertHeapUsed(WebElement element, String message, long expected, long delta) { + long actual = Long.parseLong(element.getAttribute("aria-valuenow")); + String detailedMessage = String.format("'" + message + "' not match (expected: %d, actual: %d, max. delta: %d)", + expected, actual, delta); + assertTrue(detailedMessage, Math.abs(expected - actual) <= delta || expected > actual); } }