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/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) {