From 53cbbb2b9bf3063edfe5a754c3f463ee7f640eb0 Mon Sep 17 00:00:00 2001 From: Augusto Date: Fri, 2 Aug 2024 21:03:03 +0200 Subject: [PATCH] Removing Chrome and Firefox instance creation --- .../no_elastest/common/BaseLoggedTest.java | 46 +++++++------------ 1 file changed, 16 insertions(+), 30 deletions(-) diff --git a/src/test/java/com/fullteaching/e2e/no_elastest/common/BaseLoggedTest.java b/src/test/java/com/fullteaching/e2e/no_elastest/common/BaseLoggedTest.java index 02718ec..9964ef3 100644 --- a/src/test/java/com/fullteaching/e2e/no_elastest/common/BaseLoggedTest.java +++ b/src/test/java/com/fullteaching/e2e/no_elastest/common/BaseLoggedTest.java @@ -4,15 +4,11 @@ import com.fullteaching.e2e.no_elastest.common.exception.NotLoggedException; import com.fullteaching.e2e.no_elastest.utils.Click; import com.fullteaching.e2e.no_elastest.utils.Wait; -import io.github.bonigarcia.wdm.managers.ChromeDriverManager; -import io.github.bonigarcia.wdm.managers.FirefoxDriverManager; import org.junit.jupiter.api.*; import org.openqa.selenium.By; import org.openqa.selenium.TimeoutException; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; -import org.openqa.selenium.chrome.ChromeDriver; -import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.logging.LogEntries; import org.openqa.selenium.support.ui.ExpectedConditions; import org.slf4j.Logger; @@ -24,24 +20,17 @@ import java.util.Properties; import static com.fullteaching.e2e.no_elastest.common.Constants.*; -import static java.lang.invoke.MethodHandles.lookup; import static org.openqa.selenium.logging.LogType.BROWSER; -import static org.slf4j.LoggerFactory.getLogger; public class BaseLoggedTest { public static final String CHROME = "chrome"; - // For use another host - //protected static final String host= SetUp.getHost(); public static final String FIREFOX = "firefox"; public static final String EDGE = "edge"; public static final Logger log = LoggerFactory.getLogger(BaseLoggedTest.class); - protected static final Class chrome = ChromeDriver.class; - protected static final Class firefox = FirefoxDriver.class; public static String TEACHER_BROWSER; public static String STUDENT_BROWSER; public static String BROWSER_NAME; - public static String course_title; protected static String HOST = LOCALHOST; protected static String userName; protected static String userMail; @@ -66,14 +55,7 @@ static void setupAll() { // 28 lines // Load a properties file for reading properties.load(new FileInputStream("src/test/resources/inputs/test.properties")); } catch (IOException ex) { - ex.printStackTrace(); // Consider logging the exception instead of printing the stack trace - } - - // Check if running outside ElasTest - if (System.getenv("ET_EUS_API") == null) { - // Setup drivers for Chrome and Firefox - ChromeDriverManager.getInstance(chrome).setup(); - FirefoxDriverManager.getInstance(firefox).setup(); + log.error("The properties file could not be loaded"); } String envUrl = System.getProperty("SUT_URL") != null ? System.getProperty("SUT_URL") : System.getenv("SUT_URL"); @@ -85,7 +67,7 @@ static void setupAll() { // 28 lines TJOB_NAME = envTJobName; PORT = envPort; APP_URL = envUrl + TJOB_NAME + ":" + PORT + "/"; - log.debug("The URL is" + APP_URL); + log.debug("The URL is {}", APP_URL); HOST = APP_URL; } else { // Check if app.url system property is defined @@ -113,7 +95,7 @@ void setup(TestInfo info) { //65 lines if (info.getTestMethod().isPresent()) { TEST_NAME = info.getTestMethod().get().getName(); } - log.info("##### Start test: " + TEST_NAME); + log.info("##### Start test: {}", TEST_NAME); TJOB_NAME = System.getProperty("dirtarget"); user = setupBrowser("chrome", TJOB_NAME + "_" + TEST_NAME, userMail, WAIT_SECONDS); @@ -163,10 +145,10 @@ protected BrowserUser setupBrowser(String browser, String testName, void tearDown(TestInfo testInfo) { //13 lines if (user != null) { - log.info("##### Finish test: {} - Driver {}", TEST_NAME, this.user.getDriver()); + log.info("##### Finish test: {} - Driver {}", testInfo.getDisplayName(), this.user.getDriver()); log.info("Browser console at the end of the test"); LogEntries logEntries = user.getDriver().manage().logs().get(BROWSER); - logEntries.forEach((entry) -> log.info("[{}] {} {}", + logEntries.forEach(entry -> log.info("[{}] {} {}", new Date(entry.getTimestamp()), entry.getLevel(), entry.getMessage())); if (user.isOnSession()) { @@ -225,7 +207,12 @@ private void login(BrowserUser user, String userEmail, String userPass, userName = getUserName(user, true, APP_URL); } catch (NotLoggedException | ElementNotFoundException e) { // TODO Auto-generated catch block - e.printStackTrace(); + if(e.getClass().isInstance(NotLoggedException.class)){ + log.error("The user was not able to be logged in, more [INFO] {} [INFO]",e.getMessage()); + } + else{ + log.error("The web element was not found,[INFO]:{} [INFO]",e.getMessage()); + } } log.info("Logging in successful for user {}", user.getClientData()); @@ -233,10 +220,9 @@ private void login(BrowserUser user, String userEmail, String userPass, } protected void logout(BrowserUser user) { //43 lines - // log.info("Logging out {}", user.getClientData()); + log.info("Logging out {}", user.getClientData()); - if (user.getDriver().findElements(By.cssSelector("#fixed-icon")) - .size() > 0) { + if (!user.getDriver().findElements(By.cssSelector("#fixed-icon")).isEmpty()) { // Get out of video session page if (!isClickable("#exit-icon", user)) { // Side menu not opened user.getDriver().findElement(By.cssSelector("#fixed-icon")) @@ -347,7 +333,7 @@ protected void waitSeconds(int seconds) { try { Thread.sleep(1000L * seconds); } catch (InterruptedException e) { - e.printStackTrace(); + log.error("Interrupted exception during the waiting with the Thread.sleep"); } } @@ -372,14 +358,14 @@ public String getUserName(BrowserUser user, boolean goBack, String host) throws WebElement name_placeholder = Wait.notTooMuch(user.getDriver()).until(ExpectedConditions.visibilityOfElementLocated(By.xpath(USERNAME_XPATH))); - String userName = name_placeholder.getText().trim(); + String userPlaceHolderName = name_placeholder.getText().trim(); if (goBack) { user.getDriver().navigate().back(); } //Check if the username is the expected log.info("[END] getUserName"); - return userName; + return userPlaceHolderName; }