diff --git a/src/test/java/com/fullteaching/e2e/no_elastest/common/BaseLoggedTest.java b/src/test/java/com/fullteaching/e2e/no_elastest/common/BaseLoggedTest.java index 02718ec..02a1d81 100644 --- a/src/test/java/com/fullteaching/e2e/no_elastest/common/BaseLoggedTest.java +++ b/src/test/java/com/fullteaching/e2e/no_elastest/common/BaseLoggedTest.java @@ -21,18 +21,15 @@ import java.io.FileInputStream; import java.io.IOException; import java.util.Date; +import java.util.List; import java.util.Properties; import static com.fullteaching.e2e.no_elastest.common.Constants.*; -import static java.lang.invoke.MethodHandles.lookup; import static org.openqa.selenium.logging.LogType.BROWSER; -import static org.slf4j.LoggerFactory.getLogger; public class BaseLoggedTest { public static final String CHROME = "chrome"; - // For use another host - //protected static final String host= SetUp.getHost(); public static final String FIREFOX = "firefox"; public static final String EDGE = "edge"; public static final Logger log = LoggerFactory.getLogger(BaseLoggedTest.class); @@ -41,7 +38,6 @@ public class BaseLoggedTest { public static String TEACHER_BROWSER; public static String STUDENT_BROWSER; public static String BROWSER_NAME; - public static String course_title; protected static String HOST = LOCALHOST; protected static String userName; protected static String userMail; @@ -52,7 +48,9 @@ public class BaseLoggedTest { protected final static int DEPTH = 3; public WebDriver driver; - protected BrowserUser user; + protected BrowserUser teacher; + protected BrowserUser student; + protected List studentBrowserUserList; public BaseLoggedTest() { } @@ -66,7 +64,7 @@ static void setupAll() { // 28 lines // Load a properties file for reading properties.load(new FileInputStream("src/test/resources/inputs/test.properties")); } catch (IOException ex) { - ex.printStackTrace(); // Consider logging the exception instead of printing the stack trace + log.error("Properties file could not be loaded"); } // Check if running outside ElasTest @@ -85,7 +83,7 @@ static void setupAll() { // 28 lines TJOB_NAME = envTJobName; PORT = envPort; APP_URL = envUrl + TJOB_NAME + ":" + PORT + "/"; - log.debug("The URL is" + APP_URL); + log.debug("The URL is {}" , APP_URL); HOST = APP_URL; } else { // Check if app.url system property is defined @@ -110,14 +108,13 @@ static void setupAll() { // 28 lines @BeforeEach void setup(TestInfo info) { //65 lines - if (info.getTestMethod().isPresent()) { - TEST_NAME = info.getTestMethod().get().getName(); - } - log.info("##### Start test: " + TEST_NAME); + log.info("##### Start test: {}" , info.getDisplayName()); TJOB_NAME = System.getProperty("dirtarget"); - user = setupBrowser("chrome", TJOB_NAME + "_" + TEST_NAME, userMail, WAIT_SECONDS); - driver = user.getDriver(); + teacher = setupBrowser("chrome", TJOB_NAME + "_" + info.getDisplayName()+"-TEACHER", userMail, WAIT_SECONDS); + + driver = teacher.getDriver(); + } protected BrowserUser setupBrowser(String browser, String testName, @@ -161,19 +158,41 @@ protected BrowserUser setupBrowser(String browser, String testName, @AfterEach void tearDown(TestInfo testInfo) { //13 lines + if (this.teacher != null) { + log.info("##### Finish test: {} - Driver {}", testInfo.getDisplayName(), this.teacher.getDriver()); + log.info("Browser console at the end of the test"); + LogEntries logEntries = teacher.getDriver().manage().logs().get(BROWSER); + logEntries.forEach(entry -> log.info("[{}] {} {}", + new Date(entry.getTimestamp()), entry.getLevel(), + entry.getMessage())); + if (this.teacher.isOnSession()) { + this.logout(this.teacher); + } + + this.teacher.dispose(); + } - if (user != null) { - log.info("##### Finish test: {} - Driver {}", TEST_NAME, this.user.getDriver()); + if (this.student != null) { + log.info("##### Finish test: {} - Driver {}", testInfo.getDisplayName(), this.student.getDriver()); log.info("Browser console at the end of the test"); - LogEntries logEntries = user.getDriver().manage().logs().get(BROWSER); - logEntries.forEach((entry) -> log.info("[{}] {} {}", + LogEntries logEntries = student.getDriver().manage().logs().get(BROWSER); + logEntries.forEach(entry -> log.info("[{}] {} {}", new Date(entry.getTimestamp()), entry.getLevel(), entry.getMessage())); - if (user.isOnSession()) { - this.logout(user); + //TO-DO- ERROR with the logout + if (this.student.isOnSession()) { + this.logout(student); } - user.dispose(); + student.dispose();} + //Logout and exit list of Students + if (this.studentBrowserUserList!=null) { + for (BrowserUser memberStudent : this.studentBrowserUserList) { + if (memberStudent.isOnSession()) { + this.logout(memberStudent); + } + memberStudent.dispose(); + } } } @@ -233,10 +252,9 @@ private void login(BrowserUser user, String userEmail, String userPass, } protected void logout(BrowserUser user) { //43 lines - // log.info("Logging out {}", user.getClientData()); + log.info("Logging out {}", user.getClientData()); - if (user.getDriver().findElements(By.cssSelector("#fixed-icon")) - .size() > 0) { + if (!user.getDriver().findElements(By.cssSelector("#fixed-icon")).isEmpty()) { // Get out of video session page if (!isClickable("#exit-icon", user)) { // Side menu not opened user.getDriver().findElement(By.cssSelector("#fixed-icon")) @@ -347,7 +365,7 @@ protected void waitSeconds(int seconds) { try { Thread.sleep(1000L * seconds); } catch (InterruptedException e) { - e.printStackTrace(); + log.error("Thread.sleep interrupted"); } } @@ -372,14 +390,14 @@ public String getUserName(BrowserUser user, boolean goBack, String host) throws WebElement name_placeholder = Wait.notTooMuch(user.getDriver()).until(ExpectedConditions.visibilityOfElementLocated(By.xpath(USERNAME_XPATH))); - String userName = name_placeholder.getText().trim(); + String userNameTag = name_placeholder.getText().trim(); if (goBack) { user.getDriver().navigate().back(); } //Check if the username is the expected log.info("[END] getUserName"); - return userName; + return userNameTag; } diff --git a/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/LoggedForumTest.java b/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/LoggedForumTest.java index 7a67ec6..74fa4d9 100644 --- a/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/LoggedForumTest.java +++ b/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/LoggedForumTest.java @@ -23,7 +23,6 @@ import org.openqa.selenium.WebElement; import org.openqa.selenium.support.ui.ExpectedCondition; import org.openqa.selenium.support.ui.ExpectedConditions; -import org.slf4j.Logger; import java.io.IOException; import java.util.Calendar; @@ -31,9 +30,7 @@ import java.util.stream.Stream; import static com.fullteaching.e2e.no_elastest.common.Constants.*; -import static java.lang.invoke.MethodHandles.lookup; import static org.junit.jupiter.api.Assertions.*; -import static org.slf4j.LoggerFactory.getLogger; @Tag("e2e") @@ -69,12 +66,12 @@ public static Stream data() throws IOException { @ParameterizedTest @MethodSource("data") void forumLoadEntriesTest(String mail, String password, String role) { //47lines +115 +28 set up +13 lines teardown =203 - this.slowLogin(user, mail, password);//24 lines + this.slowLogin(teacher, mail, password);//24 lines try { //navigate to courses. NavigationUtilities.toCoursesHome(driver);//3lines List courses = CourseNavigationUtilities.getCoursesList(driver);//13lines - assertTrue(courses.size() > 0, "No courses in the list"); + assertFalse(courses.isEmpty(), "No courses in the list"); //find course with forum activated boolean activated_forum_on_some_test = false; boolean has_comments = false; @@ -92,7 +89,7 @@ void forumLoadEntriesTest(String mail, String password, String role) { //47lines log.info("Loading the entries list"); //Load list of entries List entries_list = ForumNavigationUtilities.getFullEntryList(driver);//6lines - if (entries_list.size() > 0) { + if (!entries_list.isEmpty()) { //Go into first entry for (String entry_name : entries_list) { log.info("Checking the entry with name: {}", entry_name); @@ -102,7 +99,7 @@ void forumLoadEntriesTest(String mail, String password, String role) { //47lines 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) { + if (!comments.isEmpty()) { has_comments = true; log.info("Comments found, saving them"); @@ -137,7 +134,7 @@ void forumLoadEntriesTest(String mail, String password, String role) { //47lines @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 + this.slowLogin(teacher, mail, password); //24 lines Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); int mYear = calendar.get(Calendar.YEAR); @@ -180,7 +177,7 @@ void forumNewEntryTest(String mail, String password, String role) {// 48+ 104 + //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"); + assertFalse(comments.isEmpty(), "No comments on the entry"); Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(FORUM_COMMENT_LIST)); Wait.waitForPageLoaded(driver); WebElement newComment = comments.get(0); @@ -193,7 +190,7 @@ void forumNewEntryTest(String mail, String password, String role) {// 48+ 104 + 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); + teacher.getDriver().get(APP_URL); } /** @@ -214,7 +211,7 @@ void forumNewEntryTest(String mail, String password, String role) {// 48+ 104 + @ParameterizedTest @MethodSource("data") void forumNewCommentTest(String mail, String password, String role) { // 69+142 + 28 set up +13 lines teardown =252 - this.slowLogin(user, mail, password); //24 lines + this.slowLogin(teacher, mail, password); //24 lines Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); int mYear = calendar.get(Calendar.YEAR); @@ -260,8 +257,8 @@ void forumNewCommentTest(String mail, String password, String role) { // 69+142 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 -> { + teacher.waitUntil(ExpectedConditions.visibilityOfElementLocated(FORUM_COMMENT_LIST_COMMENT), "The comment list are not visible"); + teacher.waitUntil((ExpectedCondition) driver -> { int elementCount = ForumNavigationUtilities.getComments(driver).size(); return elementCount > numberCommentsOld; }, "Comment not attached"); @@ -269,7 +266,7 @@ void forumNewCommentTest(String mail, String password, String role) { // 69+142 //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"); + teacher.waitUntil(ExpectedConditions.visibilityOfElementLocated(FORUM_COMMENT_LIST_COMMENT), "The comment list are not visible"); boolean commentFound = false; for (WebElement comment : comments) { @@ -309,7 +306,7 @@ void forumNewCommentTest(String mail, String password, String role) { // 69+142 @Resource(resID = "Course", replaceable = {"Forum"}) @AccessMode(resID = "Course", concurrency = 1, sharing = false, accessMode = "READWRITE") void forumNewReply2CommentTest(String mail, String password, String role) { // 63+137+ 28 set up +13 lines teardown = 242 - this.slowLogin(user, mail, password);//24 lines + this.slowLogin(teacher, mail, password);//24 lines Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); int mYear = calendar.get(Calendar.YEAR); @@ -350,14 +347,14 @@ void forumNewReply2CommentTest(String mail, String password, String role) { // 6 Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(FORUM_COMMENT_LIST_MODAL_NEW_REPLY)); WebElement textField = driver.findElement(FORUM_COMMENT_LIST_MODAL_NEW_REPLY_TEXT_FIELD); textField.sendKeys(newReplyContent); - Click.element(user.getDriver(), FORUM_NEW_COMMENT_MODAL_POST_BUTTON); + Click.element(teacher.getDriver(), FORUM_NEW_COMMENT_MODAL_POST_BUTTON); - user.waitUntil(ExpectedConditions.visibilityOfElementLocated(FORUM_COMMENT_LIST), "The comments are not visible"); + teacher.waitUntil(ExpectedConditions.visibilityOfElementLocated(FORUM_COMMENT_LIST), "The comments are not visible"); - user.waitUntil(ExpectedConditions.visibilityOfElementLocated(FORUM_COMMENT_LIST_COMMENT), "The comment list are not visible"); - comments = ForumNavigationUtilities.getComments(user.getDriver()); //2lines + teacher.waitUntil(ExpectedConditions.visibilityOfElementLocated(FORUM_COMMENT_LIST_COMMENT), "The comment list are not visible"); + comments = ForumNavigationUtilities.getComments(teacher.getDriver()); //2lines //getComment replies - List replies = ForumNavigationUtilities.getReplies(user.getDriver(), comments.get(0)); // 7 lines + List replies = ForumNavigationUtilities.getReplies(teacher.getDriver(), comments.get(0)); // 7 lines WebElement newReply = null; for (WebElement reply : replies) { diff --git a/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/LoggedLinksTests.java b/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/LoggedLinksTests.java index 9c2a9a8..4f81e9b 100644 --- a/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/LoggedLinksTests.java +++ b/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/LoggedLinksTests.java @@ -6,13 +6,10 @@ import com.fullteaching.e2e.no_elastest.utils.ParameterLoader; import giis.retorch.annotations.AccessMode; import giis.retorch.annotations.Resource; -import io.github.bonigarcia.seljup.SeleniumJupiter; -import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import org.openqa.selenium.WebElement; -import org.slf4j.Logger; import java.io.IOException; import java.util.ArrayList; @@ -21,25 +18,18 @@ import java.util.Map; import java.util.stream.Stream; -import static java.lang.invoke.MethodHandles.lookup; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.slf4j.LoggerFactory.getLogger; -@ExtendWith(SeleniumJupiter.class) class LoggedLinksTests extends BaseLoggedTest { - - public LoggedLinksTests() { super(); } - public static Stream data() throws IOException { return ParameterLoader.getTestUsers(); } - /** * This test get logged the user and checks the navigation by URL works correctly.First * get all the possible URLS for the current user for after it iterate over them checking @@ -55,7 +45,7 @@ public static Stream data() throws IOException { @Resource(resID = "Course", replaceable = {}) @AccessMode(resID = "Course", concurrency = 15, sharing = true, accessMode = "READWRITE") void spiderLoggedTest(String mail, String password, String role) { //140 + 28 set up +13 lines teardown = 181 - this.slowLogin(user, mail, password); + this.slowLogin(teacher, mail, password); //*navigate from home*//* NavigationUtilities.getUrlAndWaitFooter(driver, HOST); //13 lines List pageLinks = SpiderNavigation.getPageLinks(driver); //29 lines @@ -66,7 +56,7 @@ void spiderLoggedTest(String mail, String password, String role) { //140 + 28 se List failed_links = new ArrayList<>(); System.out.println(mail + " tested " + explored.size() + " urls"); explored.forEach((link, result) -> { - log.debug("\t" + link + " => " + result); + log.debug("\t {} => {}", link, result); if (result.equals("KO")) { failed_links.add(link); } diff --git a/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/UserTest.java b/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/UserTest.java index abf50aa..7c8f3cf 100644 --- a/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/UserTest.java +++ b/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/UserTest.java @@ -42,18 +42,18 @@ public static Stream data() throws IOException { @AccessMode(resID = "OpenVidu", concurrency = 10, sharing = true, accessMode = "NOACCESS") void loginTest(String mail, String password, String role) { //22 +85 +28 set up +13 lines teardown =148 try { - this.slowLogin(user, mail, password); //24 lines + this.slowLogin(teacher, mail, password); //24 lines UserUtilities.checkLogin(driver, mail); //12 lines assertTrue(true, "not logged"); } catch (NotLoggedException | BadUserException e) { - e.printStackTrace(); + log.debug("The user was not logged"); fail("Not logged"); } catch (ElementNotFoundException e) { - e.printStackTrace(); + log.debug("The web element used to check the log was not found"); fail(e.getLocalizedMessage()); } try { - this.logout(user); //14 lines + this.logout(teacher); //14 lines UserUtilities.checkLogOut(driver); //8lines } catch (ElementNotFoundException eleNotFoundExcept) { fail("Still logged"); diff --git a/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/media/FullTeachingEndToEndEChatTests.java b/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/media/FullTeachingEndToEndEChatTests.java index 9e08e21..b53b7cf 100644 --- a/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/media/FullTeachingEndToEndEChatTests.java +++ b/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/media/FullTeachingEndToEndEChatTests.java @@ -19,21 +19,22 @@ import com.fullteaching.e2e.no_elastest.common.BaseLoggedTest; import com.fullteaching.e2e.no_elastest.common.BrowserUser; +import com.fullteaching.e2e.no_elastest.utils.ParameterLoader; import giis.retorch.annotations.AccessMode; import giis.retorch.annotations.Resource; -import io.github.bonigarcia.seljup.SeleniumJupiter; import org.junit.jupiter.api.*; -import org.junit.jupiter.api.extension.ExtendWith; +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.logging.LogEntries; import org.openqa.selenium.support.ui.ExpectedConditions; -import java.util.Date; +import java.io.IOException; import java.util.List; +import java.util.stream.Stream; import static com.fullteaching.e2e.no_elastest.common.Constants.*; -import static org.openqa.selenium.logging.LogType.BROWSER; /** * E2E tests for FullTeaching chat in a video session. @@ -46,16 +47,13 @@ @DisplayName("E2E tests for FullTeaching chat") class FullTeachingEndToEndEChatTests extends BaseLoggedTest { - - private final static String TEACHER_BROWSER = "chrome"; private final static String STUDENT_BROWSER = "chrome"; - - final String teacherMail = "teacher@gmail.com"; - final String teacherPass = "pass"; final String studentMail = "student1@gmail.com"; final String studentPass = "pass"; - BrowserUser student; - private String TestName = "default-test-name"; + + public static Stream data() throws IOException { + return ParameterLoader.getTestTeachers(); + } @Resource(resID = "LoginService", replaceable = {}) @AccessMode(resID = "LoginService", concurrency = 10, sharing = true, accessMode = "READONLY") @@ -63,31 +61,36 @@ class FullTeachingEndToEndEChatTests extends BaseLoggedTest { @AccessMode(resID = "OpenVidu", concurrency = 10, sharing = true, accessMode = "READWRITE") @Resource(resID = "Course", replaceable = {"Configuration"}) @AccessMode(resID = "Course", concurrency = 1, sharing = false, accessMode = "READONLY") - @Test - void oneToOneChatInSessionChrome() { //197 Lines of code - int numberpriormessages = 1; + @DisplayName("oneToOneChatInSessionChrome") + @ParameterizedTest + @MethodSource("data") + @Tag("Multiuser Test") + void oneToOneChatInSessionChrome(String mail, String password, String role ) { //197 Lines of code + int numberpriormessages; // TEACHER - this.slowLogin(user, teacherMail, teacherPass);//24 + this.slowLogin(teacher, mail, password);//24 - log.info("{} entering first course", user.getClientData()); - user.getWaiter().until(ExpectedConditions.presenceOfElementLocated( + log.info("{} entering first course", teacher.getClientData()); + teacher.getWaiter().until(ExpectedConditions.presenceOfElementLocated( By.cssSelector(("ul.collection li.collection-item:first-child div.course-title")))); - user.getDriver().findElement(By.cssSelector("ul.collection li.collection-item:first-child div.course-title")) + teacher.getDriver().findElement(By.cssSelector("ul.collection li.collection-item:first-child div.course-title")) .click(); - log.info("{} navigating to 'Sessions' tab", user.getClientData()); - user.getWaiter().until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(("#md-tab-label-0-1")))); - user.getDriver().findElement(By.cssSelector("#md-tab-label-0-1")).click(); + log.info("{} navigating to 'Sessions' tab", teacher.getClientData()); + teacher.getWaiter().until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(("#md-tab-label-0-1")))); + teacher.getDriver().findElement(By.cssSelector("#md-tab-label-0-1")).click(); - log.info("{} getting into first session", user.getClientData()); - user.getDriver().findElement(By.cssSelector("ul div:first-child li.session-data div.session-ready")).click(); - user.waitUntil(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("#fixed-icon")), "Element fixed-icon not clickable"); + log.info("{} getting into first session", teacher.getClientData()); + teacher.getDriver().findElement(By.cssSelector("ul div:first-child li.session-data div.session-ready")).click(); + teacher.waitUntil(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("#fixed-icon")), "Element fixed-icon not clickable"); // Check connected message - user.getDriver().findElement(By.cssSelector("#fixed-icon")).click(); + teacher.getDriver().findElement(By.cssSelector("#fixed-icon")).click(); - checkSystemMessage("Connected", user, 100); // 6 lines + checkSystemMessage("Connected", teacher, 100); // 6 lines // STUDENT + student = setupBrowser(STUDENT_BROWSER, TJOB_NAME + "_" +"oneToOneChatInSessionChrome-STUDENT", studentMail,5);//27 lines + this.slowLogin(student, studentMail, studentPass); student.getWaiter().until(ExpectedConditions.presenceOfElementLocated( @@ -103,26 +106,26 @@ void oneToOneChatInSessionChrome() { //197 Lines of code checkSystemMessage("Connected", student, 0); //6 lines - checkSystemMessage(STUDENT_NAME + " has connected", user, 100); //6 lines + checkSystemMessage(STUDENT_NAME + " has connected", teacher, 100); //6 lines checkSystemMessage(TEACHER_NAME + " has connected", student, 100);//6lines // Test chat String teacherMessage = "TEACHER CHAT MESSAGE"; String studentMessage = "STUDENT CHAT MESSAGE"; - numberpriormessages = getNumberMessages(user); - WebElement chatInputTeacher = user.getDriver().findElement(By.id("message")); + numberpriormessages = getNumberMessages(teacher); + WebElement chatInputTeacher = teacher.getDriver().findElement(By.id("message")); chatInputTeacher.sendKeys(teacherMessage); - user.getWaiter().until(ExpectedConditions.elementToBeClickable(By.id("send-btn"))); - user.getDriver().findElement(By.id("send-btn")).click(); + teacher.getWaiter().until(ExpectedConditions.elementToBeClickable(By.id("send-btn"))); + teacher.getDriver().findElement(By.id("send-btn")).click(); - checkOwnMessage(teacherMessage, TEACHER_NAME, user, numberpriormessages);//7 lines + checkOwnMessage(teacherMessage, TEACHER_NAME, teacher, numberpriormessages);//7 lines checkStrangerMessage(teacherMessage, TEACHER_NAME, student, numberpriormessages); //8lines numberpriormessages = getNumberMessages(student); WebElement chatInputStudent = student.getDriver().findElement(By.id("message")); chatInputStudent.sendKeys(studentMessage); student.getWaiter().until(ExpectedConditions.elementToBeClickable(By.id("send-btn"))); student.getDriver().findElement(By.id("send-btn")).click(); - checkStrangerMessage(studentMessage, STUDENT_NAME, user, numberpriormessages); //8lines + checkStrangerMessage(studentMessage, STUDENT_NAME, teacher, numberpriormessages); //8lines checkOwnMessage(studentMessage, STUDENT_NAME, student, numberpriormessages);//7lines @@ -169,61 +172,5 @@ private int getNumberMessages(BrowserUser user) { return user.getDriver().findElements(By.tagName("app-chat-line")).size(); } - @BeforeEach - void setup(TestInfo info) { //65 lines - log.info("Custom Set-up for the OpenviduTest"); - if (info.getTestMethod().isPresent()) { - TestName = info.getTestMethod().get().getName(); - } - - log.info("##### Start test: " + TestName); - TJOB_NAME = System.getProperty("dirtarget"); - user = setupBrowser(TEACHER_BROWSER, TJOB_NAME + "_" + TestName, teacherMail, WAIT_SECONDS); - student = setupBrowser(STUDENT_BROWSER, TJOB_NAME + "_" + TestName, studentMail, WAIT_SECONDS);//27 lines - - } - - @AfterEach - void tearDown(TestInfo testInfo) { //13 lines - log.info("Custom TearDown"); - if (testInfo.getTestMethod().isPresent()) { - TestName = testInfo.getTestMethod().get().getName(); - } - if (student != null) { - log.info("##### Finish test: {} - Driver {}", TestName, this.student.getDriver()); - log.info("Browser console at the end of the test"); - LogEntries logEntries = student.getDriver().manage().logs().get(BROWSER); - logEntries.forEach((entry) -> log.info("[{}] {} {}", - new Date(entry.getTimestamp()), entry.getLevel(), - entry.getMessage())); - //TO-DO- ERROR with the logout - if (student.isOnSession()) { - this.logout(student); - } - - student.dispose(); - - - } - - if (user != null) { - log.info("##### Finish test: {} - Driver {}", TestName, this.user.getDriver()); - log.info("Browser console at the end of the test"); - LogEntries logEntries = user.getDriver().manage().logs().get(BROWSER); - logEntries.forEach((entry) -> log.info("[{}] {} {}", - new Date(entry.getTimestamp()), entry.getLevel(), - entry.getMessage())); - //TO-DO- ERROR with the logout - if (user.isOnSession()) { - this.logout(user); - } - - user.dispose(); - - - } - - - } } \ No newline at end of file diff --git a/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/media/FullTeachingEndToEndRESTTests.java b/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/media/FullTeachingEndToEndRESTTests.java index a655bf8..93153bb 100644 --- a/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/media/FullTeachingEndToEndRESTTests.java +++ b/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/media/FullTeachingEndToEndRESTTests.java @@ -20,22 +20,25 @@ import com.fullteaching.e2e.no_elastest.common.BaseLoggedTest; import com.fullteaching.e2e.no_elastest.common.CourseNavigationUtilities; import com.fullteaching.e2e.no_elastest.common.exception.ElementNotFoundException; +import com.fullteaching.e2e.no_elastest.utils.ParameterLoader; import giis.retorch.annotations.AccessMode; import giis.retorch.annotations.Resource; -import io.github.bonigarcia.seljup.SeleniumJupiter; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; +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.time.LocalDate; import java.time.LocalTime; import java.time.format.DateTimeFormatter; import java.util.List; +import java.util.stream.Stream; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -52,11 +55,13 @@ class FullTeachingEndToEndRESTTests extends BaseLoggedTest { final String TEST_COURSE_INFO = "TEST_COURSE_INFO"; final String EDITED = " EDITED"; - final String TEACHER_MAIL = "teacher@gmail.com"; - final String TEACHER_PASS = "pass"; final String TEACHER_NAME = "Teacher Cheater"; String COURSE_NAME = "TEST_COURSE"; + public static Stream data() throws IOException { + return ParameterLoader.getTestTeachers(); + } + public FullTeachingEndToEndRESTTests() { super(); } @@ -69,32 +74,34 @@ public FullTeachingEndToEndRESTTests() { @AccessMode(resID = "OpenVidu", concurrency = 10, sharing = true, accessMode = "NOACCESS") @Resource(resID = "Course", replaceable = {"Configuration"}) @AccessMode(resID = "Course", concurrency = 1, sharing = false, accessMode = "READWRITE") - @Test - void courseRestOperations() throws ElementNotFoundException { - loginAndCreateNewCourse(); + @DisplayName("courseRestOperations") + @ParameterizedTest + @MethodSource("data") + void courseRestOperations(String mail, String password, String role ) throws ElementNotFoundException { + loginAndCreateNewCourse(mail,password); editCourse(); - CourseNavigationUtilities.deleteCourse(user.getDriver(), COURSE_NAME + EDITED); // Tear down + CourseNavigationUtilities.deleteCourse(teacher.getDriver(), COURSE_NAME + EDITED); // Tear down } - private void loginAndCreateNewCourse() throws ElementNotFoundException { - slowLogin(user, TEACHER_MAIL, TEACHER_PASS); - CourseNavigationUtilities.newCourse(user.getDriver(), COURSE_NAME); + private void loginAndCreateNewCourse(String mail, String password) throws ElementNotFoundException { + slowLogin(teacher, mail, password); + CourseNavigationUtilities.newCourse(teacher.getDriver(), COURSE_NAME); } private void editCourse() { log.info("Editing course"); String editedCourseName = COURSE_NAME + EDITED; - List editIcons = user.getDriver().findElements(By.className("course-put-icon")); - openDialog(editIcons.get(editIcons.size() - 1), user); - user.waitUntil(ExpectedConditions.elementToBeClickable(By.id("input-put-course-name")), "Input for course name not clickable"); - WebElement courseNameInput = user.getDriver().findElement(By.id("input-put-course-name")); + List editIcons = teacher.getDriver().findElements(By.className("course-put-icon")); + openDialog(editIcons.get(editIcons.size() - 1), teacher); + teacher.waitUntil(ExpectedConditions.elementToBeClickable(By.id("input-put-course-name")), "Input for course name not clickable"); + WebElement courseNameInput = teacher.getDriver().findElement(By.id("input-put-course-name")); courseNameInput.clear(); courseNameInput.sendKeys(editedCourseName); - user.getDriver().findElement(By.id("submit-put-course-btn")).click(); - waitForDialogClosed("course-modal", "Edition of course failed", user); - user.waitUntil(ExpectedConditions.textToBe(By.cssSelector("#course-list .course-list-item:last-child div.course-title span"), editedCourseName), "Unexpected course name"); + teacher.getDriver().findElement(By.id("submit-put-course-btn")).click(); + waitForDialogClosed("course-modal", "Edition of course failed", teacher); + teacher.waitUntil(ExpectedConditions.textToBe(By.cssSelector("#course-list .course-list-item:last-child div.course-title span"), editedCourseName), "Unexpected course name"); } @Resource(resID = "LoginService", replaceable = {}) @@ -103,20 +110,22 @@ private void editCourse() { @AccessMode(resID = "OpenVidu", concurrency = 10, sharing = true, accessMode = "NOACCESS") @Resource(resID = "Course", replaceable = {"Information"}) @AccessMode(resID = "Course", concurrency = 1, sharing = false, accessMode = "READWRITE") - @Test - void courseInfoRestOperations() throws ElementNotFoundException { //12+16+65 set up +60 lines teardown =153 - loginAndCreateNewCourse(); + @DisplayName("courseInfoRestOperations") + @ParameterizedTest + @MethodSource("data") + void courseInfoRestOperations(String mail, String password, String role) throws ElementNotFoundException { //12+16+65 set up +60 lines teardown =153 + loginAndCreateNewCourse(mail,password); enterCourseAndNavigateTab(COURSE_NAME, "info-tab-icon");//16 lines - user.waitUntil(ExpectedConditions.presenceOfNestedElementLocatedBy(By.cssSelector(".md-tab-body.md-tab-active"), By.cssSelector(".card-panel.warning")), "Course info wasn't empty"); + teacher.waitUntil(ExpectedConditions.presenceOfNestedElementLocatedBy(By.cssSelector(".md-tab-body.md-tab-active"), By.cssSelector(".card-panel.warning")), "Course info wasn't empty"); log.info("Editing course information"); - user.getDriver().findElement(By.id("edit-course-info")).click(); - user.getDriver().findElement(By.className("ql-editor")).sendKeys(TEST_COURSE_INFO); - user.getDriver().findElement(By.id("send-info-btn")).click(); + teacher.getDriver().findElement(By.id("edit-course-info")).click(); + teacher.getDriver().findElement(By.className("ql-editor")).sendKeys(TEST_COURSE_INFO); + teacher.getDriver().findElement(By.id("send-info-btn")).click(); - user.waitUntil(ExpectedConditions.textToBe(By.cssSelector(".ql-editor p"), TEST_COURSE_INFO), "Unexpected course info"); + teacher.waitUntil(ExpectedConditions.textToBe(By.cssSelector(".ql-editor p"), TEST_COURSE_INFO), "Unexpected course info"); log.info("Course information successfully updated"); - CourseNavigationUtilities.deleteCourse(user.getDriver(), COURSE_NAME); + CourseNavigationUtilities.deleteCourse(teacher.getDriver(), COURSE_NAME); } @Resource(resID = "LoginService", replaceable = {}) @@ -125,9 +134,11 @@ void courseInfoRestOperations() throws ElementNotFoundException { //12+16+65 set @AccessMode(resID = "OpenVidu", concurrency = 10, sharing = true, accessMode = "NOACCESS") @Resource(resID = "Course", replaceable = {"Session"}) @AccessMode(resID = "Course", concurrency = 1, sharing = false, accessMode = "READWRITE") - @Test - void sessionRestOperations() throws ElementNotFoundException { - loginAndCreateNewCourse(); + @DisplayName("sessionRestOperations") + @ParameterizedTest + @MethodSource("data") + void sessionRestOperations(String mail, String password, String role) throws ElementNotFoundException { + loginAndCreateNewCourse(mail,password); addNewSession(); @@ -135,44 +146,44 @@ void sessionRestOperations() throws ElementNotFoundException { deleteSession(); - CourseNavigationUtilities.deleteCourse(user.getDriver(), COURSE_NAME); + CourseNavigationUtilities.deleteCourse(teacher.getDriver(), COURSE_NAME); } private void addNewSession() { enterCourseAndNavigateTab(COURSE_NAME, "sessions-tab-icon"); log.info("Adding new session"); - openDialog("#add-session-icon", user); + openDialog("#add-session-icon", teacher); fillSessionForm("TEST LESSON NAME", "TEST LESSON COMMENT", LocalDate.parse("2018-03-01"), LocalTime.parse("15:10"), false); - waitForDialogClosed("course-details-modal", "Addition of session failed", user); + waitForDialogClosed("course-details-modal", "Addition of session failed", teacher); verifySessionDetails("TEST LESSON NAME", "TEST LESSON COMMENT", "Jan 3, 2018 - 03:10", "Mar 1, 2018 - 15:10"); } private void editSession() { log.info("Editing session"); - openDialog(".edit-session-icon", user); + openDialog(".edit-session-icon", teacher); fillSessionForm("TEST LESSON NAME EDITED", "TEST LESSON COMMENT EDITED", LocalDate.parse("2019-04-02"), LocalTime.parse("05:10"), true); - waitForDialogClosed("put-delete-modal", "Edition of session failed", user); + waitForDialogClosed("put-delete-modal", "Edition of session failed", teacher); verifySessionDetails("TEST LESSON NAME EDITED", "TEST LESSON COMMENT EDITED", "Feb 4, 2019 - 05:10", "Apr 2, 2019 - 05:10"); } private void deleteSession() { log.info("Deleting session"); - openDialog(".edit-session-icon", user); - user.waitUntil(ExpectedConditions.elementToBeClickable(By.id(("label-delete-checkbox"))), "Checkbox for session deletion not clickable"); - user.getDriver().findElement(By.id("label-delete-checkbox")).click(); - user.waitUntil(ExpectedConditions.elementToBeClickable(By.id(("delete-session-btn"))), "Button for session deletion not clickable"); - user.getDriver().findElement(By.id("delete-session-btn")).click(); - waitForDialogClosed("put-delete-modal", "Deletion of session failed", user); - user.waitUntil(ExpectedConditions.numberOfElementsToBe(By.cssSelector("li.session-data"), 0), "Unexpected number of sessions"); + openDialog(".edit-session-icon", teacher); + teacher.waitUntil(ExpectedConditions.elementToBeClickable(By.id(("label-delete-checkbox"))), "Checkbox for session deletion not clickable"); + teacher.getDriver().findElement(By.id("label-delete-checkbox")).click(); + teacher.waitUntil(ExpectedConditions.elementToBeClickable(By.id(("delete-session-btn"))), "Button for session deletion not clickable"); + teacher.getDriver().findElement(By.id("delete-session-btn")).click(); + waitForDialogClosed("put-delete-modal", "Deletion of session failed", teacher); + teacher.waitUntil(ExpectedConditions.numberOfElementsToBe(By.cssSelector("li.session-data"), 0), "Unexpected number of sessions"); log.info("Session successfully deleted"); } private void fillSessionForm(String title, String comment, LocalDate date, LocalTime hour, boolean edit) { // Get the different fields depending on if it's editing the Session or not - WebElement titleField = user.getDriver().findElement(By.id(edit ? "input-put-title" : "input-post-title")); - WebElement commentField = user.getDriver().findElement(By.id(edit ? "input-put-comment" : "input-post-comment")); - WebElement dateField = user.getDriver().findElement(By.id(edit ? "input-put-date" : "input-post-date")); - WebElement timeField = user.getDriver().findElement(By.id(edit ? "input-put-time" : "input-post-time")); + WebElement titleField = teacher.getDriver().findElement(By.id(edit ? "input-put-title" : "input-post-title")); + WebElement commentField = teacher.getDriver().findElement(By.id(edit ? "input-put-comment" : "input-post-comment")); + WebElement dateField = teacher.getDriver().findElement(By.id(edit ? "input-put-date" : "input-post-date")); + WebElement timeField = teacher.getDriver().findElement(By.id(edit ? "input-put-time" : "input-post-time")); if (edit) { //If its editing previously clear the fields content titleField.clear(); commentField.clear(); @@ -185,18 +196,18 @@ private void fillSessionForm(String title, String comment, LocalDate date, Local dateField.sendKeys(date.format(dateFormatter)); timeField.sendKeys(hour.format(timeFormatter)); // Submit session form - user.getDriver().findElement(By.id(edit ? "put-modal-btn" : "post-modal-btn")).click(); + teacher.getDriver().findElement(By.id(edit ? "put-modal-btn" : "post-modal-btn")).click(); } private void verifySessionDetails(String expectedTitle, String expectedComment, String expectedDateTime1, String expectedDateTime2) { - user.waitUntil(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("li.session-data .session-title")), "Unexpected session title"); - Assertions.assertEquals(expectedTitle, user.getDriver().findElement(By.cssSelector("li.session-data .session-title")).getText()); + teacher.waitUntil(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("li.session-data .session-title")), "Unexpected session title"); + Assertions.assertEquals(expectedTitle, teacher.getDriver().findElement(By.cssSelector("li.session-data .session-title")).getText()); - user.waitUntil(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("li.session-data .session-description")), "The element located by css li.session-data .session-description is not visible"); - Assertions.assertEquals(expectedComment, user.getDriver().findElement(By.cssSelector("li.session-data .session-description")).getText()); + teacher.waitUntil(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("li.session-data .session-description")), "The element located by css li.session-data .session-description is not visible"); + Assertions.assertEquals(expectedComment, teacher.getDriver().findElement(By.cssSelector("li.session-data .session-description")).getText()); - user.waitUntil(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("li.session-data .session-datetime")), "The element located by css li.session-data .session-datetime is not visible"); - String actualDateTime = user.getDriver().findElement(By.cssSelector("li.session-data .session-datetime")).getText(); + teacher.waitUntil(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("li.session-data .session-datetime")), "The element located by css li.session-data .session-datetime is not visible"); + String actualDateTime = teacher.getDriver().findElement(By.cssSelector("li.session-data .session-datetime")).getText(); Assertions.assertTrue(actualDateTime.equals(expectedDateTime1) || actualDateTime.equals(expectedDateTime2)); } @@ -206,70 +217,72 @@ private void verifySessionDetails(String expectedTitle, String expectedComment, @AccessMode(resID = "OpenVidu", concurrency = 10, sharing = true, accessMode = "NOACCESS") @Resource(resID = "Course", replaceable = {"Forum"}) @AccessMode(resID = "Course", concurrency = 1, sharing = false, accessMode = "READWRITE") - @Test - void forumRestOperations() throws ElementNotFoundException { //60+66+65 set up +60 lines teardown =251 - loginAndCreateNewCourse(); + @DisplayName("forumRestOperations") + @ParameterizedTest + @MethodSource("data") + void forumRestOperations(String mail, String password, String role) throws ElementNotFoundException { //60+66+65 set up +60 lines teardown =251 + loginAndCreateNewCourse(mail,password); enterCourseAndNavigateTab(COURSE_NAME, "forum-tab-icon");//16 lines log.info("Adding new entry to the forum"); - openDialog("#add-entry-icon", user);//8lines + openDialog("#add-entry-icon", teacher);//8lines // Find form elements - WebElement titleField = user.getDriver().findElement(By.id("input-post-title")); - WebElement commentField = user.getDriver().findElement(By.id("input-post-comment")); + WebElement titleField = teacher.getDriver().findElement(By.id("input-post-title")); + WebElement commentField = teacher.getDriver().findElement(By.id("input-post-comment")); String title = "TEST FORUM ENTRY"; String comment = "TEST FORUM COMMENT"; String entryDate = "a few seconds ago"; // Fill input fields titleField.sendKeys(title); commentField.sendKeys(comment); - user.getDriver().findElement(By.id("post-modal-btn")).click(); - waitForDialogClosed("course-details-modal", "Addition of entry failed", user);////14 lines + teacher.getDriver().findElement(By.id("post-modal-btn")).click(); + waitForDialogClosed("course-details-modal", "Addition of entry failed", teacher);////14 lines // Check fields of new entry - WebElement entryEl = user.getDriver().findElement(By.cssSelector("li.entry-title")); - user.waitUntil(ExpectedConditions.textToBe(By.cssSelector("li.entry-title .forum-entry-title"), title), + WebElement entryEl = teacher.getDriver().findElement(By.cssSelector("li.entry-title")); + teacher.waitUntil(ExpectedConditions.textToBe(By.cssSelector("li.entry-title .forum-entry-title"), title), "Unexpected entry title in the forum"); - user.waitUntil(ExpectedConditions.textToBe(By.cssSelector("li.entry-title .forum-entry-author"), TEACHER_NAME), + teacher.waitUntil(ExpectedConditions.textToBe(By.cssSelector("li.entry-title .forum-entry-author"), TEACHER_NAME), "Unexpected entry author in the forum"); - user.waitUntil(ExpectedConditions.textToBe(By.cssSelector("li.entry-title .forum-entry-date"), entryDate), + teacher.waitUntil(ExpectedConditions.textToBe(By.cssSelector("li.entry-title .forum-entry-date"), entryDate), "Unexpected entry date in the forum"); log.info("New entry successfully added to the forum"); log.info("Entering the new entry"); entryEl.click(); - user.waitUntil(ExpectedConditions.textToBe( + teacher.waitUntil(ExpectedConditions.textToBe( By.cssSelector(".comment-block > app-comment:first-child > div.comment-div .message-itself"), comment), "Unexpected entry title in the entry details view"); - user.waitUntil(ExpectedConditions.textToBe( + teacher.waitUntil(ExpectedConditions.textToBe( By.cssSelector(".comment-block > app-comment:first-child > div.comment-div .forum-comment-author"), TEACHER_NAME), "Unexpected entry author in the entry details view"); // Comment reply log.info("Adding new replay to the entry's only comment"); String reply = "TEST FORUM REPLY"; - openDialog(".replay-icon", user);//8lines - commentField = user.getDriver().findElement(By.id("input-post-comment")); + openDialog(".replay-icon", teacher);//8lines + commentField = teacher.getDriver().findElement(By.id("input-post-comment")); commentField.sendKeys(reply); - user.getDriver().findElement(By.id("post-modal-btn")).click(); - waitForDialogClosed("course-details-modal", "Addition of entry reply failed", user);//14 lines - user.waitUntil(ExpectedConditions.textToBe(By.cssSelector( + teacher.getDriver().findElement(By.id("post-modal-btn")).click(); + waitForDialogClosed("course-details-modal", "Addition of entry reply failed", teacher);//14 lines + teacher.waitUntil(ExpectedConditions.textToBe(By.cssSelector( ".comment-block > app-comment:first-child > div.comment-div div.comment-div .message-itself"), reply), "Unexpected reply message in the entry details view"); - user.waitUntil(ExpectedConditions.textToBe(By.cssSelector( + teacher.waitUntil(ExpectedConditions.textToBe(By.cssSelector( ".comment-block > app-comment:first-child > div.comment-div div.comment-div .forum-comment-author"), TEACHER_NAME), "Unexpected reply author in the entry details view"); log.info("Replay successfully added"); // Forum deactivation - user.getDriver().findElement(By.id("entries-sml-btn")).click(); + teacher.getDriver().findElement(By.id("entries-sml-btn")).click(); log.info("Deactivating forum"); - openDialog("#edit-forum-icon", user);//8lines - user.waitUntil(ExpectedConditions.elementToBeClickable(By.id(("label-forum-checkbox"))), + openDialog("#edit-forum-icon", teacher);//8lines + teacher.waitUntil(ExpectedConditions.elementToBeClickable(By.id(("label-forum-checkbox"))), "Checkbox for forum deactivation not clickable"); - user.getDriver().findElement(By.id("label-forum-checkbox")).click(); - user.waitUntil(ExpectedConditions.elementToBeClickable(By.id(("put-modal-btn"))), + teacher.getDriver().findElement(By.id("label-forum-checkbox")).click(); + teacher.waitUntil(ExpectedConditions.elementToBeClickable(By.id(("put-modal-btn"))), "Button for forum deactivation not clickable"); - user.getDriver().findElement(By.id("put-modal-btn")).click(); - waitForDialogClosed("put-delete-modal", "Deactivation of forum failed", user);//14 lines - user.waitUntil(ExpectedConditions.elementToBeClickable(By.cssSelector("app-error-message .card-panel.warning")), + teacher.getDriver().findElement(By.id("put-modal-btn")).click(); + waitForDialogClosed("put-delete-modal", "Deactivation of forum failed", teacher);//14 lines + teacher.waitUntil(ExpectedConditions.elementToBeClickable(By.cssSelector("app-error-message .card-panel.warning")), "Warning card (forum deactivated) missing"); log.info("Forum successfully deactivated"); - CourseNavigationUtilities.deleteCourse(user.getDriver(), COURSE_NAME); + CourseNavigationUtilities.deleteCourse(teacher.getDriver(), COURSE_NAME); } @Resource(resID = "LoginService", replaceable = {}) @@ -278,99 +291,101 @@ void forumRestOperations() throws ElementNotFoundException { //60+66+65 set up + @AccessMode(resID = "OpenVidu", concurrency = 10, sharing = true, accessMode = "NOACCESS") @Resource(resID = "Course", replaceable = {"Files"}) @AccessMode(resID = "Course", concurrency = 1, sharing = false, accessMode = "READWRITE") - @Test - void filesRestOperations() throws ElementNotFoundException {//88+112+65 set up +60 lines teardown =325 - loginAndCreateNewCourse(); + @DisplayName("filesRestOperations") + @ParameterizedTest + @MethodSource("data") + void filesRestOperations(String mail, String password, String role) throws ElementNotFoundException {//88+112+65 set up +60 lines teardown =325 + loginAndCreateNewCourse(mail,password); enterCourseAndNavigateTab(COURSE_NAME, "files-tab-icon");//16 lines log.info("Checking that there are no files in the course"); - user.waitUntil(ExpectedConditions.elementToBeClickable(By.cssSelector("app-error-message .card-panel.warning")), + teacher.waitUntil(ExpectedConditions.elementToBeClickable(By.cssSelector("app-error-message .card-panel.warning")), "Warning card (course with no files) missing"); log.info("Adding new file group"); - openDialog("#add-files-icon", user);//8lines + openDialog("#add-files-icon", teacher);//8lines String fileGroup = "TEST FILE GROUP"; // Find form elements - WebElement titleField = user.getDriver().findElement(By.id("input-post-title")); + WebElement titleField = teacher.getDriver().findElement(By.id("input-post-title")); titleField.sendKeys(fileGroup); - user.getDriver().findElement(By.id("post-modal-btn")).click(); - waitForDialogClosed("course-details-modal", "Addition of file group failed", user);//14 lines + teacher.getDriver().findElement(By.id("post-modal-btn")).click(); + waitForDialogClosed("course-details-modal", "Addition of file group failed", teacher);//14 lines // Check fields of new file group - user.waitUntil(ExpectedConditions.textToBe(By.cssSelector(".file-group-title h5"), fileGroup), + teacher.waitUntil(ExpectedConditions.textToBe(By.cssSelector(".file-group-title h5"), fileGroup), "Unexpected file group name"); log.info("File group successfully added"); // Edit file group log.info("Editing file group"); - openDialog("#edit-filegroup-icon", user);//8lines + openDialog("#edit-filegroup-icon", teacher);//8lines // Find form elements - titleField = user.getDriver().findElement(By.id("input-file-title")); + titleField = teacher.getDriver().findElement(By.id("input-file-title")); titleField.clear(); titleField.sendKeys(fileGroup + EDITED); - user.getDriver().findElement(By.id("put-modal-btn")).click(); - waitForDialogClosed("put-delete-modal", "Edition of file group failed", user);//14 lines + teacher.getDriver().findElement(By.id("put-modal-btn")).click(); + waitForDialogClosed("put-delete-modal", "Edition of file group failed", teacher);//14 lines // Check fields of edited file group - user.waitUntil( + teacher.waitUntil( ExpectedConditions.textToBe(By.cssSelector("app-file-group .file-group-title h5"), fileGroup + EDITED), "Unexpected file group name"); log.info("File group successfully edited"); // Add file subgroup log.info("Adding new file sub-group"); String fileSubGroup = "TEST FILE SUBGROUP"; - openDialog(".add-subgroup-btn", user);//8lines - titleField = user.getDriver().findElement(By.id("input-post-title")); + openDialog(".add-subgroup-btn", teacher);//8lines + titleField = teacher.getDriver().findElement(By.id("input-post-title")); titleField.sendKeys(fileSubGroup); - user.getDriver().findElement(By.id("post-modal-btn")).click(); - waitForDialogClosed("course-details-modal", "Addition of file sub-group failed", user);//14 lines + teacher.getDriver().findElement(By.id("post-modal-btn")).click(); + waitForDialogClosed("course-details-modal", "Addition of file sub-group failed", teacher);//14 lines // Check fields of new file subgroup - user.waitUntil(ExpectedConditions.textToBe(By.cssSelector("app-file-group app-file-group .file-group-title h5"), + teacher.waitUntil(ExpectedConditions.textToBe(By.cssSelector("app-file-group app-file-group .file-group-title h5"), fileSubGroup), "Unexpected file sub-group name"); log.info("File sub-group successfully added"); log.info("Adding new file to sub-group"); - openDialog("app-file-group app-file-group .add-file-btn", user);//8lines - WebElement fileUploader = user.getDriver().findElement(By.className("input-file-uploader")); + openDialog("app-file-group app-file-group .add-file-btn", teacher);//8lines + WebElement fileUploader = teacher.getDriver().findElement(By.className("input-file-uploader")); String fileName = "testFile.txt"; log.info("Uploading file located on path '{}'", System.getProperty("user.dir") + "/src/test/resources/" + fileName); - user.runJavascript("arguments[0].setAttribute('style', 'display:block')", fileUploader); - user.waitUntil( + teacher.runJavascript("arguments[0].setAttribute('style', 'display:block')", fileUploader); + teacher.waitUntil( ExpectedConditions.presenceOfElementLocated(By.xpath( "//input[contains(@class, 'input-file-uploader') and contains(@style, 'display:block')]")), "Waiting for the input file to be displayed"); fileUploader.sendKeys(System.getProperty("user.dir") + "/src/test/resources/" + fileName); - user.getDriver().findElement(By.id("upload-all-btn")).click(); + teacher.getDriver().findElement(By.id("upload-all-btn")).click(); // Wait for upload - user.waitUntil( + teacher.waitUntil( ExpectedConditions.presenceOfElementLocated( By.xpath("//div[contains(@class, 'determinate') and contains(@style, 'width: 100')]")), "Upload process not completed. Progress bar not filled"); - user.waitUntil(ExpectedConditions.textToBe(By.xpath("//i[contains(@class, 'icon-status-upload')]"), "done"), + teacher.waitUntil(ExpectedConditions.textToBe(By.xpath("//i[contains(@class, 'icon-status-upload')]"), "done"), "Upload process failed"); log.info("File upload successful"); // Close dialog - user.getDriver().findElement(By.id("close-upload-modal-btn")).click(); - waitForDialogClosed("course-details-modal", "Upload of file failed", user);//14 lines + teacher.getDriver().findElement(By.id("close-upload-modal-btn")).click(); + waitForDialogClosed("course-details-modal", "Upload of file failed", teacher);//14 lines // Check new uploaded file - user.waitUntil(ExpectedConditions.textToBe(By.cssSelector("app-file-group app-file-group .chip .file-name-div"), + teacher.waitUntil(ExpectedConditions.textToBe(By.cssSelector("app-file-group app-file-group .chip .file-name-div"), fileName), "Unexpected uploaded file name"); log.info("File successfully added"); // Edit file log.info("Editing file"); - openDialog("app-file-group app-file-group .edit-file-name-icon", user);//8lines - titleField = user.getDriver().findElement(By.id("input-file-title")); + openDialog("app-file-group app-file-group .edit-file-name-icon", teacher);//8lines + titleField = teacher.getDriver().findElement(By.id("input-file-title")); titleField.clear(); String editedFileName = "testFileEDITED.txt"; titleField.sendKeys(editedFileName); - user.getDriver().findElement(By.id("put-modal-btn")).click(); - waitForDialogClosed("put-delete-modal", "Edition of file failed", user);//14 lines + teacher.getDriver().findElement(By.id("put-modal-btn")).click(); + waitForDialogClosed("put-delete-modal", "Edition of file failed", teacher);//14 lines // Check edited file name - user.waitUntil(ExpectedConditions.textToBe(By.cssSelector("app-file-group app-file-group .chip .file-name-div"), + teacher.waitUntil(ExpectedConditions.textToBe(By.cssSelector("app-file-group app-file-group .chip .file-name-div"), editedFileName), "Unexpected uploaded file name"); log.info("File successfully edited"); // Delete file group log.info("Deleting file-group"); - user.getDriver().findElement(By.cssSelector("app-file-group .delete-filegroup-icon")).click(); - user.waitUntil(ExpectedConditions.elementToBeClickable(By.cssSelector("app-error-message .card-panel.warning")), + teacher.getDriver().findElement(By.cssSelector("app-file-group .delete-filegroup-icon")).click(); + teacher.waitUntil(ExpectedConditions.elementToBeClickable(By.cssSelector("app-error-message .card-panel.warning")), "Warning card (course with no files) missing"); log.info("File group successfully deleted"); - CourseNavigationUtilities.deleteCourse(user.getDriver(), COURSE_NAME); + CourseNavigationUtilities.deleteCourse(teacher.getDriver(), COURSE_NAME); } @Resource(resID = "LoginService", replaceable = {}) @@ -379,53 +394,55 @@ void filesRestOperations() throws ElementNotFoundException {//88+112+65 set up + @AccessMode(resID = "OpenVidu", concurrency = 10, sharing = true, accessMode = "NOACCESS") @Resource(resID = "Course", replaceable = {"Attenders"}) @AccessMode(resID = "Course", concurrency = 1, sharing = false, accessMode = "READWRITE") - @Test - void attendersRestOperations() throws ElementNotFoundException {//42+32+65 set up +60 lines teardown =199 - loginAndCreateNewCourse(); + @DisplayName("attendersRestOperations") + @ParameterizedTest + @MethodSource("data") + void attendersRestOperations(String mail, String password, String role) throws ElementNotFoundException {//42+32+65 set up +60 lines teardown =199 + loginAndCreateNewCourse(mail,password); enterCourseAndNavigateTab(COURSE_NAME, "attenders-tab-icon");//16 lines log.info("Checking that there is only one attender to the course"); - user.waitUntil(ExpectedConditions.numberOfElementsToBe(By.className("attender-row-div"), 1), + teacher.waitUntil(ExpectedConditions.numberOfElementsToBe(By.className("attender-row-div"), 1), "Unexpected number of attenders for the course"); - user.waitUntil(ExpectedConditions.textToBe(By.cssSelector(".attender-row-div .attender-name-p"), TEACHER_NAME), + teacher.waitUntil(ExpectedConditions.textToBe(By.cssSelector(".attender-row-div .attender-name-p"), TEACHER_NAME), "Unexpected name for the attender"); // Add attender fail log.info("Adding attender (should FAIL)"); - openDialog("#add-attenders-icon", user);//8lines + openDialog("#add-attenders-icon", teacher);//8lines String attenderName = "studentFail@gmail.com"; - WebElement titleField = user.getDriver().findElement(By.id("input-attender-simple")); + WebElement titleField = teacher.getDriver().findElement(By.id("input-attender-simple")); titleField.sendKeys(attenderName); - user.getDriver().findElement(By.id("put-modal-btn")).click(); - waitForDialogClosed("put-delete-modal", "Addition of attender fail", user);//14 lines - user.waitUntil(ExpectedConditions.elementToBeClickable(By.cssSelector("app-error-message .card-panel.fail")), + teacher.getDriver().findElement(By.id("put-modal-btn")).click(); + waitForDialogClosed("put-delete-modal", "Addition of attender fail", teacher);//14 lines + teacher.waitUntil(ExpectedConditions.elementToBeClickable(By.cssSelector("app-error-message .card-panel.fail")), "Error card (attender not added to the course) missing"); - user.waitUntil(ExpectedConditions.numberOfElementsToBe(By.className("attender-row-div"), 1), + teacher.waitUntil(ExpectedConditions.numberOfElementsToBe(By.className("attender-row-div"), 1), "Unexpected number of attenders for the course"); - user.getDriver().findElement(By.cssSelector("app-error-message .card-panel.fail .material-icons")).click(); + teacher.getDriver().findElement(By.cssSelector("app-error-message .card-panel.fail .material-icons")).click(); log.info("Attender addition successfully failed"); // Add attender success log.info("Adding attender (should SUCCESS)"); - openDialog("#add-attenders-icon", user);//8lines + openDialog("#add-attenders-icon", teacher);//8lines attenderName = "student1@gmail.com"; - titleField = user.getDriver().findElement(By.id("input-attender-simple")); + titleField = teacher.getDriver().findElement(By.id("input-attender-simple")); titleField.sendKeys(attenderName); - user.getDriver().findElement(By.id("put-modal-btn")).click(); - waitForDialogClosed("put-delete-modal", "Addition of attender failed", user);//14 lines - user.waitUntil(ExpectedConditions.elementToBeClickable(By.cssSelector("app-error-message .card-panel.correct")), + teacher.getDriver().findElement(By.id("put-modal-btn")).click(); + waitForDialogClosed("put-delete-modal", "Addition of attender failed", teacher);//14 lines + teacher.waitUntil(ExpectedConditions.elementToBeClickable(By.cssSelector("app-error-message .card-panel.correct")), "Success card (attender properly added to the course) missing"); - user.waitUntil(ExpectedConditions.numberOfElementsToBe(By.className("attender-row-div"), 2), + teacher.waitUntil(ExpectedConditions.numberOfElementsToBe(By.className("attender-row-div"), 2), "Unexpected number of attenders for the course"); - user.getDriver().findElement(By.cssSelector("app-error-message .card-panel.correct .material-icons")).click(); + teacher.getDriver().findElement(By.cssSelector("app-error-message .card-panel.correct .material-icons")).click(); log.info("Attender addition successfully finished"); // Remove attender log.info("Removing attender"); - user.getDriver().findElement(By.id("edit-attenders-icon")).click(); - user.waitUntil(ExpectedConditions.elementToBeClickable(By.cssSelector(".del-attender-icon")), + teacher.getDriver().findElement(By.id("edit-attenders-icon")).click(); + teacher.waitUntil(ExpectedConditions.elementToBeClickable(By.cssSelector(".del-attender-icon")), "Button for attender deletion not clickable"); - user.getDriver().findElement(By.cssSelector(".del-attender-icon")).click(); - user.waitUntil(ExpectedConditions.numberOfElementsToBe(By.className("attender-row-div"), 1), + teacher.getDriver().findElement(By.cssSelector(".del-attender-icon")).click(); + teacher.waitUntil(ExpectedConditions.numberOfElementsToBe(By.className("attender-row-div"), 1), "Unexpected number of attenders for the course"); log.info("Attender successfully removed"); - CourseNavigationUtilities.deleteCourse(user.getDriver(), COURSE_NAME); + CourseNavigationUtilities.deleteCourse(teacher.getDriver(), COURSE_NAME); } /*** Auxiliary methods ***/ @@ -434,8 +451,8 @@ void attendersRestOperations() throws ElementNotFoundException {//42+32+65 set u private void enterCourseAndNavigateTab(String courseName, String tabId) { //16 lines log.info("Entering course {}", courseName); //All these tests always create a new course, so we wait for 3-courses in the main page (more than 2) - user.waitUntil(ExpectedConditions.numberOfElementsToBeMoreThan(By.cssSelector("#course-list .course-list-item div.course-title span"), 2), "The number of courses should be 3"); - List allCourses = user.getDriver() + teacher.waitUntil(ExpectedConditions.numberOfElementsToBeMoreThan(By.cssSelector("#course-list .course-list-item div.course-title span"), 2), "The number of courses should be 3"); + List allCourses = teacher.getDriver() .findElements(By.cssSelector("#course-list .course-list-item div.course-title span")); WebElement courseSpan = null; for (WebElement c : allCourses) { @@ -447,9 +464,9 @@ private void enterCourseAndNavigateTab(String courseName, String tabId) { //16 l assertNotNull(courseSpan, "The course with the name '" + courseName + "' could not be found. Total courses available: " + allCourses.size()); courseSpan.click(); - user.waitUntil(ExpectedConditions.textToBe(By.id("main-course-title"), courseName), "Unexpected course title"); + teacher.waitUntil(ExpectedConditions.textToBe(By.id("main-course-title"), courseName), "Unexpected course title"); log.info("Navigating to tab by clicking icon with id '{}'", tabId); - user.getDriver().findElement(By.id(tabId)).click(); + teacher.getDriver().findElement(By.id(tabId)).click(); } diff --git a/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/media/FullTeachingLoggedVideoSessionTests.java b/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/media/FullTeachingLoggedVideoSessionTests.java index 126ac97..5f4f038 100644 --- a/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/media/FullTeachingLoggedVideoSessionTests.java +++ b/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/media/FullTeachingLoggedVideoSessionTests.java @@ -6,16 +6,17 @@ import com.fullteaching.e2e.no_elastest.common.SessionNavigationUtilities; 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.AfterEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.DisplayName; +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.JavascriptExecutor; import org.openqa.selenium.WebElement; -import org.openqa.selenium.logging.LogEntries; import org.openqa.selenium.support.ui.ExpectedConditions; import org.slf4j.Logger; @@ -24,14 +25,13 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Calendar; -import java.util.Date; import java.util.List; +import java.util.stream.Stream; import static com.fullteaching.e2e.no_elastest.common.Constants.*; import static java.lang.invoke.MethodHandles.lookup; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.openqa.selenium.logging.LogType.BROWSER; import static org.slf4j.LoggerFactory.getLogger; class FullTeachingLoggedVideoSessionTests extends BaseLoggedTest { @@ -39,11 +39,14 @@ class FullTeachingLoggedVideoSessionTests extends BaseLoggedTest { final static Logger log = getLogger(lookup().lookupClass()); public String courseName; - protected List studentBrowserUserList; protected List studentPassList; protected List studentNamesList; protected List studentNameList; + public static Stream data() throws IOException { + return ParameterLoader.getTestTeachers(); + } + /** * This method tests the video session functionality of the application. @@ -56,17 +59,19 @@ class FullTeachingLoggedVideoSessionTests extends BaseLoggedTest { @AccessMode(resID = "OpenVidu", concurrency = 10, sharing = true, accessMode = "READWRITE") @Resource(resID = "Course", replaceable = {"Session"}) @AccessMode(resID = "Course", concurrency = 1, sharing = false, accessMode = "READONLY") - @Test - void sessionTest() throws ElementNotFoundException, IOException { + @DisplayName("sessionTest") + @ParameterizedTest + @MethodSource("data") + void sessionTest(String mail, String password, String role) throws ElementNotFoundException, IOException { String sessionName = "Today's Session"; courseName = "Pseudoscientific course for treating the evil eye"; - this.slowLogin(this.user, "teacher@gmail.com", "pass"); + this.slowLogin(this.teacher, mail, password); initializeStudents("src/test/resources/inputs/default_user_LoggedVideoStudents.csv"); createNewSession(sessionName); - joinSession(sessionName, this.user); + joinSession(sessionName, this.teacher); joinSessionStudents(sessionName); leaveStudentSessions(); - leaveSession(this.user); + leaveSession(this.teacher); deleteSession(sessionName); } @@ -76,6 +81,7 @@ void sessionTest() throws ElementNotFoundException, IOException { * @throws IOException if there is an error reading the file */ private void initializeStudents(String pathData) throws IOException { + log.info("Initializing students"); String users_data = loadStudentsData(pathData); studentNameList = new ArrayList<>(); studentPassList = new ArrayList<>(); @@ -94,6 +100,7 @@ private void initializeStudents(String pathData) throws IOException { studentNamesList.add(userid); studentBrowserUserList.add(studentD); } + log.info("Initializing students end, number of students: {} " ,studentNameList.size()); } /** * This method creates a new video session with the given name, navigating to the course, opens the new session modal, @@ -106,19 +113,19 @@ private void createNewSession(String sessionName) throws ElementNotFoundExceptio String sessionHour = getCurrentTime(); String sessionDescription = "Wow today session will be amazing"; - navigateToCourse(user, courseName); - Click.element(user.getDriver(), SESSION_LIST_NEW_SESSION_ICON); - WebElement modal = Wait.notTooMuch(user.getDriver()).until(ExpectedConditions.visibilityOfElementLocated(SESSION_LIST_NEW_SESSION_MODAL)); + navigateToCourse(teacher, courseName); + Click.element(teacher.getDriver(), SESSION_LIST_NEW_SESSION_ICON); + WebElement modal = Wait.notTooMuch(teacher.getDriver()).until(ExpectedConditions.visibilityOfElementLocated(SESSION_LIST_NEW_SESSION_MODAL)); modal.findElement(SESSION_LIST_NEW_SESSION_MODAL_TITLE).sendKeys(sessionName); modal.findElement(SESSION_LIST_NEW_SESSION_MODAL_CONTENT).sendKeys(sessionDescription); modal.findElement(SESSION_LIST_NEW_SESSION_MODAL_DATE).sendKeys(sessionDate); modal.findElement(SESSION_LIST_NEW_SESSION_MODAL_TIME).sendKeys(sessionHour); - Click.element(user.getDriver(), modal.findElement(SESSION_LIST_NEW_SESSION_MODAL_POST_BUTTON)); - Wait.notTooMuch(user.getDriver()); + Click.element(teacher.getDriver(), modal.findElement(SESSION_LIST_NEW_SESSION_MODAL_POST_BUTTON)); + Wait.notTooMuch(teacher.getDriver()); // Verify session creation - Wait.waitForPageLoaded(user.getDriver()); - user.waitUntil(ExpectedConditions.numberOfElementsToBeMoreThan(SESSION_LIST_SESSION_ROW,3),"Incorrect number of sessions (never more than 2)"); - List session_titles = SessionNavigationUtilities.getFullSessionList(user.getDriver()); + Wait.waitForPageLoaded(teacher.getDriver()); + teacher.waitUntil(ExpectedConditions.numberOfElementsToBeMoreThan(SESSION_LIST_SESSION_ROW,3),"Incorrect number of sessions (never more than 2)"); + List session_titles = SessionNavigationUtilities.getFullSessionList(teacher.getDriver()); assertTrue(session_titles.contains(sessionName), "Session has not been created"); } /** @@ -202,13 +209,13 @@ private void deleteSession(String sessionName) throws ElementNotFoundException { List session_titles; WebElement modal; WebElement session; - session = SessionNavigationUtilities.getSession(user.getDriver(), sessionName); - Click.element(user.getDriver(), session.findElement(SESSION_LIST_SESSION_EDIT_ICON)); - modal = Wait.notTooMuch(user.getDriver()).until(ExpectedConditions.visibilityOfElementLocated(SESSION_LIST_EDIT_MODAL)); - Click.element(user.getDriver(), modal.findElement(SESSION_LIST_EDIT_MODAL_DELETE_DIV).findElement(By.tagName("label"))); - Click.element(user.getDriver(), modal.findElement(SESSION_LIST_EDIT_MODAL_DELETE_DIV).findElement(By.tagName("a"))); - Wait.waitForPageLoaded(user.getDriver());//13 lines - session_titles = SessionNavigationUtilities.getFullSessionList(user.getDriver()); //7 lines + session = SessionNavigationUtilities.getSession(teacher.getDriver(), sessionName); + Click.element(teacher.getDriver(), session.findElement(SESSION_LIST_SESSION_EDIT_ICON)); + modal = Wait.notTooMuch(teacher.getDriver()).until(ExpectedConditions.visibilityOfElementLocated(SESSION_LIST_EDIT_MODAL)); + Click.element(teacher.getDriver(), modal.findElement(SESSION_LIST_EDIT_MODAL_DELETE_DIV).findElement(By.tagName("label"))); + Click.element(teacher.getDriver(), modal.findElement(SESSION_LIST_EDIT_MODAL_DELETE_DIV).findElement(By.tagName("a"))); + Wait.waitForPageLoaded(teacher.getDriver());//13 lines + session_titles = SessionNavigationUtilities.getFullSessionList(teacher.getDriver()); //7 lines assertFalse(session_titles.contains(sessionName), "Session has not been deleted"); } @@ -225,29 +232,5 @@ public String loadStudentsData(String path) throws IOException { System.out.println(key); return key.toString(); } - @AfterEach - void tearDown(TestInfo testInfo) { - //Logout and exit students - if (studentBrowserUserList!=null) { - for (BrowserUser student : studentBrowserUserList) { - if (student.isOnSession()) { - this.logout(student); - } - student.dispose(); - } - } - if (user != null) { - log.info("##### Finish test: {} - Driver {}", TEST_NAME, this.user.getDriver()); - log.info("Browser console at the end of the test"); - LogEntries logEntries = user.getDriver().manage().logs().get(BROWSER); - logEntries.forEach((entry) -> log.info("[{}] {} {}", - new Date(entry.getTimestamp()), entry.getLevel(), - entry.getMessage())); - if (user.isOnSession()) { - this.logout(user); - } - user.dispose(); - } - } } diff --git a/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/media/FullTeachingTestEndToEndVideoSessionTests.java b/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/media/FullTeachingTestEndToEndVideoSessionTests.java index 8f6e5c8..51690ac 100644 --- a/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/media/FullTeachingTestEndToEndVideoSessionTests.java +++ b/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/media/FullTeachingTestEndToEndVideoSessionTests.java @@ -19,20 +19,20 @@ import com.fullteaching.e2e.no_elastest.common.BaseLoggedTest; import com.fullteaching.e2e.no_elastest.common.BrowserUser; +import com.fullteaching.e2e.no_elastest.utils.ParameterLoader; import giis.retorch.annotations.AccessMode; import giis.retorch.annotations.Resource; -import io.github.bonigarcia.seljup.SeleniumJupiter; import org.junit.jupiter.api.*; -import org.junit.jupiter.api.extension.ExtendWith; +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.logging.LogEntries; import org.openqa.selenium.support.ui.ExpectedConditions; -import java.util.Date; +import java.io.IOException; +import java.util.stream.Stream; -import static com.fullteaching.e2e.no_elastest.common.Constants.WAIT_SECONDS; -import static org.openqa.selenium.logging.LogType.BROWSER; /*This test case were disabled due to problems with the OpenVidu Server. The video input doesn't work , so it's not * feasible check that in the other side of the connection its playing the stream*/ @@ -41,13 +41,12 @@ @DisplayName("E2E tests for FullTeaching video session") class FullTeachingTestEndToEndVideoSessionTests extends BaseLoggedTest { - - final String teacherMail = "teacher@gmail.com"; - final String teacherPass = "pass"; final String studentMail = "student1@gmail.com"; final String studentPass = "pass"; - BrowserUser student; + public static Stream data() throws IOException { + return ParameterLoader.getTestTeachers(); + } public FullTeachingTestEndToEndVideoSessionTests() { super(); @@ -60,43 +59,43 @@ public FullTeachingTestEndToEndVideoSessionTests() { @AccessMode(resID = "OpenVidu", concurrency = 10, sharing = true, accessMode = "READWRITE") @Resource(resID = "Course", replaceable = {"Session"}) @AccessMode(resID = "Course", concurrency = 1, sharing = false, accessMode = "READWRITE") - @Test - void oneToOneVideoAudioSessionChrome() { //124+ 232+ 20 set up +8 lines teardown = 564 + @DisplayName("sessionTest") + @ParameterizedTest + @MethodSource("data") + void oneToOneVideoAudioSessionChrome(String mail, String password, String role) { //124+ 232+ 20 set up +8 lines teardown = 564 - String testName = new Object() { - }.getClass().getEnclosingMethod().getName(); - log.info("##### Start test: " + testName); // TEACHER - this.slowLogin(user, teacherMail, teacherPass);//24 + this.slowLogin(teacher, mail, password);//24 - log.info("{} entering first course", user.getClientData()); - user.getWaiter().until( + log.info("{} entering first course", teacher.getClientData()); + teacher.getWaiter().until( ExpectedConditions.presenceOfElementLocated(By.cssSelector( ("ul.collection li.collection-item:first-child div.course-title")))); - user.getDriver().findElement(By.cssSelector( + teacher.getDriver().findElement(By.cssSelector( "ul.collection li.collection-item:first-child div.course-title")) .click(); - log.info("{} navigating to 'Sessions' tab", user.getClientData()); - user.getWaiter().until(ExpectedConditions.presenceOfElementLocated( + log.info("{} navigating to 'Sessions' tab", teacher.getClientData()); + teacher.getWaiter().until(ExpectedConditions.presenceOfElementLocated( By.cssSelector(("#md-tab-label-0-1")))); - user.getDriver().findElement(By.cssSelector("#md-tab-label-0-1")) + teacher.getDriver().findElement(By.cssSelector("#md-tab-label-0-1")) .click(); - log.info("{} getting into first session", user.getClientData()); - user.getDriver() + log.info("{} getting into first session", teacher.getClientData()); + teacher.getDriver() .findElement(By.cssSelector( "ul div:first-child li.session-data div.session-ready")) .click(); - user.getWaiter().until(ExpectedConditions.presenceOfElementLocated( + teacher.getWaiter().until(ExpectedConditions.presenceOfElementLocated( By.cssSelector(("div.participant video")))); - checkVideoPlaying(user, - user.getDriver() + checkVideoPlaying(teacher, + teacher.getDriver() .findElement(By.cssSelector(("div.participant video"))), "div.participant"); //30 lines // STUDENT + student = setupBrowser(STUDENT_BROWSER, TJOB_NAME + "_" +"oneToOneVideoAudioSessionChrome-STUDENT", studentMail,5);//27 lines slowLogin(student, studentMail, studentPass); @@ -133,10 +132,10 @@ void oneToOneVideoAudioSessionChrome() { //124+ 232+ 20 set up +8 lines teardown .click(); // Teacher accepts intervention - user.getWaiter().until(ExpectedConditions.elementToBeClickable( + teacher.getWaiter().until(ExpectedConditions.elementToBeClickable( By.xpath("//a[contains(@class, 'usr-btn')]"))); - log.info("{} accepts student intervention", user.getClientData()); - user.getDriver() + log.info("{} accepts student intervention", teacher.getClientData()); + teacher.getDriver() .findElement(By.xpath("//a[contains(@class, 'usr-btn')]")) .click(); // Check both videos for both users @@ -152,27 +151,27 @@ void oneToOneVideoAudioSessionChrome() { //124+ 232+ 20 set up +8 lines teardown student.getDriver() .findElement(By.cssSelector(("div.participant video"))), "div.participant");//30 lines - user.getWaiter().until(ExpectedConditions.presenceOfElementLocated( + teacher.getWaiter().until(ExpectedConditions.presenceOfElementLocated( By.cssSelector(("div.participant-small video")))); // Small video of teacher - checkVideoPlaying(user, - user.getDriver().findElement( + checkVideoPlaying(teacher, + teacher.getDriver().findElement( By.cssSelector(("div.participant-small video"))), "div.participant-small");//30 lines // Main video of teacher - checkVideoPlaying(user, - user.getDriver() + checkVideoPlaying(teacher, + teacher.getDriver() .findElement(By.cssSelector(("div.participant video"))), - "div.participant");//30 lines waitSeconds(5); + "div.participant"); // Teacher stops student intervention - user.getWaiter().until(ExpectedConditions.elementToBeClickable( + teacher.getWaiter().until(ExpectedConditions.elementToBeClickable( By.xpath("//a[contains(@class, 'usr-btn')]"))); - log.info("{} canceling student intervention", user.getClientData()); - user.getDriver() + log.info("{} canceling student intervention", teacher.getClientData()); + teacher.getDriver() .findElement(By.xpath("//a[contains(@class, 'usr-btn')]")) .click(); // Wait until only one video - user.getWaiter().until(ExpectedConditions + teacher.getWaiter().until(ExpectedConditions .not(ExpectedConditions.presenceOfAllElementsLocatedBy( By.cssSelector(("div.participant-small video"))))); student.getWaiter().until(ExpectedConditions @@ -183,71 +182,6 @@ void oneToOneVideoAudioSessionChrome() { //124+ 232+ 20 set up +8 lines teardown } - @BeforeEach - void setup(TestInfo info) { //65 lines - String TEST_NAME; - if (info.getTestMethod().isPresent()) { - log.info("Custom Set-up for the OpenviduTest"); - TEST_NAME = info.getTestMethod().get().getName(); - } else { - TEST_NAME = "test-name-default"; - } - - log.info("##### Start test: " + TEST_NAME); - TJOB_NAME = System.getProperty("dirtarget"); - user = setupBrowser(TEACHER_BROWSER, TJOB_NAME + "_" + TEST_NAME, teacherMail, WAIT_SECONDS); - student = setupBrowser(STUDENT_BROWSER, TJOB_NAME + "_" + TEST_NAME, studentMail, WAIT_SECONDS);//27 lines - - } - - @AfterEach - void tearDown(TestInfo testInfo) { //13 lines - String testName; - if (testInfo.getTestMethod().isPresent()) { - - testName = testInfo.getTestMethod().get().getName(); - log.info("Custom TearDown the info is present"); - } else { - log.info("No test name, using default"); - testName = "No-named-test"; - } - - if (student != null) { - log.info("##### Finish test: {} - Driver {}", testName, this.student.getDriver()); - log.info("Browser console at the end of the test"); - LogEntries logEntries = student.getDriver().manage().logs().get(BROWSER); - logEntries.forEach((entry) -> log.info("[{}] {} {}", - new Date(entry.getTimestamp()), entry.getLevel(), - entry.getMessage())); - //TO-DO- ERROR with the logout - if (student.isOnSession()) { - this.logout(student); - } - student.dispose(); - - - } - - if (user != null) { - log.info("##### Finish test: {} - Driver {}", testName, this.user.getDriver()); - log.info("Browser console at the end of the test"); - LogEntries logEntries = user.getDriver().manage().logs().get(BROWSER); - logEntries.forEach((entry) -> log.info("[{}] {} {}", - new Date(entry.getTimestamp()), entry.getLevel(), - entry.getMessage())); - //TO-DO- ERROR with the logout - if (user.isOnSession()) { - this.logout(user); - } - - user.dispose(); - - - } - - - } - /* * @Test diff --git a/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/student/CourseStudentTest.java b/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/student/CourseStudentTest.java index 2a6b75e..75c6923 100644 --- a/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/student/CourseStudentTest.java +++ b/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/student/CourseStudentTest.java @@ -49,7 +49,7 @@ public static Stream data() throws IOException { @ParameterizedTest @MethodSource("data") void studentCourseMainTest(String userMail, String password, String role) {//45+ 107+28 set up +13 lines teardown =193 - this.slowLogin(user, userMail, password);//24 lines + this.slowLogin(teacher, userMail, password);//24 lines try { NavigationUtilities.toCoursesHome(driver); //3lines //go to first course diff --git a/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/teacher/CourseTeacherTest.java b/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/teacher/CourseTeacherTest.java index a2d83a1..dfd0cc4 100644 --- a/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/teacher/CourseTeacherTest.java +++ b/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/teacher/CourseTeacherTest.java @@ -50,7 +50,7 @@ public static Stream data() throws IOException { @ParameterizedTest @MethodSource("data") void teacherCourseMainTest(String mail, String password, String role) {//39+80+ 28 set up +13 lines teardown =160 - this.slowLogin(user, mail, password); + this.slowLogin(teacher, mail, password); try { NavigationUtilities.toCoursesHome(driver); //4lines @@ -106,23 +106,23 @@ void teacherCourseMainTest(String mail, String password, String role) {//39+80+ @MethodSource("data") void teacherCreateAndDeleteCourseTest(String mail, String password, String role) throws ElementNotFoundException { // Setup - this.slowLogin(user, mail, password); + this.slowLogin(teacher, mail, password); // Create a new course String courseTitle = "Test Course_" + System.currentTimeMillis(); - CourseNavigationUtilities.newCourse(user.getDriver(), courseTitle); + CourseNavigationUtilities.newCourse(teacher.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); + CourseNavigationUtilities.deleteCourse(teacher.getDriver(), courseTitle); // Verify the course has been deleted assertFalse(checkIfCourseExists(driver, courseTitle)); // Teardown - user.getDriver().get(APP_URL); + teacher.getDriver().get(APP_URL); } @@ -146,7 +146,7 @@ void teacherCreateAndDeleteCourseTest(String mail, String password, String role) @MethodSource("data") void teacherEditCourseValues(String mail, String password, String role) {//165+256+ 28 set up +13 lines teardown =462 String courseName = properties.getProperty("forum.test.course"); - this.slowLogin(user, mail, password); //24 lines + this.slowLogin(teacher, mail, password); //24 lines try { // navigate to course if not there NavigationUtilities.toCoursesHome(driver);//3lines @@ -193,7 +193,7 @@ void teacherEditCourseValues(String mail, String password, String role) {//165+2 //wait for editor md editor???' WebElement edit_description_desc = Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(By.className(EDIT_DESCRIPTION_CONTENT_BOX_CLASS))); //text here?? /html/body/app/div/com.fullteaching.e2e.no_elastest.main/app-course-details/div/div[4]/md-tab-group/div[2]/div[1]/div/div[2]/p-editor/div/div[2]/div[1] - String old_desc = edit_description_desc.getAttribute("ng-reflect-model"); + edit_description_desc.getAttribute("ng-reflect-model"); //delete old_desc log.info("Deleting old description"); WebElement editor = driver.findElement(By.className("ql-editor")); @@ -213,7 +213,7 @@ void teacherEditCourseValues(String mail, String password, String role) {//165+2 editor = driver.findElement(By.className("ql-editor")); jse.executeScript("arguments[0].innerHTML = '

New Title

New SubHeading

This is the normal content

'", editor); driver.findElement(By.xpath("//*[@id=\"textEditorRowButtons\"]/a[2]")).click(); - user.waitUntil(ExpectedConditions.visibilityOfElementLocated(By.className("ql-editor-custom")), "Element that was waiting doesn't found"); + teacher.waitUntil(ExpectedConditions.visibilityOfElementLocated(By.className("ql-editor-custom")), "Element that was waiting doesn't found"); WebElement preview = Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(By.className("ql-editor-custom"))); //check heading TO-DO : Error here, the type of font is not saved assertEquals("New Title", preview.findElement(By.tagName("h1")).getText(), "Heading preview not properly rendered"); @@ -253,7 +253,6 @@ void teacherEditCourseValues(String mail, String password, String role) {//165+2 //check if Forum is enabled if (ForumNavigationUtilities.isForumEnabled(forum_tab_content)) {//6lines - //if (enabled) //check entries ¡Only check if there is entries and all the buttons are present! log.info("Forum enabled checking that the entries and buttons are present"); assertNotNull(forum_tab_content.findElement(FORUM_NEW_ENTRY_ICON), "Add Entry not found"); @@ -310,7 +309,7 @@ void teacherEditCourseValues(String mail, String password, String role) {//165+2 @ParameterizedTest @MethodSource("data") void teacherDeleteCourseTest(String mail, String password, String role) throws ElementNotFoundException {//51+114+28 set up +13 lines teardown =206 - this.slowLogin(user, mail, password);//24 + this.slowLogin(teacher, mail, password);//24 String courseName = "Test Course_" + System.currentTimeMillis(); // navigate to course if not there try { @@ -333,9 +332,9 @@ void teacherDeleteCourseTest(String mail, String password, String role) throws E // in attenders // TODO: add attenders // delete course - List allCoursesPriorDeleting = user.getDriver().findElements(By.className("course-list-item")); - CourseNavigationUtilities.deleteCourse(user.getDriver(), courseName); - List allCourses = user.getDriver().findElements(By.className("course-list-item")); + List allCoursesPriorDeleting = teacher.getDriver().findElements(By.className("course-list-item")); + CourseNavigationUtilities.deleteCourse(teacher.getDriver(), courseName); + List allCourses = teacher.getDriver().findElements(By.className("course-list-item")); assertEquals(allCoursesPriorDeleting.size() - 1, allCourses.size()); //Well done! }