diff --git a/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/llmexperimentation/AViewEnrolledCoursesTest.java b/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/llmexperimentation/AViewEnrolledCoursesTest.java new file mode 100644 index 0000000..532c161 --- /dev/null +++ b/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/llmexperimentation/AViewEnrolledCoursesTest.java @@ -0,0 +1,227 @@ +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.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.WebElement; +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 AViewEnrolledCoursesTest 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 AViewEnrolledCoursesTest() { + super(); + } + + public static Stream 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 + */ + @AccessMode(resID = "loginservice", concurrency = 10, sharing = true, accessMode = "READONLY") + @AccessMode(resID = "openvidumock", concurrency = 10, sharing = true, accessMode = "NOACCESS") + @AccessMode(resID = "forum", concurrency = 10, sharing = true, accessMode = "READONLY") + @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 forumLoadEntriesOriginalTest(String mail, String password, String role) { + this.slowLogin(user, mail, password); + try { + //navigate to courses. + NavigationUtilities.toCoursesHome(driver); + List courses = CourseNavigationUtilities.getCoursesList(driver); + 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); + 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); + 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 entries_list = ForumNavigationUtilities.getFullEntryList(driver); + 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); + Click.element(driver, entry.findElement(FORUM_ENTRY_LIST_ENTRY_TITLE)); + //Load comments + Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(FORUM_COMMENT_LIST)); + List 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); + }//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()); + } + } + @ParameterizedTest + @MethodSource("data") + void viewEnrolledCoursesFS4oTest(String mail, String password, String role) { + // Step 1: User logs into the application + this.slowLogin(user, mail, password); + + // Step 2: User navigates to the dashboard + try { + if (NavigationUtilities.amINotHere(driver, COURSES_URL.replace("__HOST__", HOST))) { + NavigationUtilities.toCoursesHome(driver); + } + + // Step 3: System displays a list of courses the user is enrolled in + Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(By.id("courses-list"))); + List courses = driver.findElements(By.className("course-item")); + + // Expected Output: The dashboard shows a list of courses the user is enrolled in + assertTrue(courses.size() > 0, "No enrolled courses found for the user"); + + } catch (Exception e) { + fail("Failed to view enrolled courses: " + e.getClass() + ": " + e.getLocalizedMessage()); + } + + // Teardown: Navigate to the main page to logout + user.getDriver().get(APP_URL); + } + @Test + void viewEnrolledCoursesCOT4oTest() { + // Setup + String email = "user@example.com"; + String password = "password"; + String[] expectedCourses = {"Course 1", "Course 2", "Course 3"}; + + // Login + this.slowLogin(user, email, password); + + // Verify Dashboard + try { + // Wait for the dashboard to load + Wait.notTooMuch(driver).until(ExpectedConditions.presenceOfElementLocated(By.id("dashboard"))); + + // Get the list of enrolled courses + List courses = driver.findElements(By.className("course-title")); + + // Verify the number of courses + assertEquals(expectedCourses.length, courses.size(), "Number of enrolled courses does not match"); + + // Verify the course titles + for (int i = 0; i < expectedCourses.length; i++) { + assertEquals(expectedCourses[i], courses.get(i).getText(), "Course title does not match"); + } + + } catch (Exception e) { + fail("Failed to verify enrolled courses: " + e.getClass() + ": " + e.getLocalizedMessage()); + } + + // Teardown + user.getDriver().get(APP_URL); + } + @AccessMode(resID = "loginservice", concurrency = 10, sharing = true, accessMode = "READONLY") + @AccessMode(resID = "course", concurrency = 15, sharing = true, accessMode = "READONLY") + @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 viewEnrolledCoursesFS4oMiniTest(String mail, String password, String role) { + // Setup: User logs into the application + this.slowLogin(user, mail, password); + + // Navigate to the dashboard + NavigationUtilities.toDashboard(driver); + + // Wait for the courses list to be visible + Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(By.id("enrolledCoursesList"))); + + // Verify that the dashboard shows a list of courses the user is enrolled in + List enrolledCourses = driver.findElements(By.className("course-title")); + assertFalse(enrolledCourses.isEmpty(), "The enrolled courses list should not be empty."); + + // Optionally, you can check for specific course titles if known + // assertTrue(enrolledCourses.stream().anyMatch(course -> course.getText().equals("Expected Course Title")), "Expected course is not found in the enrolled courses list."); + + // Teardown: Navigate back to the main page or logout + user.getDriver().get(APP_URL); + } + @Test + void viewEnrolledCoursesCOT4oMiniTest() { + // Setup: Log in to the application + String email = "testuser@example.com"; // Replace with actual test user email + String password = "password"; // Replace with actual test user password + this.slowLogin(user, email, password); + + // Navigation: Navigate to the dashboard + NavigationUtilities.toDashboard(driver); + + // Verification: Check that the system displays a list of enrolled courses + List enrolledCourses = driver.findElements(By.className("enrolled-course")); // Replace with actual class name for enrolled courses + Assertions.assertFalse(enrolledCourses.isEmpty(), "The enrolled courses list should not be empty."); + + // Optionally, validate the content of the enrolled courses + for (WebElement course : enrolledCourses) { + String courseTitle = course.getText(); // Assuming the course title is displayed as text + Assertions.assertNotNull(courseTitle, "Course title should not be null."); + // Add more assertions as needed to validate course details + } + + // Teardown: Log out of the application + NavigationUtilities.logout(driver); // Replace with actual logout method + } + + +} diff --git a/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/llmexperimentation/BViewCourseClassesTest.java b/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/llmexperimentation/BViewCourseClassesTest.java new file mode 100644 index 0000000..63ee542 --- /dev/null +++ b/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/llmexperimentation/BViewCourseClassesTest.java @@ -0,0 +1,264 @@ +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.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.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 BViewCourseClassesTest 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 BViewCourseClassesTest() { + super(); + } + + public static Stream data() throws IOException { + return ParameterLoader.getTestUsers(); + } + + @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 forumNewEntryTest(String mail, String password, String role) {// 48+ 104 + 28 set up +13 lines teardown =193 + this.slowLogin(user, mail, password); //24 lines + 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); + log.info("Setting new entry title and content"); + 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; + log.info("Navigating to courses tab"); + try { + log.info("Navigating to courses tab"); + //navigate to courses. + if (NavigationUtilities.amINotHere(driver, COURSES_URL.replace("__HOST__", HOST))) { + NavigationUtilities.toCoursesHome(driver);//3lines + } + WebElement course = CourseNavigationUtilities.getCourseByName(driver, courseName);//14lines + log.info("Entering the course List"); + course.findElement(COURSE_LIST_COURSE_TITLE).click(); + + Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(By.id(TABS_DIV_ID))); + log.info("Entering the Forum"); + CourseNavigationUtilities.go2Tab(driver, FORUM_ICON); //4lines + assertTrue(ForumNavigationUtilities.isForumEnabled(CourseNavigationUtilities.getTabContent(driver, FORUM_ICON)), "Forum not activated"); //6lines + Wait.waitForPageLoaded(driver); + ForumNavigationUtilities.newEntry(driver, newEntryTitle, newEntryContent); //16lines + //Retorch Modification, this test fails due to the speed of the browser + Wait.waitForPageLoaded(driver); + //Check entry... Flake Here + WebElement newEntry = ForumNavigationUtilities.getEntry(driver, newEntryTitle);//16lines + Wait.waitForPageLoaded(driver); + assertEquals(newEntry.findElement(FORUM_ENTRY_LIST_ENTRY_USER).getText(), userName, "Incorrect user"); + Click.element(driver, newEntry.findElement(FORUM_ENTRY_LIST_ENTRY_TITLE)); + Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(FORUM_COMMENT_LIST)); + 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"); + //first comment should be the inserted while creating the entry + Wait.waitForPageLoaded(driver); + List comments = ForumNavigationUtilities.getComments(driver); + assertFalse(comments.size() < 1, "No comments on the entry"); + Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(FORUM_COMMENT_LIST)); + Wait.waitForPageLoaded(driver); + WebElement newComment = comments.get(0); + String commentContent = newComment.findElement(FORUM_COMMENT_LIST_COMMENT_CONTENT).getText(); + assertEquals(commentContent, newEntryContent, "Bad content of comment"); + Wait.waitForPageLoaded(driver); + String comment = newComment.findElement(FORUM_COMMENT_LIST_COMMENT_USER).getText(); + assertEquals(comment, userName, "Bad user in comment"); + } catch (ElementNotFoundException notFoundException) { + Assertions.fail("Failed to navigate to course forum:: " + notFoundException.getClass() + ": " + notFoundException.getLocalizedMessage()); + } + //Fix Flaky test Navigating to the mainpage to logout... + user.getDriver().get(APP_URL); + } + @AccessMode(resID = "loginservice", concurrency = 10, sharing = true, accessMode = "READONLY") + @AccessMode(resID = "course", concurrency = 15, sharing = true, accessMode = "DYNAMIC") + @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 accessCoursesAndViewClassesFS4oTest(String mail, String password, String role) { + this.slowLogin(user, mail, password); + try { + // Navigate to courses + NavigationUtilities.toCoursesHome(driver); + List courses = CourseNavigationUtilities.getCoursesList(driver); + assertTrue(courses.size() > 0, "No courses in the list"); + + // Access the first course + WebElement course = CourseNavigationUtilities.getCourseByName(driver, courses.get(0)); + course.findElement(By.cssSelector(".course-title")).click(); + Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(By.id("course-classes"))); + + // Verify classes are ordered by date + List classes = driver.findElements(By.cssSelector(".class-item")); + assertTrue(classes.size() > 0, "No classes found in the course"); + + // Check if classes are ordered by date + boolean isOrderedByDate = true; + for (int i = 1; i < classes.size(); i++) { + String previousDate = classes.get(i - 1).findElement(By.cssSelector(".class-date")).getText(); + String currentDate = classes.get(i).findElement(By.cssSelector(".class-date")).getText(); + if (previousDate.compareTo(currentDate) > 0) { + isOrderedByDate = false; + break; + } + } + assertTrue(isOrderedByDate, "Classes are not ordered by date"); + + } catch (Exception e) { + fail("Failed to access courses and view classes: " + e.getClass() + ": " + e.getLocalizedMessage()); + } + } + @Test + void userAccessCoursesAndViewClassesCOT4oTest() { + // Step 1: User logs into the application + this.slowLogin(user, "user@example.com", "password"); + + try { + // Step 2: User navigates to the dashboard + NavigationUtilities.toCoursesHome(driver); + List courses = CourseNavigationUtilities.getCoursesList(driver); + assertTrue(courses.size() > 0, "No courses in the list"); + + // Step 3: User clicks on a course + String courseName = courses.get(0); // Select the first course for simplicity + WebElement course = CourseNavigationUtilities.getCourseByName(driver, courseName); + course.findElement(By.cssSelector(".course-title")).click(); + Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(By.id("course-page"))); + + // Step 4: System displays the classes within the course, ordered by date + List classes = driver.findElements(By.cssSelector(".class-item")); + assertTrue(classes.size() > 0, "No classes found in the course"); + + // Verify that classes are ordered by date + for (int i = 1; i < classes.size(); i++) { + String previousDate = classes.get(i - 1).findElement(By.cssSelector(".class-date")).getText(); + String currentDate = classes.get(i).findElement(By.cssSelector(".class-date")).getText(); + assertTrue(previousDate.compareTo(currentDate) <= 0, "Classes are not ordered by date"); + } + + } catch (Exception e) { + fail("Test failed: " + e.getMessage()); + } + } + @AccessMode(resID = "loginservice", concurrency = 10, sharing = true, accessMode = "READONLY") + @AccessMode(resID = "course", concurrency = 15, sharing = true, accessMode = "READONLY") + @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 userAccessCoursesAndViewClassesFS4oMiniTest(String mail, String password, String role) { + // Step 1: User logs into the application + this.slowLogin(user, mail, password); + + try { + // Step 2: User navigates to the dashboard + NavigationUtilities.toCoursesHome(driver); + + // Step 3: User clicks on a course + List courses = CourseNavigationUtilities.getCoursesList(driver); + assertFalse(courses.isEmpty(), "No courses available for the user."); + + // Click on the first course in the list + WebElement course = CourseNavigationUtilities.getCourseByName(driver, courses.get(0)); + Click.element(driver, course.findElement(COURSE_LIST_COURSE_TITLE)); + + // Step 4: System displays the classes within the course, ordered by date + Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(By.id(TABS_DIV_ID))); + + // Verify that classes are displayed + List classes = CourseNavigationUtilities.getClassesList(driver); + assertFalse(classes.isEmpty(), "No classes found for the selected course."); + + // Optionally, check if classes are ordered by date + // (Assuming there is a method to verify the order of classes) + assertTrue(CourseNavigationUtilities.areClassesOrderedByDate(classes), "Classes are not ordered by date."); + + } catch (ElementNotFoundException notFoundException) { + fail("Failed to navigate to courses or view classes: " + notFoundException.getClass() + ": " + notFoundException.getLocalizedMessage()); + } + } + @AccessMode(resID = "loginservice", concurrency = 10, sharing = true, accessMode = "READONLY") + @AccessMode(resID = "course", concurrency = 15, sharing = true, accessMode = "READONLY") + @ParameterizedTest + @MethodSource("data") // Assuming data() provides test users + void userAccessCoursesAndViewClassesCOT4oMiniTest(String mail, String password, String role) { + // Step 1: Login to the application + this.slowLogin(user, mail, password); + + try { + // Step 2: Navigate to the dashboard + NavigationUtilities.toDashboard(driver); + Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(By.id(DASHBOARD_ID))); + + // Step 3: View enrolled courses + List enrolledCourses = CourseNavigationUtilities.getCoursesList(driver); + assertFalse(enrolledCourses.isEmpty(), "The user should have enrolled courses displayed."); + + // Step 4: Access a course + String courseName = enrolledCourses.get(0); // Access the first course + WebElement courseElement = CourseNavigationUtilities.getCourseByName(driver, courseName); + Click.element(driver, courseElement); + Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(By.id(COURSE_PAGE_ID))); + + // Step 5: View classes within the course + List classes = CourseNavigationUtilities.getClassesList(driver); + assertFalse(classes.isEmpty(), "The course should have classes displayed."); + // Optionally, check if classes are ordered by date + // (Assuming there's a method to verify order) + assertTrue(CourseNavigationUtilities.areClassesOrderedByDate(classes), "Classes should be ordered by date."); + + } catch (Exception e) { + fail("Test failed due to an exception: " + e.getMessage()); + } finally { + // Step 6: Teardown + user.getDriver().get(APP_URL); // Navigate back to the home page + } + } + +} diff --git a/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/llmexperimentation/CTeacherCreatesCourseTest.java b/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/llmexperimentation/CTeacherCreatesCourseTest.java new file mode 100644 index 0000000..ad5eaf5 --- /dev/null +++ b/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/llmexperimentation/CTeacherCreatesCourseTest.java @@ -0,0 +1,210 @@ +package com.fullteaching.e2e.no_elastest.functional.test.llmexperimentation; + +import com.fullteaching.e2e.no_elastest.common.BaseLoggedTest; +import com.fullteaching.e2e.no_elastest.utils.ParameterLoader; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.params.provider.Arguments; + +import java.io.IOException; +import java.util.stream.Stream; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +@Tag("e2e") +@DisplayName("E2E tests for FullTeaching Login Session") +class CTeacherCreatesCourseTest 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 CTeacherCreatesCourseTest() { + super(); + } + + public static Stream data() throws IOException { + return ParameterLoader.getTestUsers(); + } + + @AccessMode(resID = "loginservice", concurrency = 10, sharing = true, accessMode = "READONLY") + @AccessMode(resID = "openvidumock", concurrency = 10, sharing = true, accessMode = "NOACCESS") + @AccessMode(resID = "course", concurrency = 15, sharing = true, accessMode = "DYNAMIC") + @AccessMode(resID = "executor", concurrency = 1, accessMode = "READWRITE") + @AccessMode(resID = "webbrowser", concurrency = 1, accessMode = "READWRITE") + @AccessMode(resID = "webserver", concurrency = 1, accessMode = "READWRITE") + void teacherCreateAndDeletecourseTest (String mail, String password, String role) throws ElementNotFoundException { + // Setup + this.slowLogin(user, mail, password); + + // Create a new course + String courseTitle = "Test Course_" + System.currentTimeMillis(); + CourseNavigationUtilities.newCourse(user.getDriver(), courseTitle); + //TO-DO the problem its here + // Verify the course has been created + assertTrue(checkIfCourseExists(driver, courseTitle)); + + // Delete the course + CourseNavigationUtilities.deleteCourse(user.getDriver(), courseTitle); + + // Verify the course has been deleted + assertFalse(checkIfCourseExists(driver, courseTitle)); + + // Teardown + user.getDriver().get(APP_URL); + } + @ParameterizedTest + @MethodSource("data") + void teacherCreateCourseFS4oTest(String mail, String password, String role) { + this.slowLogin(user, mail, password); + + try { + // Navigate to the dashboard + NavigationUtilities.toDashboard(driver); + + // Click on the "Create Course" button + WebElement createCourseButton = driver.findElement(By.id("create-course-button")); + Click.element(driver, createCourseButton); + + // Enter course title + WebElement courseTitleInput = driver.findElement(By.id("course-title-input")); + courseTitleInput.sendKeys("New Course Title"); + + // Optionally upload an image + WebElement courseImageInput = driver.findElement(By.id("course-image-input")); + courseImageInput.sendKeys("/path/to/image.jpg"); + + // Click on the "Create Course" button + WebElement createCourseSubmitButton = driver.findElement(By.id("create-course-submit-button")); + Click.element(driver, createCourseSubmitButton); + + // Wait for the course to appear in the dashboard + Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(By.id("course-list"))); + + // Verify the new course appears in the teacher's dashboard + WebElement newCourse = driver.findElement(By.xpath("//div[contains(text(), 'New Course Title')]")); + assertTrue(newCourse.isDisplayed(), "New course is not displayed in the dashboard"); + + } catch (Exception e) { + fail("Failed to create a new course: " + e.getClass() + ": " + e.getLocalizedMessage()); + } + } + @ParameterizedTest + @MethodSource("data") + void teacherCreateCourseCOT4oTest(String mail, String password, String role) { + this.slowLogin(user, mail, password); + + try { + // Navigate to the dashboard + NavigationUtilities.toDashboard(driver); + + // Click on the "Create Course" button + WebElement createCourseButton = driver.findElement(By.id("create-course-button")); + Click.element(driver, createCourseButton); + + // Enter course title + WebElement courseTitleInput = driver.findElement(By.id("course-title-input")); + courseTitleInput.sendKeys("New Course Title"); + + // Optionally upload an image + WebElement courseImageInput = driver.findElement(By.id("course-image-input")); + courseImageInput.sendKeys("/path/to/image.jpg"); + + // Click on the "Create Course" button + WebElement createCourseSubmitButton = driver.findElement(By.id("create-course-submit-button")); + Click.element(driver, createCourseSubmitButton); + + // Wait for the course to appear in the dashboard + Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(By.id("course-list"))); + + // Verify the new course appears in the teacher's dashboard + WebElement newCourse = driver.findElement(By.xpath("//div[contains(text(), 'New Course Title')]")); + assertTrue(newCourse.isDisplayed(), "New course is not displayed in the dashboard"); + + } catch (Exception e) { + fail("Failed to create a new course: " + e.getClass() + ": " + e.getLocalizedMessage()); + } + } + @AccessMode(resID = "loginservice", concurrency = 10, sharing = true, accessMode = "READONLY") + @AccessMode(resID = "course", concurrency = 1, sharing = true, 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 teacherCreatesCourseFS4oMiniTest(String mail, String password, String role) { + // Log in with provided credentials + this.slowLogin(user, mail, password); + String courseTitle = "New Course Title"; + String courseImagePath = "path/to/image.jpg"; // Optional image path + + try { + // Navigate to course creation page + NavigationUtilities.toCourseCreationPage(driver); + + // Enter course title + WebElement titleInput = driver.findElement(By.id("courseTitleInput")); // Adjust the locator as necessary + titleInput.sendKeys(courseTitle); + + // Optionally upload an image + if (courseImagePath != null && !courseImagePath.isEmpty()) { + WebElement imageUploadInput = driver.findElement(By.id("courseImageUpload")); // Adjust the locator as necessary + imageUploadInput.sendKeys(courseImagePath); + } + + // Click on "Create Course" button + WebElement createCourseButton = driver.findElement(By.id("createCourseButton")); // Adjust the locator as necessary + Click.element(driver, createCourseButton); + + // Wait for the course to be created and displayed in the dashboard + Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[contains(text(), '" + courseTitle + "')]"))); // Adjust the locator as necessary + + // Verify that the new course appears in the teacher's dashboard + List courses = driver.findElements(By.xpath("//div[contains(@class, 'course-title')]")); // Adjust the locator as necessary + boolean courseCreated = courses.stream().anyMatch(course -> course.getText().equals(courseTitle)); + assertTrue(courseCreated, "The course was not created successfully and does not appear in the dashboard."); + + } catch (ElementNotFoundException notFoundException) { + fail("Failed to create course:: " + notFoundException.getClass() + ": " + notFoundException.getLocalizedMessage()); + } + } + + @Test + void teacherCreatesCourseCOT4oMiniTest() { + // Test data + String teacherEmail = "teacher@example.com"; // Replace with actual test data + String teacherPassword = "password"; // Replace with actual test data + String courseTitle = "Test Course Title"; // Replace with desired course title + String courseImagePath = "path/to/image.jpg"; // Replace with actual image path if needed + + // Step 1: Login as Teacher + this.slowLogin(user, teacherEmail, teacherPassword); + + // Step 2: Navigate to Course Creation Page + NavigationUtilities.toDashboard(driver); + Click.element(driver, By.id("create-course-button")); // Replace with actual button ID + + // Step 3: Fill in Course Details + WebElement titleInput = driver.findElement(By.id("course-title")); // Replace with actual input ID + titleInput.sendKeys(courseTitle); + + // Optional: Upload an image if applicable + if (courseImagePath != null && !courseImagePath.isEmpty()) { + WebElement imageUpload = driver.findElement(By.id("course-image-upload")); // Replace with actual upload ID + imageUpload.sendKeys(courseImagePath); + } + + Click.element(driver, By.id("create-course-submit")); // Replace with actual submit button ID + + // Step 4: Verify Course Creation + Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(By.id("dashboard"))); // Wait for dashboard to load + List courses = driver.findElements(By.className("course-title")); // Replace with actual class name + boolean courseCreated = courses.stream().anyMatch(course -> course.getText().equals(courseTitle)); + + Assertions.assertTrue(courseCreated, "The course was not created successfully."); + + // Step 5: Teardown + Click.element(driver, By.id("logout-button")); // Replace with actual logout button ID + } + +} diff --git a/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/llmexperimentation/CreateForumEntryTest.java b/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/llmexperimentation/CreateForumEntryTest.java deleted file mode 100644 index 5e24804..0000000 --- a/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/llmexperimentation/CreateForumEntryTest.java +++ /dev/null @@ -1,327 +0,0 @@ -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.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.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.WebElement; -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 CreateForumEntryTest 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 CreateForumEntryTest() { - super(); - } - - public static Stream data() throws IOException { - return ParameterLoader.getTestUsers(); - } - - /** - * This test get login and create a custom title and content with the current date. - * After that, navigate to course for access the forum section.In the forum creates - * a new entry with the previous created title and content. Secondly, we ensure that - * the entry was created correctly and ensures that there are only one comment that - * corresponds with the body of that entry. - */ - @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 = 1, sharing = false, accessMode = "READWRITE") - @ParameterizedTest - @MethodSource("data") - void forumNewEntryOriginalTest(String mail, String password, String role) {// 48+ 104 + 28 set up +13 lines teardown =193 - this.slowLogin(user, mail, password); //24 lines - 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); - log.info("Setting new entry title and content"); - 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; - log.info("Navigating to courses tab"); - try { - log.info("Navigating to courses tab"); - //navigate to courses. - if (NavigationUtilities.amINotHere(driver, COURSES_URL.replace("__HOST__", HOST))) { - NavigationUtilities.toCoursesHome(driver);//3lines - } - WebElement course = CourseNavigationUtilities.getCourseByName(driver, courseName);//14lines - log.info("Entering the course List"); - course.findElement(COURSE_LIST_COURSE_TITLE).click(); - - Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(By.id(TABS_DIV_ID))); - log.info("Entering the Forum"); - CourseNavigationUtilities.go2Tab(driver, FORUM_ICON); //4lines - assertTrue(ForumNavigationUtilities.isForumEnabled(CourseNavigationUtilities.getTabContent(driver, FORUM_ICON)), "Forum not activated"); //6lines - Wait.waitForPageLoaded(driver); - ForumNavigationUtilities.newEntry(driver, newEntryTitle, newEntryContent); //16lines - //Retorch Modification, this test fails due to the speed of the browser - Wait.waitForPageLoaded(driver); - //Check entry... Flake Here - WebElement newEntry = ForumNavigationUtilities.getEntry(driver, newEntryTitle);//16lines - Wait.waitForPageLoaded(driver); - assertEquals(newEntry.findElement(FORUM_ENTRY_LIST_ENTRY_USER).getText(), userName, "Incorrect user"); - Click.element(driver, newEntry.findElement(FORUM_ENTRY_LIST_ENTRY_TITLE)); - Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(FORUM_COMMENT_LIST)); - 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"); - //first comment should be the inserted while creating the entry - Wait.waitForPageLoaded(driver); - List comments = ForumNavigationUtilities.getComments(driver); - assertFalse(comments.size() < 1, "No comments on the entry"); - Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(FORUM_COMMENT_LIST)); - Wait.waitForPageLoaded(driver); - WebElement newComment = comments.get(0); - String commentContent = newComment.findElement(FORUM_COMMENT_LIST_COMMENT_CONTENT).getText(); - assertEquals(commentContent, newEntryContent, "Bad content of comment"); - Wait.waitForPageLoaded(driver); - String comment = newComment.findElement(FORUM_COMMENT_LIST_COMMENT_USER).getText(); - assertEquals(comment, userName, "Bad user in comment"); - } catch (ElementNotFoundException notFoundException) { - Assertions.fail("Failed to navigate to course forum:: " + notFoundException.getClass() + ": " + notFoundException.getLocalizedMessage()); - } - //Fix Flaky test Navigating to the mainpage to logout... - user.getDriver().get(APP_URL); - } - - /** - * This test logs in and creates a new forum entry with a custom title and content. - * After that, it verifies that the entry appears in the forum. - */ - @ParameterizedTest - @MethodSource("data") - @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") - void forumNewEntryFS4oTest(String mail, String password, String role) { - // Perform login - this.slowLogin(user, mail, password); - - // Get current time for unique entry - Calendar calendar = Calendar.getInstance(); - calendar.setTimeInMillis(System.currentTimeMillis()); - int year = calendar.get(Calendar.YEAR); - int month = calendar.get(Calendar.MONTH); - int day = calendar.get(Calendar.DAY_OF_MONTH); - int hour = calendar.get(Calendar.HOUR_OF_DAY); - int minute = calendar.get(Calendar.MINUTE); - int second = calendar.get(Calendar.SECOND); - - try { - // Navigate to courses - NavigationUtilities.toCoursesHome(driver); - - // Find and select course - WebElement course = CourseNavigationUtilities.getCourseByName(driver, COURSE_NAME); - course.findElement(COURSE_LIST_COURSE_TITLE).click(); - Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(By.id(TABS_DIV_ID))); - - // Go to forum tab - CourseNavigationUtilities.go2Tab(driver, FORUM_ICON); - assertTrue(ForumNavigationUtilities.isForumEnabled(CourseNavigationUtilities.getTabContent(driver, FORUM_ICON)), "Forum not activated"); - - // Create new entry - String entryTitle = String.format("New Entry Test %d%d%d%d%d%d", day, month, year, hour, minute, second); - String entryContent = String.format("This is the content written on %d of %s, %d:%d:%d", day, MONTHS[month], hour, minute, second); - ForumNavigationUtilities.newEntry(driver, entryTitle, entryContent); - - // Verify the new entry - WebElement entry = ForumNavigationUtilities.getEntry(driver, entryTitle); - assertNotNull(entry, "New entry not found"); - Click.element(driver, entry.findElement(FORUM_ENTRY_LIST_ENTRY_TITLE)); - WebElement entryContentElement = Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(FORUM_ENTRY_CONTENT)); - assertEquals(entryContent, entryContentElement.getText(), "Entry content does not match"); - - } catch (ElementNotFoundException e) { - fail("Failed to navigate to course forum: " + e.getClass() + ": " + e.getLocalizedMessage()); - } - } - - @ParameterizedTest - @MethodSource("data") - void createForumEntryCOT4oTest(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 - NavigationUtilities.toCoursesHome(driver); - List courses = CourseNavigationUtilities.getCoursesList(driver); - assertTrue(courses.size() > 0, "No courses in the list"); - - // Select a course and navigate to its forum - WebElement course = CourseNavigationUtilities.getCourseByName(driver, courseName); - course.findElement(COURSE_LIST_COURSE_TITLE).click(); - Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(By.id(TABS_DIV_ID))); - CourseNavigationUtilities.go2Tab(driver, FORUM_ICON); - assertTrue(ForumNavigationUtilities.isForumEnabled(CourseNavigationUtilities.getTabContent(driver, FORUM_ICON)), "Forum not activated"); - - // Create a new forum entry - 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); - - // Verify the new entry - WebElement entry = ForumNavigationUtilities.getEntry(driver, newEntryTitle); - assertNotNull(entry, "New entry not found"); - Click.element(driver, entry.findElement(FORUM_ENTRY_LIST_ENTRY_TITLE)); - Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(FORUM_COMMENT_LIST)); - String entryContent = entry.findElement(FORUM_ENTRY_LIST_ENTRY_CONTENT).getText(); - assertEquals(newEntryContent, entryContent, "Entry content does not match"); - - } catch (ElementNotFoundException notFoundException) { - fail("Failed to navigate to course forum:: " + notFoundException.getClass() + ": " + notFoundException.getLocalizedMessage()); - } - } - - @ParameterizedTest - @MethodSource("data") - @AccessMode(resID = "loginservice", concurrency = 10, sharing = true, accessMode = "READONLY") - @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") - void forumCreateEntryFS4oMiniTest(String mail, String password, String role) { - // Login with provided user credentials - this.slowLogin(user, mail, password); - - // Get the current date and time - 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 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 entry - String newEntryTitle = String.format("New Entry Test %d%d%d%d%d%d", mDay, mMonth, mYear, mHour, mMinute, mSecond); - String newEntryContent = String.format( - "This is the content of the new entry created on %d of %s, %d:%d,%d", - mDay, - months[mMonth], - mHour, - mMinute, - mSecond - ); - ForumNavigationUtilities.newEntry(driver, newEntryTitle, newEntryContent); - - // Verify the entry is created - List entriesList = ForumNavigationUtilities.getFullEntryList(driver); - assertTrue( - entriesList.contains(newEntryTitle), - "The new entry was not found in the forum entries list" - ); - - // Optionally, verify the content of the newly created entry - WebElement createdEntry = ForumNavigationUtilities.getEntry(driver, newEntryTitle); - Click.element(driver, createdEntry.findElement(FORUM_ENTRY_LIST_ENTRY_TITLE)); - Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(FORUM_COMMENT_LIST)); - String displayedContent = driver.findElement(FORUM_ENTRY_CONTENT).getText(); - assertEquals( - newEntryContent, - displayedContent, - "The content of the entry does not match the expected content" - ); - - } catch (ElementNotFoundException notFoundException) { - fail( - "Failed to navigate to course forum:: " + notFoundException.getClass() + ": " + notFoundException.getLocalizedMessage() - ); - } - } - - @Test - void createForumEntryCOT4oMiniTest() { - // Step 1: User Login - this.slowLogin(user, "testuser@example.com", "password123"); - - // Step 2: Navigate to Courses - NavigationUtilities.toCoursesHome(driver); - Assertions.assertTrue(CourseNavigationUtilities.getCoursesList(driver).size() > 0, "No courses available"); - - // Step 3: Select a Course - WebElement course = CourseNavigationUtilities.getCourseByName(driver, courseName); - Click.element(driver, course.findElement(By.cssSelector(".course-title"))); // Assuming .course-title is the selector - Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(By.id("tabsDivId"))); // Replace with actual ID - - // Step 4: Navigate to Forum - CourseNavigationUtilities.go2Tab(driver, "forumIcon"); // Replace with actual forum icon identifier - Assertions.assertTrue(ForumNavigationUtilities.isForumEnabled(CourseNavigationUtilities.getTabContent(driver, "forumIcon")), "Forum not activated"); - - // Step 5: Create a New Forum Entry - Click.element(driver, driver.findElement(By.id("newEntryButton"))); // Replace with actual button ID - String newEntryTitle = "Test Entry Title"; - String newEntryContent = "This is a test entry content."; - driver.findElement(By.id("entryTitleField")).sendKeys(newEntryTitle); // Replace with actual field ID - driver.findElement(By.id("entryContentField")).sendKeys(newEntryContent); // Replace with actual field ID - Click.element(driver, driver.findElement(By.id("submitEntryButton"))); // Replace with actual submit button ID - - // Step 6: Verify Entry Creation - Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(By.id("forumEntriesList"))); // Replace with actual ID - Assertions.assertTrue(ForumNavigationUtilities.getFullEntryList(driver).contains(newEntryTitle), "New entry not found in the forum"); - } - -} diff --git a/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/llmexperimentation/CreateNewCommentTest.java b/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/llmexperimentation/CreateNewCommentTest.java deleted file mode 100644 index 855d70f..0000000 --- a/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/llmexperimentation/CreateNewCommentTest.java +++ /dev/null @@ -1,361 +0,0 @@ -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 CreateNewCommentTest 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 CreateNewCommentTest() { - super(); - } - - public static Stream data() throws IOException { - return ParameterLoader.getTestUsers(); - } - - /** - * This test get login and create a custom title and content with the current date. - * After that, navigate to course for access the forum section.If in the forum - * there are not any entries create a new entry and gets into it.In the other hand - * if there are any created previously entry get into the first of them. Secondly, - * once we are into the entry, we look for the new comment button, making a new comment - * in this entry with the custom content(the current date and hour).Finally, we iterate - * over all comments looking for the comment that previously we create. - */ - @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 = 1, sharing = false, accessMode = "READWRITE") - @ParameterizedTest - @MethodSource("data") - void forumNewCommentOriginalTest(String mail, String password, String role) { // 69+142 + 28 set up +13 lines teardown =252 - this.slowLogin(user, mail, password); //24 lines - 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 { - //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))); - CourseNavigationUtilities.go2Tab(driver, FORUM_ICON);//4lines - assertTrue(ForumNavigationUtilities.isForumEnabled(CourseNavigationUtilities.getTabContent(driver, FORUM_ICON)), "Forum not activated");//6lines - List entries_list = ForumNavigationUtilities.getFullEntryList(driver);//6lines - WebElement entry; - if (entries_list.size() <= 0) {//if not new entry - String 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);//16lines - entry = ForumNavigationUtilities.getEntry(driver, newEntryTitle);//16lines - } else { - entry = ForumNavigationUtilities.getEntry(driver, entries_list.get(0));//16lines - } - //go to entry - Click.element(driver, entry.findElement(FORUM_ENTRY_LIST_ENTRY_TITLE)); - WebElement commentList = Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(FORUM_COMMENT_LIST)); - //counting the number of numberComments - int numberCommentsOld = ForumNavigationUtilities.getComments(driver).size(); - //new comment - 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); - - Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(FORUM_COMMENT_LIST)); - //TO-DO think in other better way to solve this problem - Wait.waitForPageLoaded(driver); - user.waitUntil(ExpectedConditions.visibilityOfElementLocated(FORUM_COMMENT_LIST_COMMENT), "The comment list are not visible"); - user.waitUntil((ExpectedCondition) driver -> { - int elementCount = ForumNavigationUtilities.getComments(driver).size(); - return elementCount > numberCommentsOld; - }, "Comment not attached"); - List comments = ForumNavigationUtilities.getComments(driver); - //asserts - assertTrue(comments.size() > numberCommentsOld, "Comment list empty or only original comment"); - - user.waitUntil(ExpectedConditions.visibilityOfElementLocated(FORUM_COMMENT_LIST_COMMENT), "The comment list are not visible"); - - boolean commentFound = false; - for (WebElement comment : comments) { - //check if it is new comment - 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 (StaleElementReferenceException e) { - log.info("Not Found"); - } - } - assertTrue(commentFound, "Comment not found"); - } catch (ElementNotFoundException notFoundException) { - fail("Failed to navigate to course forum:: " + notFoundException.getClass() + ": " + notFoundException.getLocalizedMessage()); - } - - } - @ParameterizedTest - @MethodSource("data") - @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") - void forumNewCommentFS4oTest(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); - String newCommentContent = "New Comment Test " + mDay + mMonth + mYear + mHour + mMinute + mSecond; - - try { - // Navigate to courses - NavigationUtilities.toCoursesHome(driver); - List courses = CourseNavigationUtilities.getCoursesList(driver); - assertTrue(courses.size() > 0, "No courses in the list"); - - // Select the first course - WebElement course = CourseNavigationUtilities.getCourseByName(driver, courses.get(0)); - course.findElement(COURSE_LIST_COURSE_TITLE).click(); - Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(By.id(TABS_DIV_ID))); - - // Navigate to the forum tab - CourseNavigationUtilities.go2Tab(driver, FORUM_ICON); - assertTrue(ForumNavigationUtilities.isForumEnabled(CourseNavigationUtilities.getTabContent(driver, FORUM_ICON)), "Forum not activated"); - - // Select the first forum entry - List entriesList = ForumNavigationUtilities.getFullEntryList(driver); - assertTrue(entriesList.size() > 0, "No forum entries found"); - WebElement entry = ForumNavigationUtilities.getEntry(driver, entriesList.get(0)); - Click.element(driver, entry.findElement(FORUM_ENTRY_LIST_ENTRY_TITLE)); - Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(FORUM_COMMENT_LIST)); - - // Post a new comment - WebElement commentField = driver.findElement(FORUM_COMMENT_LIST_NEW_COMMENT_TEXT_FIELD); - commentField.sendKeys(newCommentContent); - Click.element(driver, FORUM_NEW_COMMENT_MODAL_POST_BUTTON); - - // Verify the comment is posted - Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(FORUM_COMMENT_LIST)); - List comments = ForumNavigationUtilities.getComments(driver); - assertFalse(comments.isEmpty(), "No comments found"); - WebElement newComment = comments.get(comments.size() - 1); - assertEquals(newComment.findElement(FORUM_COMMENT_LIST_COMMENT_CONTENT).getText(), newCommentContent, "Comment content mismatch"); - assertEquals(newComment.findElement(FORUM_COMMENT_LIST_COMMENT_USER).getText(), userName, "Comment user mismatch"); - - } catch (ElementNotFoundException notFoundException) { - Assertions.fail("Failed to navigate to course forum:: " + notFoundException.getClass() + ": " + notFoundException.getLocalizedMessage()); - } - } - @ParameterizedTest - @MethodSource("data") - void createNewCommentCOT4oTest(String mail, String password, String role) { - this.slowLogin(mail, password); - - try { - // Navigate to courses - NavigationUtilities.toCoursesHome(driver); - List courses = CourseNavigationUtilities.getCoursesList(driver); - assertTrue(courses.size() > 0, "No courses in the list"); - - // Select a course with forum enabled - WebElement course = CourseNavigationUtilities.getCourseByName(driver, courses.get(0)); - course.findElement(COURSE_LIST_COURSE_TITLE).click(); - Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(By.id(TABS_DIV_ID))); - CourseNavigationUtilities.go2Tab(driver, FORUM_ICON); - assertTrue(ForumNavigationUtilities.isForumEnabled(CourseNavigationUtilities.getTabContent(driver, FORUM_ICON)), "Forum not activated"); - - // Check for existing entries or create a new one - List entriesList = ForumNavigationUtilities.getFullEntryList(driver); - WebElement entry; - if (entriesList.size() <= 0) { - String newEntryTitle = "Test Entry"; - String newEntryContent = "This is a test entry content."; - ForumNavigationUtilities.newEntry(driver, newEntryTitle, newEntryContent); - entry = ForumNavigationUtilities.getEntry(driver, newEntryTitle); - } else { - entry = ForumNavigationUtilities.getEntry(driver, entriesList.get(0)); - } - - // Add a new comment - Click.element(driver, entry.findElement(FORUM_ENTRY_LIST_ENTRY_TITLE)); - Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(FORUM_COMMENT_LIST)); - String newCommentContent = "This is a test comment."; - ForumNavigationUtilities.newComment(driver, newCommentContent); - - // Verify the comment is added - List comments = ForumNavigationUtilities.getComments(driver); - assertFalse(comments.isEmpty(), "No comments found"); - WebElement newComment = comments.get(comments.size() - 1); - assertEquals(newComment.findElement(FORUM_COMMENT_LIST_COMMENT_CONTENT).getText(), newCommentContent, "Comment content mismatch"); - assertEquals(newComment.findElement(FORUM_COMMENT_LIST_COMMENT_USER).getText(), userName, "Comment user mismatch"); - - } 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 userCreateNewCommentInForumFS4oMiniTest(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); - - String newEntryTitle = "New Comment Test Entry " + mDay + mMonth + mYear + mHour + mMinute + mSecond; - String newEntryContent = "This is the content for the new entry created on " + mDay + " of " + months[mMonth] + - ", " + mHour + ":" + mMinute + "," + mSecond; - String newCommentContent = "This is a new comment added on " + mDay + " of " + months[mMonth] + - ", " + mHour + ":" + mMinute + "," + mSecond; - - try { - // Navigate to courses. - NavigationUtilities.toCoursesHome(driver); - 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 forum tab and check if it's enabled - CourseNavigationUtilities.go2Tab(driver, FORUM_ICON); - assertTrue(ForumNavigationUtilities.isForumEnabled(CourseNavigationUtilities.getTabContent(driver, FORUM_ICON)), - "Forum not activated"); - - // Create a new entry if no entries exist - List entriesList = ForumNavigationUtilities.getFullEntryList(driver); - if (entriesList.size() <= 0) { - ForumNavigationUtilities.newEntry(driver, newEntryTitle, newEntryContent); - } - - // Go to the first entry - WebElement entry = ForumNavigationUtilities.getEntry(driver, entriesList.get(0)); - Click.element(driver, entry.findElement(FORUM_ENTRY_LIST_ENTRY_TITLE)); - Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(FORUM_COMMENT_LIST)); - - // Add a new comment - Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(FORUM_COMMENT_LIST_MODAL_NEW_COMMENT)); - WebElement commentTextField = driver.findElement(FORUM_COMMENT_LIST_MODAL_NEW_COMMENT_TEXT_FIELD); - commentTextField.sendKeys(newCommentContent); - Click.element(driver, FORUM_NEW_COMMENT_MODAL_POST_BUTTON); - - // Wait for the comment to be visible and verify it - user.waitUntil(ExpectedConditions.visibilityOfElementLocated(FORUM_COMMENT_LIST), - "The comments are not visible"); - List comments = ForumNavigationUtilities.getComments(driver); - boolean commentFound = false; - - for (WebElement comment : comments) { - String commentContent = comment.findElement(FORUM_COMMENT_LIST_COMMENT_CONTENT).getText(); - if (commentContent.equals(newCommentContent)) { - commentFound = true; - break; - } - } - - assertTrue(commentFound, "The new comment was not found in the forum."); - } 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 forumNewCommentCOT4oMiniTest(String mail, String password, String role) { - this.slowLogin(user, mail, password); // Step 1: User Login - String commentContent = "This is a test comment for the forum."; - - try { - // Step 2: Navigate to Courses - NavigationUtilities.toCoursesHome(driver); - - // Step 3: Select a Course - WebElement course = CourseNavigationUtilities.getCourseByName(driver, courseName); - course.findElement(COURSE_LIST_COURSE_TITLE).click(); - - // Step 4: Access the Forum - Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(By.id(TABS_DIV_ID))); - CourseNavigationUtilities.go2Tab(driver, FORUM_ICON); - - // Step 5: Check Forum Activation - assertTrue(ForumNavigationUtilities.isForumEnabled(CourseNavigationUtilities.getTabContent(driver, FORUM_ICON)), "Forum not activated"); - - // Step 6: Create a New Comment - WebElement commentBox = driver.findElement(FORUM_NEW_COMMENT_TEXT_FIELD); - commentBox.sendKeys(commentContent); - Click.element(driver, FORUM_NEW_COMMENT_SUBMIT_BUTTON); - - // Step 7: Verify Comment Submission - Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(FORUM_COMMENT_LIST)); - List comments = ForumNavigationUtilities.getComments(driver); - boolean commentFound = comments.stream() - .anyMatch(comment -> comment.getText().equals(commentContent)); - assertTrue(commentFound, "The new comment was not found in the forum."); - - } catch (ElementNotFoundException notFoundException) { - fail("Failed to navigate to course forum:: " + notFoundException.getClass() + ": " + notFoundException.getLocalizedMessage()); - } - } - - -} diff --git a/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/llmexperimentation/DUserAccessCalendarTest.java b/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/llmexperimentation/DUserAccessCalendarTest.java new file mode 100644 index 0000000..7c8501e --- /dev/null +++ b/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/llmexperimentation/DUserAccessCalendarTest.java @@ -0,0 +1,203 @@ +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.ParameterLoader; +import com.fullteaching.e2e.no_elastest.utils.Wait; +import giis.retorch.annotations.AccessMode; +import giis.retorch.annotations.Resource; +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.WebElement; +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 DUserAccessCalendarTest 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 DUserAccessCalendarTest() { + super(); + } + + public static Stream data() throws IOException { + return ParameterLoader.getTestUsers(); + } + + @AccessMode(resID = "loginservice", concurrency = 10, sharing = true, accessMode = "READONLY") + @AccessMode(resID = "openvidumock", concurrency = 10, sharing = true, accessMode = "NOACCESS") + @AccessMode(resID = "course", concurrency = 15, sharing = true, accessMode = "READONLY") + @AccessMode(resID = "executor", concurrency = 1, accessMode = "READWRITE") + @AccessMode(resID = "webbrowser", concurrency = 1, accessMode = "READWRITE") + @AccessMode(resID = "webserver", concurrency = 1, accessMode = "READWRITE") + void teachercourseMainTest(String mail, String password, String role) { + this.slowLogin(user, mail, password); + try { + + NavigationUtilities.toCoursesHome(driver); //4lines + Wait.notTooMuch(driver).until(ExpectedConditions.presenceOfElementLocated(By.xpath(FIRST_COURSE_XPATH))); + Click.element(driver, By.xpath(FIRST_COURSE_XPATH)); + Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(By.id(TABS_DIV_ID))); + } catch (Exception e) { + fail("Failed to load Courses Tabs" + e.getClass() + ": " + e.getLocalizedMessage()); + } + //Check tabs + //Home tab + try { + CourseNavigationUtilities.go2Tab(driver, HOME_ICON); //4lines + } catch (Exception e) { + fail("Failed to load home tab" + e.getClass() + ": " + e.getLocalizedMessage()); + } + try { + CourseNavigationUtilities.go2Tab(driver, SESSION_ICON); //4lines + } catch (Exception e) { + fail("Failed to load session tab" + e.getClass() + ": " + e.getLocalizedMessage()); + } + try { + CourseNavigationUtilities.go2Tab(driver, FORUM_ICON); //4lines + } catch (Exception e) { + fail("Failed to load forum tab" + e.getClass() + ": " + e.getLocalizedMessage()); + } + try { + CourseNavigationUtilities.go2Tab(driver, FILES_ICON); //4lines + } catch (Exception e) { + fail("Failed to load files tab" + e.getClass() + ": " + e.getLocalizedMessage()); + } + try { + CourseNavigationUtilities.go2Tab(driver, ATTENDERS_ICON); //4lines + } catch (Exception e) { + fail("Failed to load attenders tab" + e.getClass() + ": " + e.getLocalizedMessage()); + } + } + @AccessMode(resID = "loginservice", concurrency = 10, sharing = true, accessMode = "READONLY") + @AccessMode(resID = "calendarservice", concurrency = 10, sharing = true, accessMode = "READONLY") + @AccessMode(resID = "webbrowser", concurrency = 1, accessMode = "READWRITE") + @AccessMode(resID = "webserver", concurrency = 1, accessMode = "READWRITE") + @ParameterizedTest + @MethodSource("data") + void userAccessCalendarFS4oTest(String mail, String password, String role) { + this.slowLogin(mail, password); + try { + // Navigate to the calendar page + NavigationUtilities.toCalendarPage(driver); + Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(By.id("calendar"))); + + // Verify that the calendar displays all the user's classes + List classes = driver.findElements(By.cssSelector(".calendar-class")); + assertTrue(classes.size() > 0, "No classes found in the calendar"); + + } catch (Exception e) { + fail("Failed to access the calendar: " + e.getClass() + ": " + e.getLocalizedMessage()); + } + } + @ParameterizedTest + @MethodSource("data") + void userCanAccessAndViewCalendarCOT4oTest(String mail, String password, String role) { + this.slowLogin(mail, password); + + try { + // Navigate to the calendar page + NavigationUtilities.toCalendarPage(driver); + Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(By.id("calendar"))); + + // Verify that the calendar is displayed + WebElement calendar = driver.findElement(By.id("calendar")); + assertTrue(calendar.isDisplayed(), "Calendar is not displayed"); + + // Verify that the calendar displays all the user's classes + List classes = calendar.findElements(By.className("calendar-class")); + assertTrue(classes.size() > 0, "No classes are displayed on the calendar"); + + for (WebElement calendarClass : classes) { + assertTrue(calendarClass.isDisplayed(), "Class is not displayed correctly on the calendar"); + } + + } catch (Exception e) { + fail("Failed to access and view the calendar: " + e.getMessage()); + } finally { + // Teardown + driver.get(APP_URL); + } + } + @AccessMode(resID = "loginservice", concurrency = 10, sharing = true, accessMode = "READONLY") + @AccessMode(resID = "calendar", concurrency = 1, sharing = true, accessMode = "READONLY") + @ParameterizedTest + @MethodSource("data") + @DisplayName("User Accessing Calendar Test") + void userAccessingCalendarFS4oMiniTest(String mail, String password, String role) { + // Step 1: User logs into the application + this.slowLogin(user, mail, password); + + try { + // Step 2: User navigates to the calendar page + NavigationUtilities.toCalendarPage(driver); + + // Step 3: System displays a calendar with all the user's classes + List calendarEntries = driver.findElements(By.className("calendar-entry")); // Assuming 'calendar-entry' is the class for calendar entries + assertFalse(calendarEntries.isEmpty(), "The calendar should display at least one class entry."); + + // Additional assertions can be added here to verify the content of the calendar entries + for (WebElement entry : calendarEntries) { + assertNotNull(entry.findElement(By.className("class-title")), "Class title should be present in the calendar entry."); + // You can add more checks for date, time, etc. based on your application structure + } + + } catch (ElementNotFoundException notFoundException) { + fail("Failed to navigate to the calendar page:: " + notFoundException.getClass() + ": " + notFoundException.getLocalizedMessage()); + } finally { + // Teardown: Logout or navigate back to the main page + user.getDriver().get(APP_URL); + } + } + + @ParameterizedTest + @MethodSource("data") + void userCanAccessAndViewCalendarCOT4MiniTest(String mail, String password, String role) { + // Step 1: User logs into the application + this.slowLogin(user, mail, password); + + try { + // Step 2: User navigates to the calendar page + NavigationUtilities.toCalendarPage(driver); + + // Step 3: Verify calendar display + Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(By.id(CALENDAR_ID))); + WebElement calendar = driver.findElement(By.id(CALENDAR_ID)); + assertTrue(calendar.isDisplayed(), "Calendar is not displayed"); + + // Step 4: Check that the calendar shows all the user's classes + List classes = calendar.findElements(By.className(CLASS_ITEM_CLASS)); + assertTrue(classes.size() > 0, "No classes found in the calendar"); + + // Optionally, you can validate the class details here + // For example, check if the classes match expected classes for the user + + } catch (Exception e) { + Assertions.fail("Failed to access and view the calendar: " + e.getMessage()); + } finally { + // Step 5: Teardown if necessary + user.getDriver().get(APP_URL); // Navigate back to the main page or logout + } + } + +}