From 5783521e12e9e2667946b8c51d77db106e1bc442 Mon Sep 17 00:00:00 2001 From: Augusto Date: Sun, 18 Aug 2024 14:27:34 +0200 Subject: [PATCH] Fixing the ReplyToCommentTest --- .../common/ForumNavigationUtilities.java | 5 +++-- .../functional/test/LoggedForumTest.java | 15 ++++++--------- 2 files changed, 9 insertions(+), 11 deletions(-) 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) {