Skip to content

Commit

Permalink
test cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pethers committed Jan 21, 2025
1 parent 45842c7 commit bc45e07
Show file tree
Hide file tree
Showing 12 changed files with 438 additions and 567 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
Expand All @@ -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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public abstract class AbstractAdminTest extends AbstractUITest {
*/
@Before
public void adminSetup() throws Exception {
pageVisit.cleanBrowser();
pageVisit.loginAsAdmin();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
}
}
}
}
}

}
}

This file was deleted.

Loading

0 comments on commit bc45e07

Please sign in to comment.