Skip to content

Commit

Permalink
Dealing with zombie processes
Browse files Browse the repository at this point in the history
  • Loading branch information
augustocristian committed Aug 16, 2024
1 parent 585d403 commit cb2e484
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import java.io.FileInputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.util.Date;
import java.util.List;
import java.util.Properties;
Expand Down Expand Up @@ -107,18 +109,18 @@ static void setupAll() { // 28 lines
}

@BeforeEach
void setup(TestInfo info) { //65 lines
void setup(TestInfo info) throws URISyntaxException, MalformedURLException { //65 lines
log.info("##### Start test: {}" , info.getTestMethod().get().getName());
TJOB_NAME = System.getProperty("dirtarget");

teacher = setupBrowser("chrome", TJOB_NAME + "_" + info.getTestMethod().get().getName(), "Teacher", WAIT_SECONDS);
this.teacher = setupBrowser("chrome", TJOB_NAME + "_" + info.getTestMethod().get().getName(), "Teacher", WAIT_SECONDS);

driver = teacher.getDriver();
this.driver = this.teacher.getDriver();

}

protected BrowserUser setupBrowser(String browser, String testName,
String userIdentifier, int secondsOfWait) {
String userIdentifier, int secondsOfWait) throws URISyntaxException, MalformedURLException {
BrowserUser u;
log.info("Starting browser ({})", browser);

Expand Down Expand Up @@ -179,7 +181,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);
}
Expand Down Expand Up @@ -243,8 +244,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());
Expand Down Expand Up @@ -327,7 +331,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
Expand All @@ -339,7 +343,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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@

import java.time.Duration;

import static java.lang.invoke.MethodHandles.lookup;
import static org.slf4j.LoggerFactory.getLogger;

