From bc45e07aa2b3ba35ccc4231e0c83d01665048e1c Mon Sep 17 00:00:00 2001 From: pethers Date: Tue, 21 Jan 2025 18:22:55 +0100 Subject: [PATCH] test cleanup --- .../systemintegrationtest/AbstractUITest.java | 20 +- .../CitizenIntelligenceAgencyServer.java | 1 + .../admin/AbstractAdminTest.java | 1 + .../systemintegrationtest/ui/ClickHelper.java | 100 ++-- .../ui/ElementHelper.java | 84 ---- .../ui/StaleElementUtils.java | 292 ++++++------ .../ui/TestConstants.java | 13 +- .../ui/UserPageVisit.java | 429 +++++++++--------- .../ui/WebDriverFactory.java | 14 +- .../user/home/UserHomeTest.java | 41 +- .../src/test/resources/logback-test.xml | 6 +- parent-pom/pom.xml | 4 +- 12 files changed, 438 insertions(+), 567 deletions(-) delete mode 100644 citizen-intelligence-agency/src/test/java/com/hack23/cia/systemintegrationtest/ui/ElementHelper.java diff --git a/citizen-intelligence-agency/src/test/java/com/hack23/cia/systemintegrationtest/AbstractUITest.java b/citizen-intelligence-agency/src/test/java/com/hack23/cia/systemintegrationtest/AbstractUITest.java index 712aa9eded..a20d0fc51a 100644 --- a/citizen-intelligence-agency/src/test/java/com/hack23/cia/systemintegrationtest/AbstractUITest.java +++ b/citizen-intelligence-agency/src/test/java/com/hack23/cia/systemintegrationtest/AbstractUITest.java @@ -1,7 +1,8 @@ package com.hack23.cia.systemintegrationtest; import org.junit.After; -import org.junit.Before; +import org.junit.AfterClass; +import org.junit.BeforeClass; import org.openqa.selenium.WebDriver; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -26,16 +27,16 @@ public abstract class AbstractUITest extends AbstractRoleSystemITest { CitizenIntelligenceAgencyServer.ACCESS_URL); /** The driver. */ - protected WebDriver driver; + protected static WebDriver driver; /** The page visit. */ - protected UserPageVisit pageVisit; + protected static UserPageVisit pageVisit; /** * Global setup. */ - @Before - public void globalSetup() { + @BeforeClass + public static void globalSetup() { LOG.info("Setting up test with browser"); driver = WebDriverFactory.createDriver(); pageVisit = new UserPageVisit(driver); @@ -44,12 +45,17 @@ public void globalSetup() { /** * Global teardown. */ - @After - public void globalTeardown() { + @AfterClass + public static void globalTeardown() { LOG.info("Tearing down WebDriver after all tests have run"); if (driver != null) { driver.quit(); } } + @After + public void cleanBrowser() { + pageVisit.cleanBrowser(); + } + } diff --git a/citizen-intelligence-agency/src/test/java/com/hack23/cia/systemintegrationtest/CitizenIntelligenceAgencyServer.java b/citizen-intelligence-agency/src/test/java/com/hack23/cia/systemintegrationtest/CitizenIntelligenceAgencyServer.java index a97c11178f..86e22bf1a7 100644 --- a/citizen-intelligence-agency/src/test/java/com/hack23/cia/systemintegrationtest/CitizenIntelligenceAgencyServer.java +++ b/citizen-intelligence-agency/src/test/java/com/hack23/cia/systemintegrationtest/CitizenIntelligenceAgencyServer.java @@ -77,6 +77,7 @@ public final class CitizenIntelligenceAgencyServer { System.setProperty("org.eclipse.jetty.util.log.class", "org.eclipse.jetty.util.log.Slf4jLog"); System.setProperty("jetty.sslContext.sniRequired", "false"); System.setProperty("jetty.ssl.sniRequired", "false"); + System.setProperty("java.util.logging.manage", "org.jboss.logmanager.LogManager"); LogManager.getLogManager().reset(); SLF4JBridgeHandler.install(); diff --git a/citizen-intelligence-agency/src/test/java/com/hack23/cia/systemintegrationtest/admin/AbstractAdminTest.java b/citizen-intelligence-agency/src/test/java/com/hack23/cia/systemintegrationtest/admin/AbstractAdminTest.java index 5a7b10b7bc..a8e8ed6854 100644 --- a/citizen-intelligence-agency/src/test/java/com/hack23/cia/systemintegrationtest/admin/AbstractAdminTest.java +++ b/citizen-intelligence-agency/src/test/java/com/hack23/cia/systemintegrationtest/admin/AbstractAdminTest.java @@ -19,6 +19,7 @@ public abstract class AbstractAdminTest extends AbstractUITest { */ @Before public void adminSetup() throws Exception { + pageVisit.cleanBrowser(); pageVisit.loginAsAdmin(); } diff --git a/citizen-intelligence-agency/src/test/java/com/hack23/cia/systemintegrationtest/ui/ClickHelper.java b/citizen-intelligence-agency/src/test/java/com/hack23/cia/systemintegrationtest/ui/ClickHelper.java index 1cb6171bfb..9ee6d8a444 100644 --- a/citizen-intelligence-agency/src/test/java/com/hack23/cia/systemintegrationtest/ui/ClickHelper.java +++ b/citizen-intelligence-agency/src/test/java/com/hack23/cia/systemintegrationtest/ui/ClickHelper.java @@ -1,7 +1,6 @@ package com.hack23.cia.systemintegrationtest.ui; -import java.time.Duration; - +import org.openqa.selenium.StaleElementReferenceException; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.interactions.Actions; @@ -11,66 +10,39 @@ */ public class ClickHelper { - /** The actions. */ - private final Actions actions; - - /** The helper. */ - private final UserPageVisitHelper helper; - - /** The enable screen shot. */ - public static boolean enableScreenShot = false; - - /** - * Instantiates a new click helper. - * - * @param driver the driver - * @param helper the helper - */ - public ClickHelper(WebDriver driver, UserPageVisitHelper helper) { - this.actions = new Actions(driver); - this.helper = helper; - } - - /** - * Click with retry. - * - * @param element the element - */ - public void clickWithRetry(WebElement element) { - clickElement(element); - } - - /** - * Click with delay. - * - * @param element the element - */ - public void clickWithDelay(WebElement element) { - clickElement(element); - - } - - /** - * Click element. - * - * @param element the element - */ - private void clickElement(WebElement element) { - - - - actions.pause(Duration.ofMillis(400)).build().perform(); - - actions.pause(Duration.ofMillis(250)) - .clickAndHold(helper.refreshElement(element)) - .release() - .pause(Duration.ofMillis(250)) - .perform(); - - actions.pause(Duration.ofMillis(400)).build().perform(); - - if(enableScreenShot) { - helper.grabScreenshot(); + private final Actions actions; + private final UserPageVisitHelper helper; + public static boolean enableScreenShot = false; + + public ClickHelper(WebDriver driver, UserPageVisitHelper helper) { + this.actions = new Actions(driver); + this.helper = helper; + } + + /** + * Perform click on a given element, waiting for it to be clickable. + * + * @param element the element + */ + public void performClick(WebElement element) { + for (int i = 0; i < 2; i++) { + try { + actions.pause(TestConstants.CLICK_PAUSE_AFTER).moveToElement(helper.refreshElement(element)) + .pause(TestConstants.CLICK__MOVE_TO_PAUSE).click().pause(TestConstants.CLICK_PAUSE_AFTER) + .perform(); + + if (enableScreenShot) { + helper.grabScreenshot(); + } + return; // success, break out of method + + } catch (final StaleElementReferenceException stale) { + if (i == 1) { + // if second attempt fails, re-throw + throw stale; + } + } } - } -} + + } +} \ No newline at end of file diff --git a/citizen-intelligence-agency/src/test/java/com/hack23/cia/systemintegrationtest/ui/ElementHelper.java b/citizen-intelligence-agency/src/test/java/com/hack23/cia/systemintegrationtest/ui/ElementHelper.java deleted file mode 100644 index 0c4cbf3b26..0000000000 --- a/citizen-intelligence-agency/src/test/java/com/hack23/cia/systemintegrationtest/ui/ElementHelper.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.hack23.cia.systemintegrationtest.ui; - -import java.time.Duration; -import java.util.ArrayList; -import java.util.List; - -import org.openqa.selenium.By; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.support.ui.ExpectedConditions; -import org.openqa.selenium.support.ui.WebDriverWait; - -/** - * The Class ElementHelper. - */ -public class ElementHelper { - - /** The driver. */ - private final WebDriver driver; - - /** The wait timeout. */ - private final Duration waitTimeout; - - /** - * Instantiates a new element helper. - * - * @param driver the driver - * @param waitTimeout the wait timeout - */ - public ElementHelper(WebDriver driver, Duration waitTimeout) { - this.driver = driver; - this.waitTimeout = waitTimeout; - } - - /** - * Wait for clickable. - * - * @param locator the locator - * @return the web element - */ - public WebElement waitForClickable(By locator) { - return new WebDriverWait(driver, waitTimeout) - .until(ExpectedConditions.elementToBeClickable(locator)); - } - - /** - * Find buttons. - * - * @return the list - */ - public List findButtons() { - final List buttons = new ArrayList<>(); - buttons.addAll(driver.findElements(By.className("v-nativebutton"))); - buttons.addAll(driver.findElements(By.className("v-button"))); - buttons.addAll(driver.findElements(By.className("v-button-caption"))); - buttons.addAll(driver.findElements(By.tagName("a"))); - return buttons; - } - - /** - * Find button by text. - * - * @param text the text - * @return the web element - */ - public WebElement findButtonByText(String text) { - return findButtons().stream() - .filter(button -> matchesButtonText(button, text)) - .findFirst() - .orElse(null); - } - - /** - * Matches button text. - * - * @param button the button - * @param text the text - * @return true, if successful - */ - private boolean matchesButtonText(WebElement button, String text) { - final String buttonText = button.getText().trim(); - return text.equalsIgnoreCase(buttonText) || buttonText.endsWith(text); - } -} diff --git a/citizen-intelligence-agency/src/test/java/com/hack23/cia/systemintegrationtest/ui/StaleElementUtils.java b/citizen-intelligence-agency/src/test/java/com/hack23/cia/systemintegrationtest/ui/StaleElementUtils.java index 312acbd61a..376d78ddcd 100644 --- a/citizen-intelligence-agency/src/test/java/com/hack23/cia/systemintegrationtest/ui/StaleElementUtils.java +++ b/citizen-intelligence-agency/src/test/java/com/hack23/cia/systemintegrationtest/ui/StaleElementUtils.java @@ -23,150 +23,150 @@ public class StaleElementUtils { /** The Constant LOGGER. */ private static final Logger LOGGER = LoggerFactory.getLogger(StaleElementUtils.class); - /** - * Gets the by. - * - * @param key - * the key - * @param value - * the value - * @return the by - * @throws InvocationTargetException - * the invocation target exception - * @throws IllegalAccessException - * the illegal access exception - */ - private static By getBy(final String key, final String value) throws InvocationTargetException, IllegalAccessException { - final String methodName = key.replace(" ", ""); - final Method m = getCaseInsensitiveStaticDeclaredMethod(By.class, methodName); - return (By) m.invoke(null, value); - } - - /** - * Gets the case insensitive declared method. - * - * @param obj - * the obj - * @param methodName - * the method name - * @return the case insensitive declared method - */ - private static Method getCaseInsensitiveDeclaredMethod(final Object obj, final String methodName) { - final Method[] methods = obj.getClass().getMethods(); - Method method = null; - for (final Method m : methods) { - if (m.getName().equalsIgnoreCase(methodName)) { - method = m; - break; - } - } - if (method == null) { - throw new IllegalStateException(String.format(Locale.ENGLISH,"%s Method name is not found for this Class %s", methodName, - obj.getClass().toString())); - } - return method; - } - - /** - * Gets the case insensitive static declared method. - * - * @param clazz - * the clazz - * @param methodName - * the method name - * @return the case insensitive static declared method - */ - @SuppressWarnings("rawtypes") - private static Method getCaseInsensitiveStaticDeclaredMethod(final Class clazz, final String methodName) { - final Method[] methods = clazz.getMethods(); - Method method = null; - for (final Method m : methods) { - if (m.getName().equalsIgnoreCase(methodName)) { - method = m; - break; - } - } - if (method == null) { - throw new IllegalStateException( - String.format(Locale.ENGLISH,"%s Method name is not found for this Class %s", methodName, clazz.toString())); - } - return method; - } - - /** - * Gets the web element. - * - * @param lastObject - * the last object - * @param key - * the key - * @param value - * the value - * @return the web element - */ - private static WebElement getWebElement(final Object lastObject, final String key, final String value) { - WebElement element = null; - try { - final By by = getBy(key, value); - final Method m = getCaseInsensitiveDeclaredMethod(lastObject, "findElement"); - element = (WebElement) m.invoke(lastObject, by); - } catch (final InvocationTargetException | IllegalAccessException e) { - e.printStackTrace(); - } - return element; - } - - /** - * Checks if is element stale. - * - * @param e - * the e - * @return true, if is element stale - */ - public static boolean isElementStale(final WebElement e) { - try { - e.isDisplayed(); - return false; - } catch (final StaleElementReferenceException ex) { - return true; - } - } - - /** - * Refresh element. - * - * @param elem - * the elem - * @param driver - * the driver - * @return the web element - */ - public static WebElement refreshElement(final WebElement elem, final WebDriver driver) { - if (!isElementStale(elem)) { - return elem; - } - Object lastObject = null; - try { - final String[] arr = elem.toString().split("->"); - for (final String s : arr) { - final String newstr = s.trim().replaceAll("^\\[+", "").replaceAll("\\]+$", ""); - final String[] parts = newstr.split(": "); - final String key = parts[0]; - String value = parts[1]; - final int leftBracketsCount = value.length() - value.replace("[", "").length(); - final int rightBracketscount = value.length() - value.replace("]", "").length(); - if (leftBracketsCount - rightBracketscount == 1) { - value = value + "]"; - } - if (lastObject == null) { - lastObject = driver; - } else { - lastObject = getWebElement(lastObject, key, value); - } - } - } catch (final Exception e) { - LOGGER.error("Error in Refreshing the stale Element."); - } - return (WebElement) lastObject; - } + + /** + * Checks if the given element is stale. + * + * @param element the element + * @return true if stale, false if still valid + */ + public static boolean isElementStale(final WebElement element) { + try { + element.isDisplayed(); // If this throws, we know it’s stale + return false; + } catch (final StaleElementReferenceException ex) { + return true; + } + } + + /** + * Attempt to "refresh" the element by parsing the internal toString() + * representation to reconstruct a locator. If the element is not + * stale, it is simply returned unchanged. + * + * @param elem the stale element + * @param driver the WebDriver + * @return a fresh WebElement if possible, otherwise null if re-location fails + */ + public static WebElement refreshElement(final WebElement elem, final WebDriver driver) { + // If element is still good, just return it + if (!isElementStale(elem)) { + return elem; + } + + Object lastObject = driver; // Start from the driver + try { + // Example: [[ChromeDriver: chrome on MAC (1234)] -> id: foo -> xpath: //div[...]] + final String description = elem.toString(); + final String[] locatorSegments = description.split("->"); + + // We iterate over each arrow segment to identify "key: value" + for (final String segment : locatorSegments) { + final String trimmed = segment.trim().replaceAll("^\\[+", "").replaceAll("\\]+$", ""); + final String[] parts = trimmed.split(": ", 2); + if (parts.length != 2) { + LOGGER.debug("Skipping unrecognized segment format: '{}'", segment); + continue; + } + + final String key = parts[0]; // e.g. "id", "xpath" + String value = parts[1]; // e.g. "foo", "//div[...]" + + // Sometimes the bracket balancing is off; attempt to fix + final int leftBracketsCount = value.length() - value.replace("[", "").length(); + final int rightBracketsCount = value.length() - value.replace("]", "").length(); + if (leftBracketsCount - rightBracketsCount == 1) { + value = value + "]"; + } + + // Re-find using reflection-based approach + lastObject = getWebElement(lastObject, key, value); + if (lastObject == null) { + LOGGER.warn("Could not re-locate element using key={} and value={}", key, value); + return null; + } + } + + // If lastObject is a valid WebElement, we assume it was re-located + if (lastObject instanceof WebElement) { + return (WebElement) lastObject; + } else { + LOGGER.warn("Failed to refresh stale element: lastObject is not a WebElement"); + } + + } catch (final Exception e) { + LOGGER.error("Error refreshing the stale element: {}", elem, e); + } + + // Return null if we failed to re-locate + return null; + } + + /** + * Build a By locator from a 'key: value' pair via reflection. For example: + *
id: foo
or
xpath: //div[...]
. + * + * @param key e.g. "id", "xpath" + * @param value e.g. "foo", "//div[...]" + * @return a new By object + * @throws InvocationTargetException if reflection call fails + * @throws IllegalAccessException if reflection call fails + */ + private static By getBy(final String key, final String value) + throws InvocationTargetException, IllegalAccessException { + final String methodName = key.replace(" ", ""); + final Method m = getCaseInsensitiveStaticMethod(By.class, methodName); + return (By) m.invoke(null, value); + } + + /** + * Reflectively find a static method on {@link By} that matches, ignoring case. + * E.g. "xpath", "XPATH", "XPath" all return By.xpath(...). + * + * @param clazz The By class + * @param methodName The method name (case-insensitive) + * @return matching Method + */ + @SuppressWarnings("rawtypes") + private static Method getCaseInsensitiveStaticMethod(final Class clazz, final String methodName) { + final Method[] methods = clazz.getMethods(); + for (final Method m : methods) { + if (m.getName().equalsIgnoreCase(methodName)) { + return m; + } + } + throw new IllegalStateException(String.format(Locale.ENGLISH, + "No static method named '%s' found on class %s", methodName, clazz)); + } + + /** + * Reflectively call findElement(By) on either a WebDriver or WebElement, + * ignoring case for the method name. Returns null if invocation fails. + * + * @param lastObject a WebDriver or WebElement + * @param key e.g. "id", "xpath" + * @param value the locator value + * @return the newly found WebElement or null + */ + private static WebElement getWebElement(final Object lastObject, final String key, final String value) { + try { + final By by = getBy(key, value); + + if (lastObject instanceof WebDriver) { + return ((WebDriver) lastObject).findElement(by); + } else if (lastObject instanceof WebElement) { + return ((WebElement) lastObject).findElement(by); + } else { + LOGGER.warn("Unable to call findElement(...) on object type: {}", lastObject.getClass()); + return null; + } + } catch (InvocationTargetException | IllegalAccessException e) { + LOGGER.error("Failed to invoke By.{}(\"{}\") or findElement(...) via reflection", key, value, e); + return null; + } catch (final Exception ex) { + LOGGER.error("Unexpected error creating or using By locator: {} = {}", key, value, ex); + return null; + } + } + } diff --git a/citizen-intelligence-agency/src/test/java/com/hack23/cia/systemintegrationtest/ui/TestConstants.java b/citizen-intelligence-agency/src/test/java/com/hack23/cia/systemintegrationtest/ui/TestConstants.java index ddc46eca46..bd0d7d1a3f 100644 --- a/citizen-intelligence-agency/src/test/java/com/hack23/cia/systemintegrationtest/ui/TestConstants.java +++ b/citizen-intelligence-agency/src/test/java/com/hack23/cia/systemintegrationtest/ui/TestConstants.java @@ -12,10 +12,18 @@ public final class TestConstants { public static final long DEFAULT_TIMEOUT = 25000; /** The Constant WAIT_FOR_PAGE_DELAY. */ - public static final int WAIT_FOR_PAGE_DELAY = 7500; + public static final long CHECK = 100; /** The Constant WAIT_FOR_PAGE_ELEMENT. */ - public static final Duration WAIT_FOR_PAGE_ELEMENT = Duration.ofMillis(7500); + public static final Duration WAIT_FOR_PAGE_ELEMENT = Duration.ofMillis(8000); + + public static final Duration DEFAULT_BROWSER_TIMEOUT = Duration.ofSeconds(7); + + public static final Duration CLICK_PAUSE = Duration.ofSeconds(5); + + public static final Duration CLICK__MOVE_TO_PAUSE = Duration.ofMillis(500); + public static final Duration CLICK_PAUSE_AFTER = Duration.ofMillis(1000); + /** * Instantiates a new test constants. @@ -39,6 +47,7 @@ private TestConstants() { /** The Constant DEFAULT_COUNTRY. */ public static final String DEFAULT_COUNTRY = "Sweden"; + /** * Generate password. * diff --git a/citizen-intelligence-agency/src/test/java/com/hack23/cia/systemintegrationtest/ui/UserPageVisit.java b/citizen-intelligence-agency/src/test/java/com/hack23/cia/systemintegrationtest/ui/UserPageVisit.java index f0998ea0a8..bf8a1ecb91 100644 --- a/citizen-intelligence-agency/src/test/java/com/hack23/cia/systemintegrationtest/ui/UserPageVisit.java +++ b/citizen-intelligence-agency/src/test/java/com/hack23/cia/systemintegrationtest/ui/UserPageVisit.java @@ -32,7 +32,6 @@ import org.openqa.selenium.WebElement; import org.openqa.selenium.interactions.Actions; import org.openqa.selenium.support.ui.ExpectedConditions; -import org.openqa.selenium.support.ui.FluentWait; import org.openqa.selenium.support.ui.WebDriverWait; import com.hack23.cia.systemintegrationtest.CitizenIntelligenceAgencyServer; @@ -75,40 +74,93 @@ public final class UserPageVisit extends Assert { } } + /** The action. */ + private final Actions action; + + /** The click helper. */ + private final ClickHelper clickHelper; + /** The driver. */ final WebDriver driver; + /** The helper. */ private final UserPageVisitHelper helper; - /** The element helper. */ - private final ElementHelper elementHelper; - - /** The click helper. */ - private final ClickHelper clickHelper; - - /** The action. */ - private final Actions action; + private final WebDriverWait wait; /** * Instantiates a new user page visit. * - * @param driver the driver + * @param driver the driver */ public UserPageVisit(final WebDriver driver) { super(); this.driver = driver; this.helper = new UserPageVisitHelper(driver); - this.elementHelper = new ElementHelper(driver, TestConstants.WAIT_FOR_PAGE_ELEMENT); this.clickHelper = new ClickHelper(driver, helper); action = new Actions(driver); - } + wait = new WebDriverWait(driver, TestConstants.WAIT_FOR_PAGE_ELEMENT,Duration.ofMillis(TestConstants.CHECK)); + } + + + /** + * Wait for clickable. + * + * @param locator the locator + * @return the web element + */ + public WebElement waitForClickable(By locator) { + return wait.until(ExpectedConditions.elementToBeClickable(locator)); + } + + /** + * Find buttons. + * + * @return the list + */ + public List findButtons() { + final List buttons = new ArrayList<>(); + buttons.addAll(driver.findElements(By.className("v-nativebutton"))); + buttons.addAll(driver.findElements(By.className("v-button"))); + buttons.addAll(driver.findElements(By.className("v-button-caption"))); + buttons.addAll(driver.findElements(By.tagName("a"))); + return buttons; + } + + /** + * Find button by text. + * + * @param text the text + * @return the web element + */ + public WebElement findButtonByText(String text) { + return findButtons().stream() + .filter(button -> matchesButtonText(button, text)) + .findFirst() + .orElse(null); + } + + /** + * Matches button text. + * + * @param button the button + * @param text the text + * @return true, if successful + */ + private boolean matchesButtonText(WebElement button, String text) { + final String buttonText = button.getText().trim(); + return text.equalsIgnoreCase(buttonText) || buttonText.endsWith(text); + } + + + /** * Change password. * - * @param password the password - * @param newPassword the new password + * @param password the password + * @param newPassword the new password * @param repeatNewPassword the repeat new password */ public void changePassword(final String password, final String newPassword, final String repeatNewPassword) { @@ -116,18 +168,17 @@ public void changePassword(final String password, final String newPassword, fina setFieldValue("Change password.newPassword", newPassword); setFieldValue("Change password.repeatNewPassword", repeatNewPassword); - clickHelper.clickWithRetry(findButton("Change password")); + clickHelper.performClick(findButton("Change password")); } /** * Check html body contains text. * - * @param text - * the text + * @param text the text * @return true, if successful */ public boolean checkHtmlBodyContainsText(final String text) { - final FluentWait wait = new WebDriverWait(driver, TestConstants.WAIT_FOR_PAGE_ELEMENT).pollingEvery(Duration.ofMillis(10)); + wait.until(helper.containsViewAction(ViewAction.VISIT_MAIN_VIEW)); return getHtmlBodyAsText().contains(text); } @@ -135,11 +186,10 @@ public boolean checkHtmlBodyContainsText(final String text) { /** * Check notification message. * - * @param expectedValue - * the expected value + * @param expectedValue the expected value */ public void checkNotificationMessage(final String expectedValue) { - final FluentWait wait = new WebDriverWait(driver, TestConstants.WAIT_FOR_PAGE_ELEMENT).pollingEvery(Duration.ofMillis(10)); + wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("v-Notification"))); final WebElement notification = driver.findElement(By.className("v-Notification")); assertNotNull(notification); @@ -147,6 +197,36 @@ public void checkNotificationMessage(final String expectedValue) { } + /** + * Clean browser. + */ + public void cleanBrowser() { + if (driver != null) { + driver.manage().deleteAllCookies(); + driver.get("about:blank"); + } + } + + /** + * Click first row in grid. + * + * @param userPageVisit the user page visit + * @throws InterruptedException the interrupted exception + */ + protected final void clickFirstRowInGrid(final UserPageVisit userPageVisit) throws InterruptedException { + final List gridRows = userPageVisit.getGridRows(); + assertFalse(gridRows.isEmpty()); + + final WebElement choosenRow = gridRows.iterator().next(); + + final List cells = choosenRow.findElements(By.className("v-grid-cell")); + + final WebElement choosenCell = cells.iterator().next(); + + userPageVisit.performClickAction(choosenCell); + + } + /** * Close modal. */ @@ -154,36 +234,36 @@ public void closeModal() { final WebElement closeModalWindow = driver.findElement(By.className("v-window-closebox")); assertNotNull("Expect to find a Window close Box", closeModalWindow); - performClickActionWithRetry(closeModalWindow); + performClick(closeModalWindow); } /** - * Disable google authenticator. + * Delete account. * * @param password the password */ - public void disableGoogleAuthenticator(final String password) { - setFieldValue("Disable Google Authenticator.userpassword", password); + public void deleteAccount(final String password) { + setFieldValue("Delete Account.userpassword", password); - final WebElement enableGoogleAuthButton = driver.findElement(By.id("Disable Google Authenticator")); - assertNotNull("Expect to find a Enable Google Authenticator Button", enableGoogleAuthButton); + final WebElement deleteButton = driver.findElement(By.id("Delete Account")); + assertNotNull("Expect to find a Delete Account Button", deleteButton); - performClickActionWithRetry(enableGoogleAuthButton); + performClick(deleteButton); } /** - * Delete account. + * Disable google authenticator. * * @param password the password */ - public void deleteAccount(final String password) { - setFieldValue("Delete Account.userpassword", password); + public void disableGoogleAuthenticator(final String password) { + setFieldValue("Disable Google Authenticator.userpassword", password); - final WebElement deleteButton = driver.findElement(By.id("Delete Account")); - assertNotNull("Expect to find a Delete Account Button", deleteButton); + final WebElement enableGoogleAuthButton = driver.findElement(By.id("Disable Google Authenticator")); + assertNotNull("Expect to find a Enable Google Authenticator Button", enableGoogleAuthButton); - performClickActionWithRetry(deleteButton); + performClick(enableGoogleAuthButton); } /** @@ -198,18 +278,17 @@ public void enableGoogleAuthenticator(final String password) { final WebElement enableGoogleAuthButton = driver.findElement(By.id("Enable Google Authenticator")); assertNotNull("Expect to find a Enable Google Authenticator Button", enableGoogleAuthButton); - performClickActionWithRetry(enableGoogleAuthButton); + performClick(enableGoogleAuthButton); } /** * Find button. * - * @param buttonLabel - * the button label + * @param buttonLabel the button label * @return the web element */ public WebElement findButton(final String buttonLabel) { - final FluentWait wait = new WebDriverWait(driver, TestConstants.WAIT_FOR_PAGE_ELEMENT).pollingEvery(Duration.ofMillis(10)); + wait.until(helper.containsButton(buttonLabel)); for (final WebElement webElement : helper.getButtons()) { @@ -230,7 +309,7 @@ public WebElement findButton(final String buttonLabel) { * @return the web element */ private WebElement findClickable(final String id) { - final FluentWait wait = new WebDriverWait(driver, TestConstants.WAIT_FOR_PAGE_ELEMENT).pollingEvery(Duration.ofMillis(10)); + wait.pollingEvery(Duration.ofMillis(10)); wait.until(ExpectedConditions.elementToBeClickable(By.id(id))); @@ -240,8 +319,7 @@ private WebElement findClickable(final String id) { /** * Gets the action ids by. * - * @param action - * the action + * @param action the action * @return the action ids by */ public List getActionIdsBy(final ViewAction action) { @@ -256,7 +334,6 @@ public List getActionIdsBy(final ViewAction action) { return idList; } - /** * Gets the grid headers. * @@ -280,41 +357,6 @@ public List getGridRows() { } - -/** - * Click first row in grid. - * - * @param userPageVisit - * the user page visit - * @throws InterruptedException - * the interrupted exception - */ - protected final void clickFirstRowInGrid(final UserPageVisit userPageVisit) throws InterruptedException { - final List gridRows = userPageVisit.getGridRows(); - assertFalse(gridRows.isEmpty()); - - final WebElement choosenRow = gridRows.iterator().next(); - - final List cells = choosenRow.findElements(By.className("v-grid-cell")); - - final WebElement choosenCell = cells.iterator().next(); - - userPageVisit.performClickAction(choosenCell); - - } - - /** - * Login as admin. - * - * @throws Exception the exception - */ - public final void loginAsAdmin() throws Exception { - visitDirectPage( - new PageModeMenuCommand(CommonsViews.MAIN_VIEW_NAME, ApplicationPageMode.LOGIN.toString())); - loginUser(systemTestTargetAdminEmail, systemTestTargetAdminPassword); - } - - /** * Gets the html body as text. * @@ -353,8 +395,7 @@ public WebElement getMenuBar() { /** * Gets the menu item. * - * @param caption - * the caption + * @param caption the caption * @return the menu item */ @@ -365,12 +406,9 @@ public WebElement getMenuItem(final String... caption) { /** * Gets the menu item. * - * @param element - * the element - * @param level - * the level - * @param caption - * the caption + * @param element the element + * @param level the level + * @param caption the caption * @return the menu item */ WebElement getMenuItem(final WebElement element, final int level, final String... caption) { @@ -407,27 +445,32 @@ WebElement getMenuItem(final WebElement element, final int level, final String.. /** * Gets the menu item. * - * @param element - * the element - * @param caption - * the caption + * @param element the element + * @param caption the caption * @return the menu item */ public WebElement getMenuItem(final WebElement element, final String... caption) { - final FluentWait wait = new WebDriverWait(driver, TestConstants.WAIT_FOR_PAGE_ELEMENT).pollingEvery(Duration.ofMillis(10)); wait.until(helper.containsMenuItem(this, element, caption)); return getMenuItem(element, 1, caption); } + /** + * Login as admin. + * + * @throws Exception the exception + */ + public final void loginAsAdmin() throws Exception { + visitDirectPage(new PageModeMenuCommand(CommonsViews.MAIN_VIEW_NAME, ApplicationPageMode.LOGIN.toString())); + loginUser(systemTestTargetAdminEmail, systemTestTargetAdminPassword); + } + /** * Login user. * - * @param username - * the username - * @param password - * the password + * @param username the username + * @param password the password */ public void loginUser(final String username, final String password) { loginUserCheckView(username, password, UserViews.USERHOME_VIEW_NAME); @@ -438,7 +481,7 @@ public void loginUser(final String username, final String password) { * * @param username the username * @param password the password - * @param view the view + * @param view the view */ public void loginUserCheckView(final String username, final String password, final String view) { loginUserCheckView(username, password, null, view); @@ -447,10 +490,10 @@ public void loginUserCheckView(final String username, final String password, fin /** * Login user check view. * - * @param username the username - * @param password the password - * @param otpCode the otp code - * @param view the view + * @param username the username + * @param password the password + * @param otpCode the otp code + * @param view the view */ public void loginUserCheckView(final String username, final String password, final String otpCode, final String view) { @@ -465,11 +508,10 @@ public void loginUserCheckView(final String username, final String password, fin final WebElement loginButton = findButton("Login"); assertNotNull("Expect to find a Login Button", loginButton); - performClickActionWithRetry(loginButton); + performClick(loginButton); final String url = systemTestTargetUrl + "#!" + view; - final FluentWait wait = new WebDriverWait(driver, TestConstants.WAIT_FOR_PAGE_ELEMENT,(Duration.ofMillis(100))); wait.until(ExpectedConditions.urlContains(url)); assertEquals(url, driver.getCurrentUrl()); @@ -491,7 +533,6 @@ public void logoutUser() { final WebElement body = driver.findElement(By.tagName("body")); body.sendKeys(Keys.ESCAPE); - final FluentWait wait = new WebDriverWait(driver, TestConstants.WAIT_FOR_PAGE_ELEMENT).pollingEvery(Duration.ofMillis(10)); wait.until(helper.containsViewAction(ViewAction.VISIT_MAIN_VIEW)); wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.tagName("body"))); @@ -515,37 +556,31 @@ public void logoutUser() { cleanBrowser(); } - - - /** - * Clean browser. + * Perform click action with retry. + * + * @param element the element */ - private void cleanBrowser() { - if (driver != null) { - driver.manage().deleteAllCookies(); - driver.get("about:blank"); - } + // The public click methods needed by all the calls + public void performClick(WebElement clickElement) { + assertNotNull(clickElement); + clickHelper.performClick(clickElement); } - /** * Perform click action. * - * @param clickElement - * the click element + * @param clickElement the click element */ public void performClickAction(final WebElement clickElement) { - performClickActionWithRetry(clickElement); + performClick(clickElement); } /** * Register new user. * - * @param username - * the username - * @param password - * the password + * @param username the username + * @param password the password */ public void registerNewUser(final String username, final String password) { registerNewUserCheckView(username, password, UserViews.USERHOME_VIEW_NAME); @@ -554,12 +589,9 @@ public void registerNewUser(final String username, final String password) { /** * Register new user check view. * - * @param username - * the username - * @param password - * the password - * @param userView - * the user view + * @param username the username + * @param password the password + * @param userView the user view */ public void registerNewUserCheckView(final String username, final String password, final String userView) { @@ -568,7 +600,7 @@ public void registerNewUserCheckView(final String username, final String passwor setFieldValue("Register.country", "Sweden"); setFieldValue("Register.userpassword", password); - performClickActionWithRetry(findClickable("Register")); + performClick(findClickable("Register")); findButton("Logout"); @@ -581,26 +613,35 @@ public void registerNewUserCheckView(final String username, final String passwor /** * Search document. * - * @param search - * the search + * @param search the search */ public void searchDocument(final String search) { setFieldValue("Search.searchExpression", search); - performClickActionWithRetry(findClickable("Search")); + performClick(findClickable("Search")); final String url = systemTestTargetUrl + "#!" + UserViews.SEARCH_DOCUMENT_VIEW_NAME; - assertEquals(url, - driver.getCurrentUrl()); + assertEquals(url, driver.getCurrentUrl()); + + } + /** + * Select first grid row. + * + * @return the user page visit + */ + public UserPageVisit selectFirstGridRow() { + final WebElement firstRow = getGridRows().get(0); + clickHelper.performClick(firstRow); + return this; } /** * Send email on email page. * - * @param email the email + * @param email the email * @param subject the subject * @param content the content */ @@ -610,19 +651,17 @@ public void sendEmailOnEmailPage(final String email, final String subject, final setFieldValue("Email.subject", subject); setFieldValue("Email.content", content); - performClickActionWithRetry(findClickable("Email")); + performClick(findClickable("Email")); } /** * Sets the field value. * - * @param id - * the id - * @param value - * the value + * @param id the id + * @param value the value */ private void setFieldValue(final String id, final String value) { - final FluentWait wait = new WebDriverWait(driver, TestConstants.WAIT_FOR_PAGE_ELEMENT).pollingEvery(Duration.ofMillis(10)); + wait.until(ExpectedConditions.elementToBeClickable(By.id(id))); final WebElement findElement = driver.findElement(By.id(id)); @@ -633,30 +672,26 @@ private void setFieldValue(final String id, final String value) { /** * Update configuration property. * - * @param property - * the property - * @param value - * the value + * @param property the property + * @param value the value */ public void updateConfigurationProperty(final String property, final String value) { setFieldValue(property, value); final WebElement updateConfigButton = findButton("Update Configuration"); assertNotNull("Expect to find a Update Config Button", updateConfigButton); - performClickActionWithRetry(updateConfigButton); + performClick(updateConfigButton); } /** * Validate page. * - * @param page - * the page + * @param page the page */ public void validatePage(final PageModeMenuCommand page) { final String url = systemTestTargetUrl + "#!" + page.getPagePath(); - final FluentWait wait = new WebDriverWait(driver, TestConstants.WAIT_FOR_PAGE_ELEMENT).pollingEvery(Duration.ofMillis(10)); wait.until(helper.containsViewAction(ViewAction.VISIT_MAIN_VIEW)); final String text = getHtmlBodyAsText(); @@ -669,11 +704,26 @@ public void validatePage(final PageModeMenuCommand page) { } + /** + * Verify page content. + * + * @param expectedContent the expected content + * @return the user page visit + */ + public UserPageVisit verifyPageContent(String expectedContent) { + try { + assertTrue("Expected content: " + expectedContent + "\nNot in:\n " + getHtmlBodyAsText(), + checkHtmlBodyContainsText(expectedContent)); + return this; + } catch (final Exception e) { + throw new RuntimeException("Page content verification failed", e); + } + } + /** * Verify view actions. * - * @param viewActions - * the view actions + * @param viewActions the view actions */ public void verifyViewActions(final ViewAction[] viewActions) { final Set actionsAvailable = helper.getActionsAvailable(); @@ -686,18 +736,20 @@ public void verifyViewActions(final ViewAction[] viewActions) { /** * Visit direct page. * - * @param page - * the page + * @param page the page */ public void visitDirectPage(final PageModeMenuCommand page) { final String url = systemTestTargetUrl + "#!" + page.getPagePath(); driver.get(url); - action.pause(500L).perform(); - final FluentWait wait = new WebDriverWait(driver, TestConstants.WAIT_FOR_PAGE_ELEMENT).pollingEvery(Duration.ofMillis(10)); + wait.until(webDriver -> "complete" + .equals(((JavascriptExecutor) webDriver).executeScript("return document.readyState"))); + + wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.tagName("body"))); wait.until(helper.containsViewAction(ViewAction.VISIT_MAIN_VIEW)); + action.pause(TestConstants.CLICK_PAUSE_AFTER).build().perform(); final String text = getHtmlBodyAsText(); assertNotNull(text); assertFalse("Page contains exception, url:" + url, text.contains("Exception")); @@ -712,81 +764,30 @@ public void visitDirectPage(final PageModeMenuCommand page) { * Visit main view. */ public void visitMainView() { - final WebElement mainViewLink = driver.findElement(By - .id(ViewAction.VISIT_MAIN_VIEW.name())); - performClickActionWithRetry(mainViewLink); + final WebElement mainViewLink = driver.findElement(By.id(ViewAction.VISIT_MAIN_VIEW.name())); + performClick(mainViewLink); - verifyViewActions(new ViewAction[] { - ViewAction.VISIT_ADMIN_AGENT_OPERATION_VIEW, - ViewAction.VISIT_ADMIN_DATA_SUMMARY_VIEW, - ViewAction.VISIT_POLITICIAN_RANKING_VIEW, - ViewAction.VISIT_PARTY_RANKING_VIEW, - ViewAction.VISIT_MINISTRY_RANKING_VIEW, - ViewAction.VISIT_COMMITTEE_RANKING_VIEW, - ViewAction.VISIT_COUNTRY_VIEW }); + verifyViewActions(new ViewAction[] { ViewAction.VISIT_ADMIN_AGENT_OPERATION_VIEW, + ViewAction.VISIT_ADMIN_DATA_SUMMARY_VIEW, ViewAction.VISIT_POLITICIAN_RANKING_VIEW, + ViewAction.VISIT_PARTY_RANKING_VIEW, ViewAction.VISIT_MINISTRY_RANKING_VIEW, + ViewAction.VISIT_COMMITTEE_RANKING_VIEW, ViewAction.VISIT_COUNTRY_VIEW }); } - /** * Visit start page. */ public void visitStartPage() { driver.get(systemTestTargetUrl); - final FluentWait wait = new WebDriverWait(driver, TestConstants.WAIT_FOR_PAGE_ELEMENT).pollingEvery(Duration.ofMillis(10)); wait.until(helper.containsViewAction(ViewAction.VISIT_MAIN_VIEW)); - assertEquals(systemTestTargetUrl, - driver.getCurrentUrl()); + assertEquals(systemTestTargetUrl, driver.getCurrentUrl()); assertEquals("Citizen Intelligence Agency", driver.getTitle()); assertNotNull(driver.getWindowHandle()); - verifyViewActions(new ViewAction[] { - ViewAction.VISIT_ADMIN_AGENT_OPERATION_VIEW, - ViewAction.VISIT_ADMIN_DATA_SUMMARY_VIEW, - ViewAction.VISIT_POLITICIAN_RANKING_VIEW, - ViewAction.VISIT_PARTY_RANKING_VIEW, - ViewAction.VISIT_MINISTRY_RANKING_VIEW, - ViewAction.VISIT_COMMITTEE_RANKING_VIEW, - ViewAction.VISIT_COUNTRY_VIEW }); - } - - /** - * Verify page content. - * - * @param expectedContent the expected content - * @return the user page visit - */ - public UserPageVisit verifyPageContent(String expectedContent) { - try { - assertTrue("Expected content: " + expectedContent +"\nNot in:\n " + getHtmlBodyAsText(), - checkHtmlBodyContainsText(expectedContent)); - return this; - } catch (final Exception e) { - throw new RuntimeException("Page content verification failed", e); - } - } - - /** - * Select first grid row. - * - * @return the user page visit - */ - public UserPageVisit selectFirstGridRow() { - final WebElement firstRow = getGridRows().get(0); - performClickActionWithRetry(firstRow); - return this; - } - - - /** - * Perform click action with retry. - * - * @param element the element - */ - // The public click methods needed by all the calls - public void performClickActionWithRetry(WebElement clickElement) { - assertNotNull(clickElement); - clickHelper.clickWithRetry(clickElement); + verifyViewActions(new ViewAction[] { ViewAction.VISIT_ADMIN_AGENT_OPERATION_VIEW, + ViewAction.VISIT_ADMIN_DATA_SUMMARY_VIEW, ViewAction.VISIT_POLITICIAN_RANKING_VIEW, + ViewAction.VISIT_PARTY_RANKING_VIEW, ViewAction.VISIT_MINISTRY_RANKING_VIEW, + ViewAction.VISIT_COMMITTEE_RANKING_VIEW, ViewAction.VISIT_COUNTRY_VIEW }); } } diff --git a/citizen-intelligence-agency/src/test/java/com/hack23/cia/systemintegrationtest/ui/WebDriverFactory.java b/citizen-intelligence-agency/src/test/java/com/hack23/cia/systemintegrationtest/ui/WebDriverFactory.java index 0e521493a2..cbbb2be57d 100644 --- a/citizen-intelligence-agency/src/test/java/com/hack23/cia/systemintegrationtest/ui/WebDriverFactory.java +++ b/citizen-intelligence-agency/src/test/java/com/hack23/cia/systemintegrationtest/ui/WebDriverFactory.java @@ -1,23 +1,14 @@ package com.hack23.cia.systemintegrationtest.ui; -import java.time.Duration; - import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * A factory for creating WebDriver objects. */ public class WebDriverFactory { - /** The Constant LOG. */ - private static final Logger LOG = LoggerFactory.getLogger(WebDriverFactory.class); - - /** The Constant DEFAULT_TIMEOUT. */ - private static final Duration DEFAULT_TIMEOUT = Duration.ofSeconds(90); /** * Instantiates a new web driver factory. @@ -31,7 +22,6 @@ private WebDriverFactory() { * @return the web driver */ public static WebDriver createDriver() { - LOG.info("Creating WebDriver for browser"); final WebDriver driver = createChromeDriver(); configureDriver(driver); return driver; @@ -56,7 +46,7 @@ private static WebDriver createChromeDriver() { * @param driver the driver */ private static void configureDriver(WebDriver driver) { - driver.manage().timeouts().pageLoadTimeout(DEFAULT_TIMEOUT); - driver.manage().timeouts().scriptTimeout(DEFAULT_TIMEOUT); + driver.manage().timeouts().pageLoadTimeout(TestConstants.DEFAULT_BROWSER_TIMEOUT); + driver.manage().timeouts().scriptTimeout(TestConstants.DEFAULT_BROWSER_TIMEOUT); } } diff --git a/citizen-intelligence-agency/src/test/java/com/hack23/cia/systemintegrationtest/user/home/UserHomeTest.java b/citizen-intelligence-agency/src/test/java/com/hack23/cia/systemintegrationtest/user/home/UserHomeTest.java index 252486f06e..06d131b8b4 100644 --- a/citizen-intelligence-agency/src/test/java/com/hack23/cia/systemintegrationtest/user/home/UserHomeTest.java +++ b/citizen-intelligence-agency/src/test/java/com/hack23/cia/systemintegrationtest/user/home/UserHomeTest.java @@ -10,7 +10,6 @@ import com.hack23.cia.systemintegrationtest.AbstractUITest; import com.hack23.cia.systemintegrationtest.categories.IntegrationTest; import com.hack23.cia.systemintegrationtest.ui.TestUtils; -import com.hack23.cia.systemintegrationtest.ui.UserPageVisit; import com.hack23.cia.web.impl.ui.application.views.common.menufactory.api.MenuItemConstants; import com.hack23.cia.web.impl.ui.application.views.common.menufactory.api.PageCommandUserConstants; import com.hack23.cia.web.impl.ui.application.views.common.viewnames.ApplicationPageMode; @@ -47,7 +46,6 @@ public void siteLoginUserChangePasswordFailureTest() throws Exception { pageVisit.changePassword("wrong" + password,"new"+ password,"new" + password); pageVisit.checkNotificationMessage(ChangePasswordClickListener.PROBLEM_CHANGING_PASSWORD); - pageVisit.logoutUser(); } @@ -77,7 +75,6 @@ public void siteLoginUserChangePasswordTest() throws Exception { pageVisit.performClickAction(securitySettingMenuItem); pageVisit.changePassword(password,"new"+ password,"new" + password); - pageVisit.logoutUser(); } @@ -98,12 +95,6 @@ public void siteLoginUserCheckUserEventsTest() throws Exception { pageVisit.registerNewUser(username, password); - pageVisit.logoutUser(); - - pageVisit.visitDirectPage(PageCommandUserConstants.COMMAND_LOGIN); - - pageVisit.loginUser(username + "@test.com", password); - final WebElement useraccountMenuItem = pageVisit.getMenuItem(MenuItemConstants.USERACCOUNT); assertNotNull(useraccountMenuItem); @@ -112,7 +103,6 @@ public void siteLoginUserCheckUserEventsTest() throws Exception { final WebElement userEventsMenuItem = pageVisit.getMenuItem("User Events"); assertNotNull(userEventsMenuItem); pageVisit.performClickAction(userEventsMenuItem); - pageVisit.logoutUser(); } /** @@ -131,15 +121,6 @@ public void siteLoginUserCheckUserVisitsTest() throws Exception { pageVisit.registerNewUser(username, password); - pageVisit.logoutUser(); - - - pageVisit.visitDirectPage( - PageCommandUserConstants.COMMAND_LOGIN); - - pageVisit.loginUser(username + "@test.com", password); - - final WebElement useraccountMenuItem = pageVisit.getMenuItem(MenuItemConstants.USERACCOUNT); assertNotNull(useraccountMenuItem); pageVisit.performClickAction(useraccountMenuItem); @@ -147,7 +128,6 @@ public void siteLoginUserCheckUserVisitsTest() throws Exception { final WebElement userVisitsMenuItem = pageVisit.getMenuItem("User Visits"); assertNotNull(userVisitsMenuItem); pageVisit.performClickAction(userVisitsMenuItem); - pageVisit.logoutUser(); } @Test(timeout = DEFAULT_TIMEOUT) @@ -171,7 +151,6 @@ public void siteLoginUserDisableGoogleAuthenticatorFailureTest() throws Exceptio pageVisit.disableGoogleAuthenticator("wrong" + password); pageVisit.checkNotificationMessage("Problem disable google authenticatorError message"); - pageVisit.logoutUser(); } @Test(timeout = DEFAULT_TIMEOUT) @@ -195,8 +174,6 @@ public void siteLoginUserDisableGoogleAuthenticatorTest() throws Exception { pageVisit.performClickAction(securitySettingMenuItem); pageVisit.disableGoogleAuthenticator(password); - pageVisit.logoutUser(); - } @Test(timeout = DEFAULT_TIMEOUT) @@ -222,15 +199,13 @@ public void siteLoginUserEnableGoogleAuthenticatorFailedLoginNoOtpTest() throws pageVisit.closeModal(); - pageVisit.logoutUser(); - - final UserPageVisit failedLoginWrongMfaVisit = new UserPageVisit(driver); + pageVisit.cleanBrowser(); - failedLoginWrongMfaVisit.visitDirectPage(PageCommandUserConstants.COMMAND_LOGIN); + pageVisit.visitDirectPage(PageCommandUserConstants.COMMAND_LOGIN); - failedLoginWrongMfaVisit.loginUserCheckView(username + "@test.com", password,"123456","main/" + ApplicationPageMode.LOGIN); + pageVisit.loginUserCheckView(username + "@test.com", password,"123456","main/" + ApplicationPageMode.LOGIN); - failedLoginWrongMfaVisit.checkNotificationMessage("Login failed:" + LoginResponse.ErrorMessage.USERNAME_OR_PASSWORD_DO_NOT_MATCH); + pageVisit.checkNotificationMessage("Login failed:" + LoginResponse.ErrorMessage.USERNAME_OR_PASSWORD_DO_NOT_MATCH); } @Test(timeout = DEFAULT_TIMEOUT) @@ -254,14 +229,14 @@ public void siteLoginDeleteAccountTest() throws Exception { pageVisit.deleteAccount(password); - final UserPageVisit failedLoginUserDeletedVisit = new UserPageVisit(driver); + pageVisit.cleanBrowser(); - failedLoginUserDeletedVisit.visitDirectPage( + pageVisit.visitDirectPage( PageCommandUserConstants.COMMAND_LOGIN); - failedLoginUserDeletedVisit.loginUserCheckView(username + "@test.com", password,"123456","main/" + ApplicationPageMode.LOGIN); + pageVisit.loginUserCheckView(username + "@test.com", password,"123456","main/" + ApplicationPageMode.LOGIN); - failedLoginUserDeletedVisit.checkNotificationMessage("Login failed:" + LoginResponse.ErrorMessage.USERNAME_OR_PASSWORD_DO_NOT_MATCH); + pageVisit.checkNotificationMessage("Login failed:" + LoginResponse.ErrorMessage.USERNAME_OR_PASSWORD_DO_NOT_MATCH); } @Test(timeout = DEFAULT_TIMEOUT) diff --git a/citizen-intelligence-agency/src/test/resources/logback-test.xml b/citizen-intelligence-agency/src/test/resources/logback-test.xml index 63aae0db3d..aac088d9d7 100644 --- a/citizen-intelligence-agency/src/test/resources/logback-test.xml +++ b/citizen-intelligence-agency/src/test/resources/logback-test.xml @@ -25,11 +25,11 @@ - - + + - + diff --git a/parent-pom/pom.xml b/parent-pom/pom.xml index d137fc050f..44326e6642 100644 --- a/parent-pom/pom.xml +++ b/parent-pom/pom.xml @@ -164,7 +164,7 @@ 21 21 21 - --add-exports java.base/sun.nio.ch=ALL-UNNAMED + -XX:+EnableDynamicAgentLoading --add-exports java.base/sun.nio.ch=ALL-UNNAMED --add-exports java.base/jdk.internal.ref=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED @@ -1439,7 +1439,7 @@ 21 - --add-exports java.base/sun.nio.ch=ALL-UNNAMED + -XX:+EnableDynamicAgentLoading --add-exports java.base/sun.nio.ch=ALL-UNNAMED --add-exports java.base/jdk.internal.ref=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED