From 36a79b7e3e452069d4e960dd530f59c7429ea612 Mon Sep 17 00:00:00 2001 From: Augusto Date: Mon, 29 Jul 2024 15:40:53 +0200 Subject: [PATCH] LLM output test cases --- .../AViewEnrolledCoursesTest.java | 227 +++++++++++++++ .../BViewCourseClassesTest.java | 264 ++++++++++++++++++ .../CTeacherCreatesCourseTest.java | 210 ++++++++++++++ .../DUserAccessCalendarTest.java | 203 ++++++++++++++ 4 files changed, 904 insertions(+) create mode 100644 src/test/java/com/fullteaching/e2e/no_elastest/functional/test/llmexperimentation/AViewEnrolledCoursesTest.java create mode 100644 src/test/java/com/fullteaching/e2e/no_elastest/functional/test/llmexperimentation/BViewCourseClassesTest.java create mode 100644 src/test/java/com/fullteaching/e2e/no_elastest/functional/test/llmexperimentation/CTeacherCreatesCourseTest.java create mode 100644 src/test/java/com/fullteaching/e2e/no_elastest/functional/test/llmexperimentation/DUserAccessCalendarTest.java 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/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 + } + } + +}