From 91d5f11578513782fc2eaba6f074869daaf5cb91 Mon Sep 17 00:00:00 2001 From: Augusto Date: Sun, 18 Aug 2024 14:27:34 +0200 Subject: [PATCH] Fixing the ReplyToCommentTest --- .../no_elastest/common/BaseLoggedTest.java | 16 +++-- .../e2e/no_elastest/common/ChromeUser.java | 29 +++----- .../e2e/no_elastest/common/EdgeUser.java | 41 ++++------- .../e2e/no_elastest/common/FirefoxUser.java | 72 +++++++------------ .../common/ForumNavigationUtilities.java | 5 +- .../functional/test/LoggedForumTest.java | 15 ++-- 6 files changed, 70 insertions(+), 108 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 6f7060d..ea37e24 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 @@ -109,11 +109,15 @@ 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, "Teacher", WAIT_SECONDS); this.driver = this.user.getDriver(); @@ -159,9 +163,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("[{}] {} {}", @@ -175,7 +179,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("[{}] {} {}", 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 a64bfec..7ab2831 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 @@ -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; @@ -45,7 +42,6 @@ public class ChromeUser extends BrowserUser { 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)); LoggingPreferences logPrefs = new LoggingPreferences(); logPrefs.enable(BROWSER, ALL); @@ -56,6 +52,7 @@ public ChromeUser(String userName, int timeOfWaitInSeconds, String testName, Str //Problems with flakiness due to screen resolution solved with --start-maximized options.addArguments("--start-maximized"); options.setAcceptInsecureCerts(true); + //This capability is to store the logs of the test case log.debug("Added Capabilities of acceptInsecureCerts and ignore alarms"); @@ -65,29 +62,23 @@ public ChromeUser(String userName, int timeOfWaitInSeconds, String testName, Str } else { Map 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"; + 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); 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 3d46ba3..84b03a8 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 @@ -26,18 +26,16 @@ 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 { + public EdgeUser(String userName, int timeOfWaitInSeconds, String testName, String userIdentifier) throws URISyntaxException, MalformedURLException { super(userName, timeOfWaitInSeconds); log.info(String.format("The Test names are: %s", testName)); @@ -52,42 +50,31 @@ public EdgeUser(String userName, int timeOfWaitInSeconds, String testName, Strin if (eusApiURL == null) { this.driver = new EdgeDriver(options); } else { - try { Map 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"; + 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)); 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 8ca21e4..3fb2cf5 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 @@ -26,17 +26,15 @@ 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 { + public FirefoxUser(String userName, int timeOfWaitInSeconds, String testName, String userIdentifier) throws URISyntaxException, MalformedURLException { super(userName, timeOfWaitInSeconds); //TO-DO Firefox configuration has changed, review it. FirefoxProfile profile = new FirefoxProfile(); @@ -48,59 +46,43 @@ public FirefoxUser(String userName, int timeOfWaitInSeconds, String testName, St String eusApiURL = System.getenv("ET_EUS_API"); - options.setCapability("acceptInsecureCerts", true); - if (eusApiURL == null) { options.setCapability("marionette", true); driver = new FirefoxDriver(options); - } else { - try { - Map 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 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"; + 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(); } + } \ No newline at end of file diff --git a/src/test/java/com/fullteaching/e2e/no_elastest/common/ForumNavigationUtilities.java b/src/test/java/com/fullteaching/e2e/no_elastest/common/ForumNavigationUtilities.java index 6f4b3d9..bf402ad 100644 --- a/src/test/java/com/fullteaching/e2e/no_elastest/common/ForumNavigationUtilities.java +++ b/src/test/java/com/fullteaching/e2e/no_elastest/common/ForumNavigationUtilities.java @@ -53,7 +53,8 @@ public static List getUserEntries(WebDriver wd, String user_name) { List 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; @@ -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 entries = tab_content.findElements(By.className("entry-title")); for (WebElement entry : entries) { try { @@ -147,6 +147,7 @@ public static WebDriver newEntry(WebDriver wd, String newEntryTitle, String newE public static List getReplies(WebDriver driver, WebElement comment) { //7 lines log.info("Get all the replies of the selected comment"); List replies = new ArrayList<>(); + Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(FORUM_COMMENT_LIST_COMMENT_DIV)); //get all comment-div List nestedComments = comment.findElements(FORUM_COMMENT_LIST_COMMENT_DIV); //ignore first it is original comment diff --git a/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/LoggedForumTest.java b/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/LoggedForumTest.java index 4fa355c..64a0508 100644 --- a/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/LoggedForumTest.java +++ b/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/LoggedForumTest.java @@ -45,7 +45,7 @@ public LoggedForumTest() { } public static Stream data() throws IOException { - return ParameterLoader.getTestUsers(); + return ParameterLoader.getTestTeachers(); } @@ -323,7 +323,6 @@ void forumNewReply2CommentTest(String mail, String password, String role) { // 6 try { //check if one course have any entry for comment NavigationUtilities.toCoursesHome(driver);//3lines - WebElement course = CourseNavigationUtilities.getCourseByName(driver, courseName);//14 lines course.findElement(COURSE_LIST_COURSE_TITLE).click(); Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(By.id(TABS_DIV_ID))); @@ -331,7 +330,7 @@ void forumNewReply2CommentTest(String mail, String password, String role) { // 6 assertTrue(ForumNavigationUtilities.isForumEnabled(CourseNavigationUtilities.getTabContent(driver, FORUM_ICON)), "Forum not activated");//2lines List entries_list = ForumNavigationUtilities.getFullEntryList(driver);//6lines WebElement entry; - if (entries_list.size() <= 0) {//if not new entry + if (entries_list.isEmpty()) {//if not new entry newEntryTitle = "New Comment Test " + mDay + mMonth + mYear + mHour + mMinute + mSecond; String newEntryContent = "This is the content written on the " + mDay + " of " + months[mMonth - 1] + ", " + mHour + ":" + mMinute + "," + mSecond; ForumNavigationUtilities.newEntry(driver, newEntryTitle, newEntryContent); //19 lines @@ -352,7 +351,7 @@ void forumNewReply2CommentTest(String mail, String password, String role) { // 6 WebElement textField = driver.findElement(FORUM_COMMENT_LIST_MODAL_NEW_REPLY_TEXT_FIELD); textField.sendKeys(newReplyContent); Click.element(user.getDriver(), FORUM_NEW_COMMENT_MODAL_POST_BUTTON); - + user.waitUntil(ExpectedConditions.invisibilityOfElementLocated(FORUM_COMMENT_LIST_MODAL_NEW_REPLY),"The model is still visible"); user.waitUntil(ExpectedConditions.visibilityOfElementLocated(FORUM_COMMENT_LIST), "The comments are not visible"); user.waitUntil(ExpectedConditions.visibilityOfElementLocated(FORUM_COMMENT_LIST_COMMENT), "The comment list are not visible"); @@ -361,16 +360,14 @@ void forumNewReply2CommentTest(String mail, String password, String role) { // 6 List replies = ForumNavigationUtilities.getReplies(user.getDriver(), comments.get(0)); // 7 lines WebElement newReply = null; for (WebElement reply : replies) { - - reply.findElement(By.cssSelector("#div.col.l11.m11.s11 > div.message-itself")); String text = reply.getText(); - if (text.equals(newReplyContent)) + if (text.contains(newReplyContent)) newReply = reply; } //assert reply assertNotNull(newReply, "Reply not found"); - boolean asserto = newReply.findElement(FORUM_COMMENT_LIST_COMMENT_USER).getText().equals(userName); - assertTrue(asserto, "Bad user in comment"); + boolean isNameEqual = newReply.findElement(FORUM_COMMENT_LIST_COMMENT_USER).getText().equals(userName); + assertTrue(isNameEqual, "Bad user in comment"); //nested reply //assert nested reply } catch (ElementNotFoundException notFoundException) {