From bf9f4ace9d71c3d46b316424ceefbd465b7e396d Mon Sep 17 00:00:00 2001 From: Augusto Date: Sat, 17 Aug 2024 00:17:03 +0200 Subject: [PATCH] Dealing with zombie processes --- .../no_elastest/common/BaseLoggedTest.java | 17 ++++++++------- .../e2e/no_elastest/common/BrowserUser.java | 2 -- .../e2e/no_elastest/common/ChromeUser.java | 12 ++++------- .../e2e/no_elastest/common/EdgeUser.java | 2 +- .../e2e/no_elastest/common/FirefoxUser.java | 4 +--- .../common/NavigationUtilities.java | 2 -- .../common/SessionNavigationUtilities.java | 2 +- .../no_elastest/common/SpiderNavigation.java | 21 +++++++------------ .../e2e/no_elastest/common/UserUtilities.java | 2 -- .../media/FullTeachingEndToEndEChatTests.java | 3 ++- ...TeachingTestEndToEndVideoSessionTests.java | 3 ++- 11 files changed, 29 insertions(+), 41 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 9863d0e..499dc27 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 @@ -20,6 +20,7 @@ import java.io.FileInputStream; import java.io.IOException; +import java.net.MalformedURLException; import java.util.Date; import java.util.List; import java.util.Properties; @@ -107,7 +108,7 @@ static void setupAll() { // 28 lines } @BeforeEach - void setup(TestInfo info) { //65 lines + void setup(TestInfo info) throws MalformedURLException { //65 lines log.info("##### Start test: {}" , info.getTestMethod().get().getName()); TJOB_NAME = System.getProperty("dirtarget"); @@ -118,7 +119,7 @@ void setup(TestInfo info) { //65 lines } protected BrowserUser setupBrowser(String browser, String testName, - String userIdentifier, int secondsOfWait) { + String userIdentifier, int secondsOfWait) throws MalformedURLException { BrowserUser u; log.info("Starting browser ({})", browser); @@ -179,7 +180,6 @@ void tearDown(TestInfo info) { //13 lines logEntries.forEach(entry -> log.info("[{}] {} {}", new Date(entry.getTimestamp()), entry.getLevel(), entry.getMessage())); - //TO-DO- ERROR with the logout if (this.student.isOnSession()) { this.logout(student); } @@ -243,8 +243,11 @@ private void login(BrowserUser user, String userEmail, String userPass, try { 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 logged",user.getClientData());} + else{ + log.error("The userName field not found" ); + } } log.info("Logging in successful for user {}", user.getClientData()); @@ -327,7 +330,7 @@ protected void openDialog(String cssSelector, BrowserUser user) { "//div[contains(@class, 'modal-overlay') and contains(@style, 'opacity: 0.5')]")), "Dialog not opened"); - log.info("Dialog opened for user {}", user.getClientData()); + log.info("Dialog opened using css selector for user {}", user.getClientData()); } protected void openDialog(WebElement el, BrowserUser user) {//8lines @@ -339,7 +342,7 @@ protected void openDialog(WebElement el, BrowserUser user) {//8lines user.waitUntil(ExpectedConditions.presenceOfElementLocated(By.xpath( "//div[contains(@class, 'modal-overlay') and contains(@style, 'opacity: 0.5')]")), "Dialog not opened"); - log.info("Dialog opened for user {}", user.getClientData()); + log.info("Dialog using webelement for user {}", user.getClientData()); } protected void waitForDialogClosed(String dialogId, String errorMessage, diff --git a/src/test/java/com/fullteaching/e2e/no_elastest/common/BrowserUser.java b/src/test/java/com/fullteaching/e2e/no_elastest/common/BrowserUser.java index 7c23457..3be0dd4 100644 --- a/src/test/java/com/fullteaching/e2e/no_elastest/common/BrowserUser.java +++ b/src/test/java/com/fullteaching/e2e/no_elastest/common/BrowserUser.java @@ -26,8 +26,6 @@ import java.time.Duration; -import static java.lang.invoke.MethodHandles.lookup; -import static org.slf4j.LoggerFactory.getLogger; public class BrowserUser { diff --git a/src/test/java/com/fullteaching/e2e/no_elastest/common/ChromeUser.java b/src/test/java/com/fullteaching/e2e/no_elastest/common/ChromeUser.java index e9d8f27..3d5f75a 100644 --- a/src/test/java/com/fullteaching/e2e/no_elastest/common/ChromeUser.java +++ b/src/test/java/com/fullteaching/e2e/no_elastest/common/ChromeUser.java @@ -41,7 +41,7 @@ public class ChromeUser extends BrowserUser { ChromeOptions options = new ChromeOptions(); - public ChromeUser(String userName, int timeOfWaitInSeconds, String testName, String userIdentifier) { + public ChromeUser(String userName, int timeOfWaitInSeconds, String testName, String userIdentifier) throws MalformedURLException { super(userName, timeOfWaitInSeconds); log.info("Starting the configuration of the web browser"); log.debug(String.format("The Test name is: %s", testName)); @@ -52,7 +52,8 @@ public ChromeUser(String userName, int timeOfWaitInSeconds, String testName, Str //Problems with the max attempt of retry, solved with : https://github.com/aerokube/selenoid/issues/1124 solved with --disable-gpu //Problems with flakiness due to screen resolution solved with --start-maximized - String[] arguments = {"--start-maximized"}; + // --no-zygote deals with the creation of zombie processes + String[] arguments = {"--start-maximized","--no-zygote"}; log.debug("Adding the arguments ({})", Arrays.toString(arguments)); for (String argument : arguments @@ -68,8 +69,6 @@ public ChromeUser(String userName, int timeOfWaitInSeconds, String testName, Str log.info("Using the Local WebDriver ()"); this.driver = new ChromeDriver(options); } else { - try { - Map selenoidOptions = new HashMap<>(); log.info("Using the remote WebDriver (Selenoid)"); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd_HH:mm"); @@ -85,7 +84,7 @@ public ChromeUser(String userName, int timeOfWaitInSeconds, String testName, Str LocalDateTime now = LocalDateTime.now(); String logName = System.getProperty("tjob_name") + "-" + dtf.format(now) + "-" + testName + "-" + userIdentifier + ".log"; String videoName = System.getProperty("tjob_name") + "-" + dtf.format(now) + "-" + testName + "-" + userIdentifier + ".mp4"; - log.debug("The data of this test would be stored into: video name " + videoName + " and the log is " + logName); + log.debug("The data of this test would be stored into: video name: {} and the log name: {} " , videoName,logName); selenoidOptions.put("enableLog", true); selenoidOptions.put("logName ", logName); @@ -101,9 +100,6 @@ public ChromeUser(String userName, int timeOfWaitInSeconds, String testName, Str log.debug("Configuring the Local File Detector"); remote.setFileDetector(new LocalFileDetector()); this.driver = remote; - } catch (MalformedURLException e) { - throw new RuntimeException("Exception creating eusApiURL", e); - } } log.debug("Configure the driver connection timeouts at ({})", this.timeOfWaitInSeconds); new WebDriverWait(driver, Duration.ofSeconds(this.timeOfWaitInSeconds)); diff --git a/src/test/java/com/fullteaching/e2e/no_elastest/common/EdgeUser.java b/src/test/java/com/fullteaching/e2e/no_elastest/common/EdgeUser.java index 11a7811..5a8736e 100644 --- a/src/test/java/com/fullteaching/e2e/no_elastest/common/EdgeUser.java +++ b/src/test/java/com/fullteaching/e2e/no_elastest/common/EdgeUser.java @@ -67,7 +67,7 @@ public EdgeUser(String userName, int timeOfWaitInSeconds, String testName, Strin LocalDateTime now = LocalDateTime.now(); String logName = dtf.format(now) + "-" + testName + "-" + userIdentifier + ".log"; String videoName = dtf.format(now) + "_" + testName + "_" + userIdentifier + ".mp4"; - log.debug("The data of this test would be stored into: video name " + videoName + " and the log is " + logName); + log.debug("The data of this test would be stored into: video name {} and the log is {}", videoName,logName); selenoidOptions.put("enableLog", true); selenoidOptions.put("logName ", logName); diff --git a/src/test/java/com/fullteaching/e2e/no_elastest/common/FirefoxUser.java b/src/test/java/com/fullteaching/e2e/no_elastest/common/FirefoxUser.java index e8a9fc3..041a1b8 100644 --- a/src/test/java/com/fullteaching/e2e/no_elastest/common/FirefoxUser.java +++ b/src/test/java/com/fullteaching/e2e/no_elastest/common/FirefoxUser.java @@ -74,8 +74,7 @@ public FirefoxUser(String userName, int timeOfWaitInSeconds, String testName, St LocalDateTime now = LocalDateTime.now(); String logName = dtf.format(now) + "-" + testName + "-" + userIdentifier + ".log"; String videoName = dtf.format(now) + "_" + testName + "_" + userIdentifier + ".mp4"; - log.debug("The data of this test would be stored into: video name " + videoName + " and the log is " + logName); - + log.debug("The data of this test would be stored into: video name {} and the log is {}", videoName,logName); selenoidOptions.put("enableLog", true); selenoidOptions.put("logName ", logName); selenoidOptions.put("videoName", videoName); @@ -99,7 +98,6 @@ public FirefoxUser(String userName, int timeOfWaitInSeconds, String testName, St } } - //this.driver.manage().timeouts().setScriptTimeout(this.timeOfWaitInSeconds, TimeUnit.SECONDS); this.configureDriver(); } diff --git a/src/test/java/com/fullteaching/e2e/no_elastest/common/NavigationUtilities.java b/src/test/java/com/fullteaching/e2e/no_elastest/common/NavigationUtilities.java index 9e8c469..e0464f6 100644 --- a/src/test/java/com/fullteaching/e2e/no_elastest/common/NavigationUtilities.java +++ b/src/test/java/com/fullteaching/e2e/no_elastest/common/NavigationUtilities.java @@ -13,8 +13,6 @@ import static com.fullteaching.e2e.no_elastest.common.BaseLoggedTest.HOST; import static com.fullteaching.e2e.no_elastest.common.Constants.*; -import static java.lang.invoke.MethodHandles.lookup; -import static org.slf4j.LoggerFactory.getLogger; public class NavigationUtilities { diff --git a/src/test/java/com/fullteaching/e2e/no_elastest/common/SessionNavigationUtilities.java b/src/test/java/com/fullteaching/e2e/no_elastest/common/SessionNavigationUtilities.java index 97bb89a..c5afdb3 100644 --- a/src/test/java/com/fullteaching/e2e/no_elastest/common/SessionNavigationUtilities.java +++ b/src/test/java/com/fullteaching/e2e/no_elastest/common/SessionNavigationUtilities.java @@ -29,7 +29,7 @@ public static WebElement getSession(WebDriver wd, String session_name) throws El try { WebElement title = session.findElement(SESSION_LIST_SESSION_NAME); String title_text = title.getText(); - if (title_text == null || title_text.equals("")) { + if (title_text == null || title_text.isEmpty()) { title_text = title.getAttribute("innerHTML"); } if (session_name.equals(title_text)) { diff --git a/src/test/java/com/fullteaching/e2e/no_elastest/common/SpiderNavigation.java b/src/test/java/com/fullteaching/e2e/no_elastest/common/SpiderNavigation.java index ee8dfaf..9a342f8 100644 --- a/src/test/java/com/fullteaching/e2e/no_elastest/common/SpiderNavigation.java +++ b/src/test/java/com/fullteaching/e2e/no_elastest/common/SpiderNavigation.java @@ -35,10 +35,9 @@ public static List getPageLinks(WebDriver wd) { //29 lines List a_lst = wd.findElements(By.tagName("a")); for (WebElement a : a_lst) { String href = a.getAttribute("href"); - if ((href != null) && (!href.trim().equals("")) && (!href.contains("#"))) { - if (isContainedIn(href.trim(), links_href) && href.contains(host)) + if ((href != null) && (!href.trim().isEmpty()) && (!href.contains("#")) && isContainedIn(href.trim(), links_href) && href.contains(host)) links.add(a); - } + } return links; } @@ -54,10 +53,8 @@ public static List getUnexploredPageLinks(WebDriver wd, Map allLinks = getPageLinks(wd); for (WebElement a : allLinks) { String href = a.getAttribute("href"); - if ((href != null) && (!href.trim().equals("")) && (!href.contains("#"))) { - if (isContainedIn(href.trim(), explored.keySet()) && href.contains(host)) //8lines - links.add(a); - } + if ((href != null) && (!href.trim().isEmpty()) && (!href.contains("#")) && isContainedIn(href.trim(), explored.keySet()) && href.contains(host)) + links.add(a); } return links; } @@ -102,20 +99,18 @@ private static boolean isContainedIn(String href, Set set) { // 8lines } public static Set addNonExistentLink(Set original, String href) { //5lines - if ((href != null) && (!href.equals("")) && (!href.contains("#"))) { - if (isContainedIn(href, original) && href.contains(host)) + if ((href != null) && (!href.isEmpty()) && (!href.contains("#")) && isContainedIn(href, original) && href.contains(host)) original.add(href); - } + return original; } public static List discardExplored(List new_links, Set explored) { //8 lines List withOutExplored = new ArrayList<>(); for (String href : new_links) { - if ((href != null) && (!href.equals("")) && (!href.contains("#"))) { - if (isContainedIn(href, explored) && href.contains(host)) + if ((href != null) && (!href.isEmpty()) && (!href.contains("#")) && isContainedIn(href, explored) && href.contains(host)) withOutExplored.add(href); - } + } return withOutExplored; } diff --git a/src/test/java/com/fullteaching/e2e/no_elastest/common/UserUtilities.java b/src/test/java/com/fullteaching/e2e/no_elastest/common/UserUtilities.java index 2addef3..5a3d84d 100644 --- a/src/test/java/com/fullteaching/e2e/no_elastest/common/UserUtilities.java +++ b/src/test/java/com/fullteaching/e2e/no_elastest/common/UserUtilities.java @@ -14,8 +14,6 @@ import org.slf4j.LoggerFactory; import static com.fullteaching.e2e.no_elastest.common.Constants.*; -import static java.lang.invoke.MethodHandles.lookup; -import static org.slf4j.LoggerFactory.getLogger; public class UserUtilities { diff --git a/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/media/FullTeachingEndToEndEChatTests.java b/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/media/FullTeachingEndToEndEChatTests.java index b53b7cf..0c973f8 100644 --- a/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/media/FullTeachingEndToEndEChatTests.java +++ b/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/media/FullTeachingEndToEndEChatTests.java @@ -31,6 +31,7 @@ import org.openqa.selenium.support.ui.ExpectedConditions; import java.io.IOException; +import java.net.MalformedURLException; import java.util.List; import java.util.stream.Stream; @@ -65,7 +66,7 @@ public static Stream data() throws IOException { @ParameterizedTest @MethodSource("data") @Tag("Multiuser Test") - void oneToOneChatInSessionChrome(String mail, String password, String role ) { //197 Lines of code + void oneToOneChatInSessionChrome(String mail, String password, String role ) throws MalformedURLException { //197 Lines of code int numberpriormessages; // TEACHER diff --git a/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/media/FullTeachingTestEndToEndVideoSessionTests.java b/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/media/FullTeachingTestEndToEndVideoSessionTests.java index 51690ac..d43d36f 100644 --- a/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/media/FullTeachingTestEndToEndVideoSessionTests.java +++ b/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/media/FullTeachingTestEndToEndVideoSessionTests.java @@ -31,6 +31,7 @@ import org.openqa.selenium.support.ui.ExpectedConditions; import java.io.IOException; +import java.net.MalformedURLException; import java.util.stream.Stream; @@ -62,7 +63,7 @@ public FullTeachingTestEndToEndVideoSessionTests() { @DisplayName("sessionTest") @ParameterizedTest @MethodSource("data") - void oneToOneVideoAudioSessionChrome(String mail, String password, String role) { //124+ 232+ 20 set up +8 lines teardown = 564 + void oneToOneVideoAudioSessionChrome(String mail, String password, String role) throws MalformedURLException { //124+ 232+ 20 set up +8 lines teardown = 564 // TEACHER this.slowLogin(teacher, mail, password);//24