Skip to content

Commit

Permalink
Fixing the ReplyToCommentTest
Browse files Browse the repository at this point in the history
  • Loading branch information
augustocristian committed Aug 18, 2024
1 parent b277862 commit 612b3fe
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 121 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,17 @@ static void setupAll() { // 28 lines
}

@BeforeEach
void setup(TestInfo info) throws URISyntaxException, MalformedURLException { //65 lines
log.info("##### Start test: {}" , info.getTestMethod().get().getName());
void setup(TestInfo info) throws URISyntaxException, MalformedURLException {
if (info.getTestMethod().isPresent()) {
TEST_NAME = info.getTestMethod().get().getName();
userName=info.getDisplayName().split(",")[2];
}
log.info("##### Start test: {}" , TEST_NAME);
TJOB_NAME = System.getProperty("dirtarget");

this.user = setupBrowser("chrome", TJOB_NAME + "_" + info.getTestMethod().get().getName(), "Teacher", WAIT_SECONDS);
this.user = setupBrowser("chrome", TJOB_NAME + "-" +TEST_NAME, userName, WAIT_SECONDS);

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

}

protected BrowserUser setupBrowser(String browser, String testName,
Expand All @@ -127,19 +130,16 @@ protected BrowserUser setupBrowser(String browser, String testName,
switch (browser) {
case FIREFOX:
BROWSER_NAME = FIREFOX;
u = new FirefoxUser(userIdentifier, secondsOfWait, testName,
userIdentifier);
u = new FirefoxUser(userIdentifier, secondsOfWait, testName);
break;
case EDGE:
BROWSER_NAME = EDGE;
u = new EdgeUser(userIdentifier, secondsOfWait, testName,
userIdentifier);
u = new EdgeUser(userIdentifier, secondsOfWait, testName);
break;

default:
BROWSER_NAME = CHROME;
u = new ChromeUser(userIdentifier, secondsOfWait, testName,
userIdentifier);
u = new ChromeUser(userIdentifier, secondsOfWait, testName);
}

log.info("Navigating to {}", APP_URL);
Expand All @@ -159,9 +159,9 @@ protected BrowserUser setupBrowser(String browser, String testName,
}

@AfterEach
void tearDown(TestInfo info) { //13 lines
void tearDown() { //13 lines
if (this.user != null) {
log.info("##### Finish test: {} - Driver {}", info.getTestMethod().get().getName(), this.user.getDriver());
log.info("##### Finish test: {} - Driver {}", TEST_NAME, 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("[{}] {} {}",
Expand All @@ -175,7 +175,7 @@ void tearDown(TestInfo info) { //13 lines
}

if (this.student != null) {
log.info("##### Finish test: {} - Driver {}", info.getTestMethod().get().getName(), this.student.getDriver());
log.info("##### Finish test: {} - Driver {}",TEST_NAME, this.student.getDriver());
log.info("Browser console at the end of the test");
LogEntries logEntries = student.getDriver().manage().logs().get(BROWSER);
logEntries.forEach(entry -> log.info("[{}] {} {}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,9 @@
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -42,10 +39,9 @@
public class ChromeUser extends BrowserUser {
ChromeOptions options = new ChromeOptions();

public ChromeUser(String userName, int timeOfWaitInSeconds, String testName, String userIdentifier) throws URISyntaxException, MalformedURLException {
super(userName, timeOfWaitInSeconds);
public ChromeUser(String userIdentifier, int timeOfWaitInSeconds, String testName) throws URISyntaxException, MalformedURLException {
super(userIdentifier, timeOfWaitInSeconds);
log.info("Starting the configuration of the web browser");
log.debug(String.format("The Test name is: %s", testName));

LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable(BROWSER, ALL);
Expand All @@ -65,29 +61,22 @@ public ChromeUser(String userName, int timeOfWaitInSeconds, String testName, Str
} else {
Map<String, Object> selenoidOptions = new HashMap<>();
log.info("Using the remote WebDriver (Selenoid)");
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd_HH:mm");
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yy-MM-dd-HH:mm");
LocalDateTime now = LocalDateTime.now();
String baseName = System.getProperty("tjob_name") + "-" + dtf.format(now) + "-" + testName + "-" + userIdentifier ;
log.debug("The data of this test are stored into .mp4 and .log files named: {}" , baseName);
log.debug("Adding all the extra capabilities needed: {testName,enableVideo,enableVNC,name,enableLog,videoName,screenResolution}");
//CAPABILITIES FOR SELENOID

selenoidOptions.put("testName", testName + "_" + userIdentifier + "_" + format.format(new Date()));
//CAPABILITIES FOR SELENOID RETORCH
selenoidOptions.put("testName", testName + "-" + userIdentifier + "-" + dtf.format(now));
selenoidOptions.put("enableVideo", true);
selenoidOptions.put("enableVNC", true);
selenoidOptions.put("name", testName + "-" + userIdentifier);

DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yy-MM-dd-HH:mm");
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: {} and the log name: {} " , videoName,logName);

selenoidOptions.put("enableLog", true);
selenoidOptions.put("logName ", logName);
selenoidOptions.put("videoName", videoName);

selenoidOptions.put("logName ", baseName + ".log");
selenoidOptions.put("videoName", baseName + ".mp4");
selenoidOptions.put("screenResolution", "1920x1080x24");

options.setCapability("selenoid:options", selenoidOptions);

//END CAPABILITIES FOR SELENOID RETORCH
log.debug("Configuring the remote WebDriver ");
RemoteWebDriver remote = new RemoteWebDriver(new URI("http://selenoid:4444/wd/hub").toURL(), options);
Expand Down
43 changes: 15 additions & 28 deletions src/test/java/com/fullteaching/e2e/no_elastest/common/EdgeUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,17 @@
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class EdgeUser extends BrowserUser {
EdgeOptions options = new EdgeOptions();

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


Expand All @@ -52,42 +50,31 @@ public EdgeUser(String userName, int timeOfWaitInSeconds, String testName, Strin
if (eusApiURL == null) {
this.driver = new EdgeDriver(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");
log.debug("Adding all the extra capabilities needed: {testName,enableVideo,enableVNC,name,enableLog,videoName,screenResolution}");

selenoidOptions.put("testName", testName + "_" + userIdentifier + "_" + format.format(new Date()));
//CAPABILITIES FOR SELENOID RETORCH
selenoidOptions.put("enableVideo", true);
selenoidOptions.put("enableVNC", true);
selenoidOptions.put("name", testName + "_" + userIdentifier);

DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yy-MM-dd-HH:mm");
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 {} and the log is {}", videoName,logName);
String baseName = System.getProperty("tjob_name") + "-" + dtf.format(now) + "-" + testName + "-" + userIdentifier ;
log.debug("The data of this test are stored into .mp4 and .log files named: {}" , baseName);
log.debug("Adding all the extra capabilities needed: {testName,enableVideo,enableVNC,name,enableLog,videoName,screenResolution}");
//CAPABILITIES FOR SELENOID

selenoidOptions.put("testName", testName + "-" + userIdentifier + "-" + dtf.format(now));
selenoidOptions.put("enableVideo", true);
selenoidOptions.put("enableVNC", true);
selenoidOptions.put("name", testName + "-" + userIdentifier);
selenoidOptions.put("enableLog", true);
selenoidOptions.put("logName ", logName);
selenoidOptions.put("videoName", videoName);

selenoidOptions.put("logName ", baseName + ".log");
selenoidOptions.put("videoName", baseName + ".mp4");
selenoidOptions.put("screenResolution", "1920x1080x24");

options.setCapability("selenoid:options", selenoidOptions);

//END CAPABILITIES FOR SELENOID RETORCH

RemoteWebDriver remote = new RemoteWebDriver(new URI(eusApiURL).toURL(), options);
log.debug("Configuring the remote WebDriver ");
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);
}
}

new WebDriverWait(driver, Duration.ofSeconds(this.timeOfWaitInSeconds));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,16 @@
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class FirefoxUser extends BrowserUser {
FirefoxOptions options = new FirefoxOptions();

public FirefoxUser(String userName, int timeOfWaitInSeconds, String testName, String userIdentifier) throws URISyntaxException {
super(userName, timeOfWaitInSeconds);
public FirefoxUser(String userIdentifier, int timeOfWaitInSeconds, String testName) throws URISyntaxException, MalformedURLException {
super(userIdentifier, timeOfWaitInSeconds);
//TO-DO Firefox configuration has changed, review it.
FirefoxProfile profile = new FirefoxProfile();
// This flag avoids granting the access to the camera
Expand All @@ -57,50 +55,36 @@ public FirefoxUser(String userName, int timeOfWaitInSeconds, String testName, St
options.setCapability("marionette", true);
driver = new FirefoxDriver(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");
log.debug("Adding all the extra capabilities needed: {testName,enableVideo,enableVNC,name,enableLog,videoName,screenResolution}");

selenoidOptions.put("testName", testName + "_" + userIdentifier + "_" + format.format(new Date()));
//CAPABILITIES FOR SELENOID RETORCH
selenoidOptions.put("enableVideo", true);
selenoidOptions.put("enableVNC", true);
selenoidOptions.put("name", testName + "_" + userIdentifier);

DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yy-MM-dd-HH:mm");
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 {} and the log is {}", videoName,logName);
selenoidOptions.put("enableLog", true);
selenoidOptions.put("logName ", logName);
selenoidOptions.put("videoName", videoName);

selenoidOptions.put("screenResolution", "1920x1080x24");

options.setCapability("selenoid:options", selenoidOptions);

//END CAPABILITIES FOR SELENOID RETORCH

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


this.driver = remote;

remote.setFileDetector(new LocalFileDetector());
this.driver = remote;
} catch (MalformedURLException e) {
throw new RuntimeException("Exception creating eusApiURL", e);
}
Map<String, Object> selenoidOptions = new HashMap<>();
log.info("Using the remote WebDriver (Selenoid)");

DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yy-MM-dd-HH:mm");
LocalDateTime now = LocalDateTime.now();
String baseName = System.getProperty("tjob_name") + "-" + dtf.format(now) + "-" + testName + "-" + userIdentifier ;
log.debug("The data of this test are stored into .mp4 and .log files named: {}", baseName);
log.debug("Adding all the extra capabilities needed: {testName,enableVideo,enableVNC,name,enableLog,videoName,screenResolution}");
//CAPABILITIES FOR SELENOID

selenoidOptions.put("testName", testName + "-" + userIdentifier + "-" + dtf.format(now));
selenoidOptions.put("enableVideo", true);
selenoidOptions.put("enableVNC", true);
selenoidOptions.put("name", testName + "-" + userIdentifier);
selenoidOptions.put("enableLog", true);
selenoidOptions.put("logName ", baseName + ".log");
selenoidOptions.put("videoName", baseName + ".mp4");
selenoidOptions.put("screenResolution", "1920x1080x24");
options.setCapability("selenoid:options", selenoidOptions);
//END CAPABILITIES FOR SELENOID RETORCH
log.debug("Configuring the remote WebDriver ");
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;
}


this.configureDriver();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public static List<String> getUserEntries(WebDriver wd, String user_name) {
List<WebElement> entries = tab_content.findElements(By.className("entry-title"));
for (WebElement entry : entries) {
//if username is the publisher of the entry...
entries_titles.add(entry.findElement(FORUM_ENTRY_LIST_ENTRY_TITLE).getText());
if (entry.getText().contains(user_name))
entries_titles.add(entry.findElement(FORUM_ENTRY_LIST_ENTRY_TITLE).getText());
}

return entries_titles;
Expand All @@ -64,7 +65,6 @@ public static WebElement getEntry(WebDriver wd, String entry_name) throws Elemen

Wait.notTooMuch(wd).until(ExpectedConditions.visibilityOfElementLocated(FORUM_ICON));
WebElement tab_content = CourseNavigationUtilities.getTabContent(wd, FORUM_ICON);
//Wait.notTooMuch(wd).until(ExpectedConditions.visibilityOfElementLocated(By.className("entry-title")));
List<WebElement> entries = tab_content.findElements(By.className("entry-title"));
for (WebElement entry : entries) {
try {
Expand Down Expand Up @@ -147,6 +147,7 @@ public static WebDriver newEntry(WebDriver wd, String newEntryTitle, String newE
public static List<WebElement> getReplies(WebDriver driver, WebElement comment) { //7 lines
log.info("Get all the replies of the selected comment");
List<WebElement> replies = new ArrayList<>();
Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(FORUM_COMMENT_LIST_COMMENT_DIV));
//get all comment-div
List<WebElement> nestedComments = comment.findElements(FORUM_COMMENT_LIST_COMMENT_DIV);
//ignore first it is original comment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public static List<WebElement> getPageLinks(WebDriver wd) { //29 lines
String href = a.getAttribute("href");
if ((href != null) && (!href.trim().isEmpty()) && (!href.contains("#")) && isContainedIn(href.trim(), links_href) && href.contains(host))
links.add(a);

}
return links;
}
Expand Down Expand Up @@ -101,7 +100,6 @@ 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.isEmpty()) && (!href.contains("#")) && isContainedIn(href, original) && href.contains(host))
original.add(href);

return original;
}

Expand All @@ -110,7 +108,6 @@ public static List<String> discardExplored(List<String> new_links, Set<String> e
for (String href : new_links) {
if ((href != null) && (!href.isEmpty()) && (!href.contains("#")) && isContainedIn(href, explored) && href.contains(host))
withOutExplored.add(href);

}
return withOutExplored;
}
Expand Down
Loading

0 comments on commit 612b3fe

Please sign in to comment.