public class BrowserUser {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
import org.openqa.selenium.support.ui.WebDriverWait;

import java.net.MalformedURLException;
import java.net.URL;
import java.net.URI;
import java.net.URISyntaxException;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.time.LocalDateTime;
Expand All @@ -41,7 +42,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 URISyntaxException, MalformedURLException {
super(userName, timeOfWaitInSeconds);
log.info("Starting the configuration of the web browser");
log.debug(String.format("The Test name is: %s", testName));
Expand All @@ -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<String, Object> selenoidOptions = new HashMap<>();
log.info("Using the remote WebDriver (Selenoid)");
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd_HH:mm");
Expand All @@ -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);
Expand All @@ -97,13 +96,10 @@ public ChromeUser(String userName, int timeOfWaitInSeconds, String testName, Str

//END CAPABILITIES FOR SELENOID RETORCH
log.debug("Configuring the remote WebDriver ");
RemoteWebDriver remote = new RemoteWebDriver(new URL("http://selenoid:4444/wd/hub"), options);
RemoteWebDriver remote = new RemoteWebDriver(new URI("http://selenoid:4444/wd/hub").toURL(), options);
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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
import org.openqa.selenium.support.ui.WebDriverWait;

import java.net.MalformedURLException;
import java.net.URL;
import java.net.URI;
import java.net.URISyntaxException;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.time.LocalDateTime;
Expand All @@ -36,7 +37,7 @@
public class EdgeUser extends BrowserUser {
EdgeOptions options = new EdgeOptions();

public EdgeUser(String userName, int timeOfWaitInSeconds, String testName, String userIdentifier) {
public EdgeUser(String userName, int timeOfWaitInSeconds, String testName, String userIdentifier) throws URISyntaxException {
super(userName, timeOfWaitInSeconds);
log.info(String.format("The Test names are: %s", testName));

Expand Down Expand Up @@ -67,7 +68,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);
Expand All @@ -79,7 +80,7 @@ public EdgeUser(String userName, int timeOfWaitInSeconds, String testName, Strin

//END CAPABILITIES FOR SELENOID RETORCH

RemoteWebDriver remote = new RemoteWebDriver(new URL(eusApiURL), options);
RemoteWebDriver remote = new RemoteWebDriver(new URI(eusApiURL).toURL(), options);
remote.setFileDetector(new LocalFileDetector());


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
import org.openqa.selenium.remote.RemoteWebDriver;

import java.net.MalformedURLException;
import java.net.URL;
import java.net.URI;
import java.net.URISyntaxException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
Expand All @@ -35,7 +36,7 @@
public class FirefoxUser extends BrowserUser {
FirefoxOptions options = new FirefoxOptions();

public FirefoxUser(String userName, int timeOfWaitInSeconds, String testName, String userIdentifier) {
public FirefoxUser(String userName, int timeOfWaitInSeconds, String testName, String userIdentifier) throws URISyntaxException {
super(userName, timeOfWaitInSeconds);
//TO-DO Firefox configuration has changed, review it.
FirefoxProfile profile = new FirefoxProfile();
Expand Down Expand Up @@ -74,8 +75,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);
Expand All @@ -86,7 +86,7 @@ public FirefoxUser(String userName, int timeOfWaitInSeconds, String testName, St

//END CAPABILITIES FOR SELENOID RETORCH

RemoteWebDriver remote = new RemoteWebDriver(new URL(eusApiURL), options);
RemoteWebDriver remote = new RemoteWebDriver(new URI(eusApiURL).toURL(), options);
remote.setFileDetector(new LocalFileDetector());


Expand All @@ -99,7 +99,6 @@ public FirefoxUser(String userName, int timeOfWaitInSeconds, String testName, St
}
}

//this.driver.manage().timeouts().setScriptTimeout(this.timeOfWaitInSeconds, TimeUnit.SECONDS);

this.configureDriver();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
import java.util.List;

import static com.fullteaching.e2e.no_elastest.common.Constants.*;
import static java.lang.invoke.MethodHandles.lookup;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.slf4j.LoggerFactory.getLogger;


public class ForumNavigationUtilities {
Expand Down Expand Up @@ -72,7 +70,7 @@ public static WebElement getEntry(WebDriver wd, String entry_name) throws Elemen
try {
WebElement title = entry.findElement(FORUM_ENTRY_LIST_ENTRY_TITLE);
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 (entry_name.equals(title_text)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ public static List<WebElement> getPageLinks(WebDriver wd) { //29 lines
List<WebElement> 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;
}
Expand All @@ -54,10 +53,8 @@ public static List<WebElement> getUnexploredPageLinks(WebDriver wd, Map<String,
List<WebElement> 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;
}
Expand Down Expand Up @@ -102,20 +99,18 @@ private static boolean isContainedIn(String href, Set<String> set) { // 8lines
}

public static Set<String> addNonExistentLink(Set<String> 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<String> discardExplored(List<String> new_links, Set<String> explored) { //8 lines
List<String> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import org.openqa.selenium.support.ui.ExpectedConditions;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.util.List;
import java.util.stream.Stream;

Expand Down Expand Up @@ -65,7 +67,7 @@ public static Stream<Arguments> 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 URISyntaxException, MalformedURLException { //197 Lines of code
int numberpriormessages;

// TEACHER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
Expand Down Expand Up @@ -62,7 +63,7 @@ public static Stream<Arguments> data() throws IOException {
@DisplayName("sessionTest")
@ParameterizedTest
@MethodSource("data")
void sessionTest(String mail, String password, String role) throws ElementNotFoundException, IOException {
void sessionTest(String mail, String password, String role) throws ElementNotFoundException, IOException, URISyntaxException {
String sessionName = "Today's Session";
courseName = "Pseudoscientific course for treating the evil eye";
this.slowLogin(this.teacher, mail, password);
Expand All @@ -80,7 +81,7 @@ void sessionTest(String mail, String password, String role) throws ElementNotFou
* @param pathData the path to the CSV file containing student data
* @throws IOException if there is an error reading the file
*/
private void initializeStudents(String pathData) throws IOException {
private void initializeStudents(String pathData) throws IOException, URISyntaxException {
log.info("Initializing students");
String users_data = loadStudentsData(pathData);
studentNameList = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import org.openqa.selenium.support.ui.ExpectedConditions;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.util.stream.Stream;


Expand Down Expand Up @@ -62,7 +64,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 URISyntaxException, MalformedURLException { //124+ 232+ 20 set up +8 lines teardown = 564

// TEACHER
this.slowLogin(teacher, mail, password);//24
Expand Down

0 comments on commit cb2e484

Please sign in to comment.