-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creating Load Forum Entries test cases
- Loading branch information
1 parent
de5ddd1
commit 5a33418
Showing
1 changed file
with
344 additions
and
0 deletions.
There are no files selected for viewing
344 changes: 344 additions & 0 deletions
344
...fullteaching/e2e/no_elastest/functional/test/llmexperimentation/LoadForumEntriesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,344 @@ | ||
package com.fullteaching.e2e.no_elastest.functional.test.llmexperimentation; | ||
|
||
import com.fullteaching.e2e.no_elastest.common.BaseLoggedTest; | ||
import com.fullteaching.e2e.no_elastest.common.CourseNavigationUtilities; | ||
import com.fullteaching.e2e.no_elastest.common.ForumNavigationUtilities; | ||
import com.fullteaching.e2e.no_elastest.common.NavigationUtilities; | ||
import com.fullteaching.e2e.no_elastest.common.exception.ElementNotFoundException; | ||
import com.fullteaching.e2e.no_elastest.utils.Click; | ||
import com.fullteaching.e2e.no_elastest.utils.DOMManager; | ||
import com.fullteaching.e2e.no_elastest.utils.ParameterLoader; | ||
import com.fullteaching.e2e.no_elastest.utils.Wait; | ||
import giis.retorch.annotations.AccessMode; | ||
import giis.retorch.annotations.Resource; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Disabled; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Tag; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
import org.openqa.selenium.By; | ||
import org.openqa.selenium.StaleElementReferenceException; | ||
import org.openqa.selenium.WebElement; | ||
import org.openqa.selenium.support.ui.ExpectedCondition; | ||
import org.openqa.selenium.support.ui.ExpectedConditions; | ||
|
||
import java.io.IOException; | ||
import java.util.Calendar; | ||
import java.util.List; | ||
import java.util.stream.Stream; | ||
|
||
import static com.fullteaching.e2e.no_elastest.common.Constants.*; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
@Tag("e2e") | ||
@DisplayName("E2E tests for FullTeaching Login Session") | ||
class LoadForumEntriesTest extends BaseLoggedTest { | ||
protected final String courseName = "Pseudoscientific course for treating the evil eye"; | ||
protected final String[] months = {"January", "February", "March", "April", | ||
"May", "June", "July", "August", "September", | ||
"October", "November", "December"}; | ||
|
||
public LoadForumEntriesTest() { | ||
super(); | ||
} | ||
|
||
public static Stream<Arguments> data() throws IOException { | ||
return ParameterLoader.getTestUsers(); | ||
} | ||
|
||
|
||
/** | ||
* This test get login and navigate to the courses zone checking if there are | ||
* any courses. Second and go to the Pseudo... course accessing to the forum | ||
* and looks if its enable.If It's enable, load all the entries and checks for | ||
* someone that have comments on it.Finally, with the two previous conditions, | ||
* makes an assertEquals() to ensure that both are accomplishment | ||
*/ | ||
@Resource(resID = "LoginService", replaceable = {}) | ||
@AccessMode(resID = "LoginService", concurrency = 10, sharing = true, accessMode = "READONLY") | ||
@Resource(resID = "OpenVidu", replaceable = {"OpenViduMock"}) | ||
@AccessMode(resID = "OpenVidu", concurrency = 10, sharing = true, accessMode = "NOACCESS") | ||
@Resource(resID = "Course", replaceable = {"Forum"}) | ||
@AccessMode(resID = "Course", concurrency = 10, sharing = true, accessMode = "READONLY") | ||
@ParameterizedTest | ||
@MethodSource("data") | ||
void forumLoadEntriesOriginalTest(String mail, String password, String role) { //47lines +115 +28 set up +13 lines teardown =203 | ||
this.slowLogin(user, mail, password);//24 lines | ||
try { | ||
//navigate to courses. | ||
NavigationUtilities.toCoursesHome(driver);//3lines | ||
List<String> courses = CourseNavigationUtilities.getCoursesList(driver);//13lines | ||
assertTrue(courses.size() > 0, "No courses in the list"); | ||
//find course with forum activated | ||
boolean activated_forum_on_some_test = false; | ||
boolean has_comments = false; | ||
for (String course_name : courses) { | ||
//go to each of the courses | ||
WebElement course = CourseNavigationUtilities.getCourseByName(driver, course_name);//14lines | ||
course.findElement(COURSE_LIST_COURSE_TITLE).click(); | ||
Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(By.id(TABS_DIV_ID))); | ||
log.info("Navigating to the forum and checking if its enabled"); | ||
//go to forum tab to check if enabled: | ||
//load forum | ||
CourseNavigationUtilities.go2Tab(driver, FORUM_ICON);//4lines | ||
if (ForumNavigationUtilities.isForumEnabled(CourseNavigationUtilities.getTabContent(driver, FORUM_ICON))) { | ||
activated_forum_on_some_test = true; | ||
log.info("Loading the entries list"); | ||
//Load list of entries | ||
List<String> entries_list = ForumNavigationUtilities.getFullEntryList(driver);//6lines | ||
if (entries_list.size() > 0) { | ||
//Go into first entry | ||
for (String entry_name : entries_list) { | ||
log.info("Checking the entry with name: {}", entry_name); | ||
WebElement entry = ForumNavigationUtilities.getEntry(driver, entry_name);//16lines | ||
Click.element(driver, entry.findElement(FORUM_ENTRY_LIST_ENTRY_TITLE)); | ||
//Load comments | ||
Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(FORUM_COMMENT_LIST)); | ||
List<WebElement> comments = ForumNavigationUtilities.getComments(driver); | ||
log.info("Checking if the entry has comments"); | ||
if (comments.size() > 0) { | ||
has_comments = true; | ||
log.info("Comments found, saving them"); | ||
|
||
ForumNavigationUtilities.getUserComments(driver, userName);//8lines | ||
}//else go to next entry | ||
Click.element(driver, DOMManager.getParent(driver, driver.findElement(BACK_TO_ENTRIES_LIST_ICON))); | ||
} | ||
}//(else) if no entries go to next course | ||
}//(else) if forum no active go to next course | ||
log.info("Returning to the main dashboard"); | ||
driver = Click.element(driver, BACK_TO_DASHBOARD); | ||
} | ||
assertTrue((activated_forum_on_some_test && has_comments), "There isn't any forum that can be used to test this [Or not activated or no entry lists or not comments]"); | ||
} catch (ElementNotFoundException notFoundException) { | ||
fail("Failed to navigate to courses forum:: " + notFoundException.getClass() + ": " + notFoundException.getLocalizedMessage()); | ||
} | ||
} | ||
|
||
@AccessMode(resID = "loginservice", concurrency = 10, sharing = true, accessMode = "READONLY") | ||
@AccessMode(resID = "openvidumock", concurrency = 10, sharing = true, accessMode = "NOACCESS") | ||
@AccessMode(resID = "forum", concurrency = 1, sharing = false, accessMode = "READWRITE") | ||
@AccessMode(resID = "executor", concurrency = 1, accessMode = "READWRITE") | ||
@AccessMode(resID = "webbrowser", concurrency = 1, accessMode = "READWRITE") | ||
@AccessMode(resID = "webserver", concurrency = 1, accessMode = "READWRITE") | ||
@ParameterizedTest | ||
@MethodSource("data") | ||
void userLoadForumEntriesFS4oTest(String mail, String password, String role) { | ||
this.slowLogin(user, mail, password); | ||
|
||
try { | ||
// Navigate to courses home | ||
NavigationUtilities.toCoursesHome(driver); | ||
|
||
// Find and click on the course | ||
WebElement course = CourseNavigationUtilities.getCourseByName(driver, courseName); | ||
course.findElement(COURSE_LIST_COURSE_TITLE).click(); | ||
|
||
// Wait for the course page to load and navigate to the forum tab | ||
Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(By.id(TABS_DIV_ID))); | ||
CourseNavigationUtilities.go2Tab(driver, FORUM_ICON); | ||
|
||
// Verify that the forum is enabled | ||
assertTrue(ForumNavigationUtilities.isForumEnabled(CourseNavigationUtilities.getTabContent(driver, FORUM_ICON)), "Forum not activated"); | ||
|
||
// Get the list of forum entries | ||
List<String> entriesList = ForumNavigationUtilities.getFullEntryList(driver); | ||
|
||
// Verify that the forum entries are displayed | ||
assertFalse(entriesList.isEmpty(), "No forum entries found"); | ||
|
||
} catch (ElementNotFoundException notFoundException) { | ||
fail("Failed to navigate to course forum: " + notFoundException.getClass() + ": " + notFoundException.getLocalizedMessage()); | ||
} | ||
} | ||
|
||
@AccessMode(resID = "loginservice", concurrency = 10, sharing = true, accessMode = "READONLY") | ||
@AccessMode(resID = "forum", concurrency = 1, sharing = false, accessMode = "READWRITE") | ||
@ParameterizedTest | ||
@MethodSource("data") | ||
void forumEntriesCOT4oTest(String mail, String password, String role) { | ||
this.slowLogin(user, mail, password); | ||
Calendar calendar = Calendar.getInstance(); | ||
calendar.setTimeInMillis(System.currentTimeMillis()); | ||
int mYear = calendar.get(Calendar.YEAR); | ||
int mMonth = calendar.get(Calendar.MONTH); | ||
int mDay = calendar.get(Calendar.DAY_OF_MONTH); | ||
int mHour = calendar.get(Calendar.HOUR_OF_DAY); | ||
int mMinute = calendar.get(Calendar.MINUTE); | ||
int mSecond = calendar.get(Calendar.SECOND); | ||
|
||
try { | ||
// Navigate to courses page | ||
NavigationUtilities.toCoursesHome(driver); | ||
|
||
// Select the course | ||
WebElement course = CourseNavigationUtilities.getCourseByName(driver, courseName); | ||
course.findElement(COURSE_LIST_COURSE_TITLE).click(); | ||
Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(By.id(TABS_DIV_ID))); | ||
|
||
// Navigate to the forum section | ||
CourseNavigationUtilities.go2Tab(driver, FORUM_ICON); | ||
assertTrue(ForumNavigationUtilities.isForumEnabled(CourseNavigationUtilities.getTabContent(driver, FORUM_ICON)), "Forum not activated"); | ||
|
||
// Check for existing forum entries | ||
List<String> entries_list = ForumNavigationUtilities.getFullEntryList(driver); | ||
WebElement entry; | ||
if (entries_list.size() <= 0) { | ||
// Create a new forum entry if none exist | ||
String newEntryTitle = "New Entry Test " + mDay + mMonth + mYear + mHour + mMinute + mSecond; | ||
String newEntryContent = "This is the content written on the " + mDay + " of " + months[mMonth] + ", " + mHour + ":" + mMinute + "," + mSecond; | ||
ForumNavigationUtilities.newEntry(driver, newEntryTitle, newEntryContent); | ||
entry = ForumNavigationUtilities.getEntry(driver, newEntryTitle); | ||
} else { | ||
// Select the first existing entry | ||
entry = ForumNavigationUtilities.getEntry(driver, entries_list.get(0)); | ||
} | ||
|
||
// Add a new comment to the selected forum entry | ||
Click.element(driver, entry.findElement(FORUM_ENTRY_LIST_ENTRY_TITLE)); | ||
WebElement commentList = Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(FORUM_COMMENT_LIST)); | ||
int numberCommentsOld = ForumNavigationUtilities.getComments(driver).size(); | ||
WebElement newCommentIcon = commentList.findElement(FORUM_COMMENT_LIST_NEW_COMMENT_ICON); | ||
Click.element(driver, newCommentIcon); | ||
Wait.aLittle(driver).until(ExpectedConditions.visibilityOfElementLocated(FORUM_NEW_COMMENT_MODAL)); | ||
String newCommentContent = "COMMENT TEST" + mDay + mMonth + mYear + mHour + mMinute + mSecond + ". This is the comment written on the " + mDay + " of " + months[mMonth] + ", " + mHour + ":" + mMinute + "," + mSecond; | ||
WebElement comment_field = driver.findElement(FORUM_NEW_COMMENT_MODAL_TEXT_FIELD); | ||
comment_field.sendKeys(newCommentContent); | ||
Click.element(driver, FORUM_NEW_COMMENT_MODAL_POST_BUTTON); | ||
|
||
// Verify the new comment is added successfully | ||
Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(FORUM_COMMENT_LIST)); | ||
Wait.waitForPageLoaded(driver); | ||
user.waitUntil(ExpectedConditions.visibilityOfElementLocated(FORUM_COMMENT_LIST_COMMENT), "The comment list are not visible"); | ||
user.waitUntil(driver -> ForumNavigationUtilities.getComments(driver).size() > numberCommentsOld, "Comment not attached"); | ||
List<WebElement> comments = ForumNavigationUtilities.getComments(driver); | ||
assertTrue(comments.size() > numberCommentsOld, "Comment list empty or only original comment"); | ||
|
||
boolean commentFound = false; | ||
for (WebElement comment : comments) { | ||
try { | ||
String text = comment.findElement(FORUM_COMMENT_LIST_COMMENT_CONTENT).getText(); | ||
if (text.equals(newCommentContent)) { | ||
commentFound = true; | ||
assertEquals(comment.findElement(FORUM_COMMENT_LIST_COMMENT_USER).getText(), userName, "Bad user in comment"); | ||
} | ||
} catch (Exception e) { | ||
log.info("Not Found"); | ||
} | ||
} | ||
assertTrue(commentFound, "Comment not found"); | ||
} catch (ElementNotFoundException notFoundException) { | ||
fail("Failed to navigate to course forum:: " + notFoundException.getClass() + ": " + notFoundException.getLocalizedMessage()); | ||
} | ||
} | ||
@AccessMode(resID = "loginservice", concurrency = 10, sharing = true, accessMode = "READONLY") | ||
@AccessMode(resID = "forum", concurrency = 10, sharing = false, accessMode = "READWRITE") | ||
@ParameterizedTest | ||
@MethodSource("data") | ||
void userLoadForumEntriesFS4oMiniTest(String mail, String password, String role) { | ||
this.slowLogin(user, mail, password); | ||
Calendar calendar = Calendar.getInstance(); | ||
calendar.setTimeInMillis(System.currentTimeMillis()); | ||
int mYear = calendar.get(Calendar.YEAR); | ||
int mMonth = calendar.get(Calendar.MONTH); | ||
int mDay = calendar.get(Calendar.DAY_OF_MONTH); | ||
int mHour = calendar.get(Calendar.HOUR_OF_DAY); | ||
int mMinute = calendar.get(Calendar.MINUTE); | ||
int mSecond = calendar.get(Calendar.SECOND); | ||
|
||
try { | ||
// Navigate to the courses home | ||
NavigationUtilities.toCoursesHome(driver); | ||
|
||
// Access the specific course | ||
WebElement course = CourseNavigationUtilities.getCourseByName(driver, courseName); | ||
course.findElement(COURSE_LIST_COURSE_TITLE).click(); | ||
Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(By.id(TABS_DIV_ID))); | ||
|
||
// Go to the forum tab | ||
CourseNavigationUtilities.go2Tab(driver, FORUM_ICON); | ||
assertTrue(ForumNavigationUtilities.isForumEnabled(CourseNavigationUtilities.getTabContent(driver, FORUM_ICON)), "Forum not activated"); | ||
|
||
// Create a new forum entry | ||
String newEntryTitle = "Load Test Entry " + mDay + "-" + mMonth + "-" + mYear + " " + mHour + ":" + mMinute + ":" + mSecond; | ||
String newEntryContent = "This is a load test entry created on " + mDay + " of " + months[mMonth] + ", " + mHour + ":" + mMinute + "," + mSecond; | ||
ForumNavigationUtilities.newEntry(driver, newEntryTitle, newEntryContent); | ||
|
||
// Verify the entry is created | ||
WebElement newEntry = ForumNavigationUtilities.getEntry(driver, newEntryTitle); | ||
assertNotNull(newEntry, "New entry was not created successfully"); | ||
|
||
// Check if the entry is displayed correctly | ||
Click.element(driver, newEntry.findElement(FORUM_ENTRY_LIST_ENTRY_TITLE)); | ||
Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(FORUM_COMMENT_LIST)); | ||
|
||
// Verify entry title and content | ||
WebElement entryTitleRow = driver.findElement(FORUM_COMMENT_LIST_ENTRY_TITLE); | ||
assertEquals(entryTitleRow.getText().split("\\n")[0], newEntryTitle, "Incorrect Entry Title"); | ||
assertEquals(entryTitleRow.findElement(FORUM_COMMENT_LIST_ENTRY_USER).getText(), userName, "Incorrect User for Entry"); | ||
|
||
// Verify that the first comment matches the entry content | ||
List<WebElement> comments = ForumNavigationUtilities.getComments(driver); | ||
assertFalse(comments.isEmpty(), "No comments on the entry"); | ||
WebElement firstComment = comments.get(0); | ||
assertEquals(firstComment.findElement(FORUM_COMMENT_LIST_COMMENT_CONTENT).getText(), newEntryContent, "Bad content of comment"); | ||
assertEquals(firstComment.findElement(FORUM_COMMENT_LIST_COMMENT_USER).getText(), userName, "Bad user in comment"); | ||
|
||
} catch (ElementNotFoundException notFoundException) { | ||
Assertions.fail("Failed to navigate to course forum:: " + notFoundException.getClass() + ": " + notFoundException.getLocalizedMessage()); | ||
} | ||
} | ||
|
||
void loadForumEntriesCOT4oMiniTest() { | ||
// Step 1: User Login | ||
this.slowLogin(user, "[email protected]", "password123"); | ||
|
||
// Step 2: Navigate to Courses | ||
NavigationUtilities.toCoursesHome(driver); | ||
|
||
// Step 3: Select a Course | ||
WebElement course = CourseNavigationUtilities.getCourseByName(driver, courseName); | ||
course.findElement(By.cssSelector(".course-title")).click(); // Adjust selector as needed | ||
|
||
// Step 4: Access the Forum Section | ||
Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(By.id("tabs-div-id"))); | ||
CourseNavigationUtilities.go2Tab(driver, "forum-icon"); // Adjust as needed | ||
|
||
// Step 5: Load Forum Entries | ||
Assertions.assertTrue(ForumNavigationUtilities.isForumEnabled(CourseNavigationUtilities.getTabContent(driver, "forum-icon")), "Forum not activated"); | ||
|
||
List<String> entriesList = ForumNavigationUtilities.getFullEntryList(driver); | ||
WebElement entry; | ||
|
||
if (entriesList.isEmpty()) { | ||
// Create a new forum entry if none exist | ||
String newEntryTitle = "New Entry Test"; | ||
String newEntryContent = "This is a test entry content."; | ||
ForumNavigationUtilities.newEntry(driver, newEntryTitle, newEntryContent); | ||
entry = ForumNavigationUtilities.getEntry(driver, newEntryTitle); | ||
} else { | ||
// Select the first existing entry | ||
entry = ForumNavigationUtilities.getEntry(driver, entriesList.get(0)); | ||
} | ||
|
||
// Step 6: Verify Forum Entry Details | ||
Click.element(driver, entry.findElement(By.cssSelector(".entry-title"))); // Adjust selector as needed | ||
WebElement entryTitle = driver.findElement(By.cssSelector(".entry-title")); | ||
WebElement entryContent = driver.findElement(By.cssSelector(".entry-content")); // Adjust selector as needed | ||
|
||
Assertions.assertNotNull(entryTitle, "Entry title is not displayed"); | ||
Assertions.assertNotNull(entryContent, "Entry content is not displayed"); | ||
|
||
// Verify comments | ||
List<WebElement> comments = ForumNavigationUtilities.getComments(driver); | ||
Assertions.assertFalse(comments.isEmpty(), "No comments found for the entry"); | ||
|
||
// Step 7: Cleanup | ||
user.getDriver().get(APP_URL); // Navigate to the main page to log out | ||
} | ||
|
||
|
||
|
||
} |