diff --git a/pom.xml b/pom.xml index 9edeb8a..d785aa5 100644 --- a/pom.xml +++ b/pom.xml @@ -150,9 +150,9 @@ - + ${basedir}/target/test-classes/${dirtarget} - + ${basedir}/target/classes/${dirtarget} 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..6f7060d 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 @@ -20,19 +20,18 @@ import java.io.FileInputStream; import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URISyntaxException; 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 +40,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; @@ -53,6 +51,8 @@ public class BaseLoggedTest { public WebDriver driver; protected BrowserUser user; + protected BrowserUser student; + protected List studentBrowserUserList; public BaseLoggedTest() { } @@ -66,7 +66,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 +85,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 @@ -109,19 +109,18 @@ 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); + void setup(TestInfo info) throws URISyntaxException, MalformedURLException { //65 lines + log.info("##### Start test: {}" , info.getTestMethod().get().getName()); TJOB_NAME = System.getProperty("dirtarget"); - user = setupBrowser("chrome", TJOB_NAME + "_" + TEST_NAME, userMail, WAIT_SECONDS); - driver = user.getDriver(); + this.user = setupBrowser("chrome", TJOB_NAME + "_" + info.getTestMethod().get().getName(), "Teacher", WAIT_SECONDS); + + this.driver = this.user.getDriver(); + } protected BrowserUser setupBrowser(String browser, String testName, - String userIdentifier, int secondsOfWait) { + String userIdentifier, int secondsOfWait) throws URISyntaxException, MalformedURLException { BrowserUser u; log.info("Starting browser ({})", browser); @@ -160,20 +159,41 @@ protected BrowserUser setupBrowser(String browser, String testName, } @AfterEach - void tearDown(TestInfo testInfo) { //13 lines - - if (user != null) { - log.info("##### Finish test: {} - Driver {}", TEST_NAME, this.user.getDriver()); + void tearDown(TestInfo info) { //13 lines + if (this.user != null) { + log.info("##### Finish test: {} - Driver {}", info.getTestMethod().get().getName(), 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("[{}] {} {}", + logEntries.forEach(entry -> log.info("[{}] {} {}", new Date(entry.getTimestamp()), entry.getLevel(), entry.getMessage())); - if (user.isOnSession()) { - this.logout(user); + if (this.user.isOnSession()) { + this.logout(this.user); } - user.dispose(); + this.user.dispose(); + } + + if (this.student != null) { + log.info("##### Finish test: {} - Driver {}", info.getTestMethod().get().getName(), 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())); + if (this.student.isOnSession()) { + this.logout(student); + } + + 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(); + } } } @@ -224,8 +244,11 @@ private void login(BrowserUser user, String userEmail, String userPass, try { userName = getUserName(user, true, APP_URL); } catch (NotLoggedException | ElementNotFoundException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + if (e.getClass().isInstance(NotLoggedException.class)){ + log.error("The user {} was not logged",user.getClientData());} + else{ + log.error("The userName field not found" ); + } } log.info("Logging in successful for user {}", user.getClientData()); @@ -233,10 +256,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")) @@ -309,7 +331,7 @@ protected void openDialog(String cssSelector, BrowserUser user) { "//div[contains(@class, 'modal-overlay') and contains(@style, 'opacity: 0.5')]")), "Dialog not opened"); - log.info("Dialog opened for user {}", user.getClientData()); + log.info("Dialog opened using css selector for user {}", user.getClientData()); } protected void openDialog(WebElement el, BrowserUser user) {//8lines @@ -321,7 +343,7 @@ protected void openDialog(WebElement el, BrowserUser user) {//8lines user.waitUntil(ExpectedConditions.presenceOfElementLocated(By.xpath( "//div[contains(@class, 'modal-overlay') and contains(@style, 'opacity: 0.5')]")), "Dialog not opened"); - log.info("Dialog opened for user {}", user.getClientData()); + log.info("Dialog using webelement for user {}", user.getClientData()); } protected void waitForDialogClosed(String dialogId, String errorMessage, @@ -347,7 +369,7 @@ protected void waitSeconds(int seconds) { try { Thread.sleep(1000L * seconds); } catch (InterruptedException e) { - e.printStackTrace(); + log.error("Thread.sleep interrupted"); } } @@ -372,14 +394,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/common/BrowserUser.java b/src/test/java/com/fullteaching/e2e/no_elastest/common/BrowserUser.java index 7c23457..3be0dd4 100644 --- a/src/test/java/com/fullteaching/e2e/no_elastest/common/BrowserUser.java +++ b/src/test/java/com/fullteaching/e2e/no_elastest/common/BrowserUser.java @@ -26,8 +26,6 @@ import java.time.Duration; -import static java.lang.invoke.MethodHandles.lookup; -import static org.slf4j.LoggerFactory.getLogger; public class BrowserUser { diff --git a/src/test/java/com/fullteaching/e2e/no_elastest/common/ChromeUser.java b/src/test/java/com/fullteaching/e2e/no_elastest/common/ChromeUser.java index b2266aa..a64bfec 100644 --- a/src/test/java/com/fullteaching/e2e/no_elastest/common/ChromeUser.java +++ b/src/test/java/com/fullteaching/e2e/no_elastest/common/ChromeUser.java @@ -25,7 +25,8 @@ import org.openqa.selenium.support.ui.WebDriverWait; import java.net.MalformedURLException; -import java.net.URL; +import java.net.URI; +import java.net.URISyntaxException; import java.text.SimpleDateFormat; import java.time.Duration; import java.time.LocalDateTime; @@ -41,25 +42,19 @@ public class ChromeUser extends BrowserUser { ChromeOptions options = new ChromeOptions(); - public ChromeUser(String userName, int timeOfWaitInSeconds, String testName, String userIdentifier) { + public ChromeUser(String userName, int timeOfWaitInSeconds, String testName, String userIdentifier) throws URISyntaxException, MalformedURLException { super(userName, timeOfWaitInSeconds); log.info("Starting the configuration of the web browser"); - log.debug(String.format("The Test names are: %s", testName)); + log.debug(String.format("The Test name is: %s", testName)); LoggingPreferences logPrefs = new LoggingPreferences(); logPrefs.enable(BROWSER, ALL); options.setCapability("goog:loggingPrefs", logPrefs); //Problems with the max attempt of retry, solved with : https://github.com/aerokube/selenoid/issues/1124 solved with --disable-gpu + // options.addArguments("--disable-gpu"); Commented for the moment //Problems with flakiness due to screen resolution solved with --start-maximized - String[] arguments = {"--no-sandbox", "--disable-dev-shm-usage", "--allow-elevated-browser", "--disable-gpu", "--start-maximized"}; - - log.debug("Adding the arguments ({})", Arrays.toString(arguments)); - for (String argument : arguments - ) { - options.addArguments(argument); - } - + options.addArguments("--start-maximized"); options.setAcceptInsecureCerts(true); //This capability is to store the logs of the test case log.debug("Added Capabilities of acceptInsecureCerts and ignore alarms"); @@ -68,8 +63,6 @@ public ChromeUser(String userName, int timeOfWaitInSeconds, String testName, Str log.info("Using the Local WebDriver ()"); this.driver = new ChromeDriver(options); } else { - try { - Map selenoidOptions = new HashMap<>(); log.info("Using the remote WebDriver (Selenoid)"); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd_HH:mm"); @@ -85,7 +78,7 @@ public ChromeUser(String userName, int timeOfWaitInSeconds, String testName, Str LocalDateTime now = LocalDateTime.now(); String logName = System.getProperty("tjob_name") + "-" + dtf.format(now) + "-" + testName + "-" + userIdentifier + ".log"; String videoName = System.getProperty("tjob_name") + "-" + dtf.format(now) + "-" + testName + "-" + userIdentifier + ".mp4"; - log.debug("The data of this test would be stored into: video name " + videoName + " and the log is " + logName); + log.debug("The data of this test would be stored into: video name: {} and the log name: {} " , videoName,logName); selenoidOptions.put("enableLog", true); selenoidOptions.put("logName ", logName); @@ -97,13 +90,10 @@ public ChromeUser(String userName, int timeOfWaitInSeconds, String testName, Str //END CAPABILITIES FOR SELENOID RETORCH log.debug("Configuring the remote WebDriver "); - RemoteWebDriver remote = new RemoteWebDriver(new URL("http://selenoid:4444/wd/hub"), options); + RemoteWebDriver remote = new RemoteWebDriver(new URI("http://selenoid:4444/wd/hub").toURL(), options); log.debug("Configuring the Local File Detector"); remote.setFileDetector(new LocalFileDetector()); this.driver = remote; - } catch (MalformedURLException e) { - throw new RuntimeException("Exception creating eusApiURL", e); - } } log.debug("Configure the driver connection timeouts at ({})", this.timeOfWaitInSeconds); new WebDriverWait(driver, Duration.ofSeconds(this.timeOfWaitInSeconds)); diff --git a/src/test/java/com/fullteaching/e2e/no_elastest/common/EdgeUser.java b/src/test/java/com/fullteaching/e2e/no_elastest/common/EdgeUser.java index 11a7811..3d46ba3 100644 --- a/src/test/java/com/fullteaching/e2e/no_elastest/common/EdgeUser.java +++ b/src/test/java/com/fullteaching/e2e/no_elastest/common/EdgeUser.java @@ -24,7 +24,8 @@ import org.openqa.selenium.support.ui.WebDriverWait; import java.net.MalformedURLException; -import java.net.URL; +import java.net.URI; +import java.net.URISyntaxException; import java.text.SimpleDateFormat; import java.time.Duration; import java.time.LocalDateTime; @@ -36,7 +37,7 @@ public class EdgeUser extends BrowserUser { EdgeOptions options = new EdgeOptions(); - public EdgeUser(String userName, int timeOfWaitInSeconds, String testName, String userIdentifier) { + public EdgeUser(String userName, int timeOfWaitInSeconds, String testName, String userIdentifier) throws URISyntaxException { super(userName, timeOfWaitInSeconds); log.info(String.format("The Test names are: %s", testName)); @@ -67,7 +68,7 @@ public EdgeUser(String userName, int timeOfWaitInSeconds, String testName, Strin LocalDateTime now = LocalDateTime.now(); String logName = dtf.format(now) + "-" + testName + "-" + userIdentifier + ".log"; String videoName = dtf.format(now) + "_" + testName + "_" + userIdentifier + ".mp4"; - log.debug("The data of this test would be stored into: video name " + videoName + " and the log is " + logName); + log.debug("The data of this test would be stored into: video name {} and the log is {}", videoName,logName); selenoidOptions.put("enableLog", true); selenoidOptions.put("logName ", logName); @@ -79,7 +80,7 @@ public EdgeUser(String userName, int timeOfWaitInSeconds, String testName, Strin //END CAPABILITIES FOR SELENOID RETORCH - RemoteWebDriver remote = new RemoteWebDriver(new URL(eusApiURL), options); + RemoteWebDriver remote = new RemoteWebDriver(new URI(eusApiURL).toURL(), options); remote.setFileDetector(new LocalFileDetector()); diff --git a/src/test/java/com/fullteaching/e2e/no_elastest/common/FirefoxUser.java b/src/test/java/com/fullteaching/e2e/no_elastest/common/FirefoxUser.java index e8a9fc3..8ca21e4 100644 --- a/src/test/java/com/fullteaching/e2e/no_elastest/common/FirefoxUser.java +++ b/src/test/java/com/fullteaching/e2e/no_elastest/common/FirefoxUser.java @@ -24,7 +24,8 @@ import org.openqa.selenium.remote.RemoteWebDriver; import java.net.MalformedURLException; -import java.net.URL; +import java.net.URI; +import java.net.URISyntaxException; import java.text.SimpleDateFormat; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; @@ -35,7 +36,7 @@ public class FirefoxUser extends BrowserUser { FirefoxOptions options = new FirefoxOptions(); - public FirefoxUser(String userName, int timeOfWaitInSeconds, String testName, String userIdentifier) { + public FirefoxUser(String userName, int timeOfWaitInSeconds, String testName, String userIdentifier) throws URISyntaxException { super(userName, timeOfWaitInSeconds); //TO-DO Firefox configuration has changed, review it. FirefoxProfile profile = new FirefoxProfile(); @@ -74,8 +75,7 @@ public FirefoxUser(String userName, int timeOfWaitInSeconds, String testName, St LocalDateTime now = LocalDateTime.now(); String logName = dtf.format(now) + "-" + testName + "-" + userIdentifier + ".log"; String videoName = dtf.format(now) + "_" + testName + "_" + userIdentifier + ".mp4"; - log.debug("The data of this test would be stored into: video name " + videoName + " and the log is " + logName); - + log.debug("The data of this test would be stored into: video name {} and the log is {}", videoName,logName); selenoidOptions.put("enableLog", true); selenoidOptions.put("logName ", logName); selenoidOptions.put("videoName", videoName); @@ -86,7 +86,7 @@ public FirefoxUser(String userName, int timeOfWaitInSeconds, String testName, St //END CAPABILITIES FOR SELENOID RETORCH - RemoteWebDriver remote = new RemoteWebDriver(new URL(eusApiURL), options); + RemoteWebDriver remote = new RemoteWebDriver(new URI(eusApiURL).toURL(), options); remote.setFileDetector(new LocalFileDetector()); @@ -99,7 +99,6 @@ public FirefoxUser(String userName, int timeOfWaitInSeconds, String testName, St } } - //this.driver.manage().timeouts().setScriptTimeout(this.timeOfWaitInSeconds, TimeUnit.SECONDS); this.configureDriver(); } diff --git a/src/test/java/com/fullteaching/e2e/no_elastest/common/ForumNavigationUtilities.java b/src/test/java/com/fullteaching/e2e/no_elastest/common/ForumNavigationUtilities.java index 8818230..6f4b3d9 100644 --- a/src/test/java/com/fullteaching/e2e/no_elastest/common/ForumNavigationUtilities.java +++ b/src/test/java/com/fullteaching/e2e/no_elastest/common/ForumNavigationUtilities.java @@ -15,10 +15,8 @@ import java.util.List; 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.slf4j.LoggerFactory.getLogger; public class ForumNavigationUtilities { @@ -72,7 +70,7 @@ public static WebElement getEntry(WebDriver wd, String entry_name) throws Elemen try { WebElement title = entry.findElement(FORUM_ENTRY_LIST_ENTRY_TITLE); String title_text = title.getText(); - if (title_text == null || title_text.equals("")) { + if (title_text == null || title_text.isEmpty()) { title_text = title.getAttribute("innerHTML"); } if (entry_name.equals(title_text)) { diff --git a/src/test/java/com/fullteaching/e2e/no_elastest/common/NavigationUtilities.java b/src/test/java/com/fullteaching/e2e/no_elastest/common/NavigationUtilities.java index 9e8c469..e0464f6 100644 --- a/src/test/java/com/fullteaching/e2e/no_elastest/common/NavigationUtilities.java +++ b/src/test/java/com/fullteaching/e2e/no_elastest/common/NavigationUtilities.java @@ -13,8 +13,6 @@ import static com.fullteaching.e2e.no_elastest.common.BaseLoggedTest.HOST; import static com.fullteaching.e2e.no_elastest.common.Constants.*; -import static java.lang.invoke.MethodHandles.lookup; -import static org.slf4j.LoggerFactory.getLogger; public class NavigationUtilities { diff --git a/src/test/java/com/fullteaching/e2e/no_elastest/common/SessionNavigationUtilities.java b/src/test/java/com/fullteaching/e2e/no_elastest/common/SessionNavigationUtilities.java index 97bb89a..c5afdb3 100644 --- a/src/test/java/com/fullteaching/e2e/no_elastest/common/SessionNavigationUtilities.java +++ b/src/test/java/com/fullteaching/e2e/no_elastest/common/SessionNavigationUtilities.java @@ -29,7 +29,7 @@ public static WebElement getSession(WebDriver wd, String session_name) throws El try { WebElement title = session.findElement(SESSION_LIST_SESSION_NAME); String title_text = title.getText(); - if (title_text == null || title_text.equals("")) { + if (title_text == null || title_text.isEmpty()) { title_text = title.getAttribute("innerHTML"); } if (session_name.equals(title_text)) { diff --git a/src/test/java/com/fullteaching/e2e/no_elastest/common/SpiderNavigation.java b/src/test/java/com/fullteaching/e2e/no_elastest/common/SpiderNavigation.java index ee8dfaf..9a342f8 100644 --- a/src/test/java/com/fullteaching/e2e/no_elastest/common/SpiderNavigation.java +++ b/src/test/java/com/fullteaching/e2e/no_elastest/common/SpiderNavigation.java @@ -35,10 +35,9 @@ public static List getPageLinks(WebDriver wd) { //29 lines List a_lst = wd.findElements(By.tagName("a")); for (WebElement a : a_lst) { String href = a.getAttribute("href"); - if ((href != null) && (!href.trim().equals("")) && (!href.contains("#"))) { - if (isContainedIn(href.trim(), links_href) && href.contains(host)) + if ((href != null) && (!href.trim().isEmpty()) && (!href.contains("#")) && isContainedIn(href.trim(), links_href) && href.contains(host)) links.add(a); - } + } return links; } @@ -54,10 +53,8 @@ public static List getUnexploredPageLinks(WebDriver wd, Map allLinks = getPageLinks(wd); for (WebElement a : allLinks) { String href = a.getAttribute("href"); - if ((href != null) && (!href.trim().equals("")) && (!href.contains("#"))) { - if (isContainedIn(href.trim(), explored.keySet()) && href.contains(host)) //8lines - links.add(a); - } + if ((href != null) && (!href.trim().isEmpty()) && (!href.contains("#")) && isContainedIn(href.trim(), explored.keySet()) && href.contains(host)) + links.add(a); } return links; } @@ -102,20 +99,18 @@ private static boolean isContainedIn(String href, Set set) { // 8lines } public static Set addNonExistentLink(Set original, String href) { //5lines - if ((href != null) && (!href.equals("")) && (!href.contains("#"))) { - if (isContainedIn(href, original) && href.contains(host)) + if ((href != null) && (!href.isEmpty()) && (!href.contains("#")) && isContainedIn(href, original) && href.contains(host)) original.add(href); - } + return original; } public static List discardExplored(List new_links, Set explored) { //8 lines List withOutExplored = new ArrayList<>(); for (String href : new_links) { - if ((href != null) && (!href.equals("")) && (!href.contains("#"))) { - if (isContainedIn(href, explored) && href.contains(host)) + if ((href != null) && (!href.isEmpty()) && (!href.contains("#")) && isContainedIn(href, explored) && href.contains(host)) withOutExplored.add(href); - } + } return withOutExplored; } diff --git a/src/test/java/com/fullteaching/e2e/no_elastest/common/UserUtilities.java b/src/test/java/com/fullteaching/e2e/no_elastest/common/UserUtilities.java index 2addef3..5a3d84d 100644 --- a/src/test/java/com/fullteaching/e2e/no_elastest/common/UserUtilities.java +++ b/src/test/java/com/fullteaching/e2e/no_elastest/common/UserUtilities.java @@ -14,8 +14,6 @@ import org.slf4j.LoggerFactory; import static com.fullteaching.e2e.no_elastest.common.Constants.*; -import static java.lang.invoke.MethodHandles.lookup; -import static org.slf4j.LoggerFactory.getLogger; public class UserUtilities { 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..4fa355c 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 @@ -12,7 +12,6 @@ import giis.retorch.annotations.AccessMode; import giis.retorch.annotations.Resource; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Tag; import org.junit.jupiter.params.ParameterizedTest; @@ -23,7 +22,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 +29,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") @@ -66,6 +62,7 @@ public static Stream data() throws IOException { @AccessMode(resID = "OpenVidu", concurrency = 10, sharing = true, accessMode = "NOACCESS") @Resource(resID = "Course", replaceable = {"Forum"}) @AccessMode(resID = "Course", concurrency = 10, sharing = true, accessMode = "READONLY") + @DisplayName("studentCourseMainTest") @ParameterizedTest @MethodSource("data") void forumLoadEntriesTest(String mail, String password, String role) { //47lines +115 +28 set up +13 lines teardown =203 @@ -74,7 +71,7 @@ void forumLoadEntriesTest(String mail, String password, String role) { //47lines //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"); @@ -134,6 +131,7 @@ void forumLoadEntriesTest(String mail, String password, String role) { //47lines @AccessMode(resID = "OpenVidu", concurrency = 10, sharing = true, accessMode = "NOACCESS") @Resource(resID = "Course", replaceable = {"Forum"}) @AccessMode(resID = "Course", concurrency = 1, sharing = false, accessMode = "READWRITE") + @DisplayName("studentCourseMainTest") @ParameterizedTest @MethodSource("data") void forumNewEntryTest(String mail, String password, String role) {// 48+ 104 + 28 set up +13 lines teardown =193 @@ -180,7 +178,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); @@ -211,6 +209,7 @@ void forumNewEntryTest(String mail, String password, String role) {// 48+ 104 + @AccessMode(resID = "OpenVidu", concurrency = 10, sharing = true, accessMode = "NOACCESS") @Resource(resID = "Course", replaceable = {"Forum"}) @AccessMode(resID = "Course", concurrency = 1, sharing = false, accessMode = "READWRITE") + @DisplayName("forumNewCommentTest") @ParameterizedTest @MethodSource("data") void forumNewCommentTest(String mail, String password, String role) { // 69+142 + 28 set up +13 lines teardown =252 @@ -299,15 +298,17 @@ void forumNewCommentTest(String mail, String password, String role) { // 69+142 * previously created, go to the first and replies to the same comment.After it, we check * that the comment was correctly published. */ - @Disabled - @ParameterizedTest - @MethodSource("data") + + @Resource(resID = "LoginService", replaceable = {}) @AccessMode(resID = "LoginService", concurrency = 10, sharing = true, accessMode = "READONLY") @Resource(resID = "OpenVidu", replaceable = {"OpenViduMock"}) @AccessMode(resID = "OpenVidu", concurrency = 10, sharing = true, accessMode = "NOACCESS") @Resource(resID = "Course", replaceable = {"Forum"}) @AccessMode(resID = "Course", concurrency = 1, sharing = false, accessMode = "READWRITE") + @DisplayName("forumNewReply2CommentTest") + @ParameterizedTest + @MethodSource("data") void forumNewReply2CommentTest(String mail, String password, String role) { // 63+137+ 28 set up +13 lines teardown = 242 this.slowLogin(user, mail, password);//24 lines Calendar calendar = Calendar.getInstance(); 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..afe2bc6 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,11 @@ 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.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.WebElement; -import org.slf4j.Logger; import java.io.IOException; import java.util.ArrayList; @@ -21,39 +19,34 @@ 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 * that the response of the rest service was KO* */ - @ParameterizedTest - @MethodSource("data") + @Resource(resID = "LoginService", replaceable = {}) @AccessMode(resID = "LoginService", concurrency = 10, sharing = true, accessMode = "READONLY") @Resource(resID = "OpenVidu", replaceable = {"OpenViduMock"}) @AccessMode(resID = "OpenVidu", concurrency = 10, sharing = true, accessMode = "NOACCESS") @Resource(resID = "Course", replaceable = {}) @AccessMode(resID = "Course", concurrency = 15, sharing = true, accessMode = "READWRITE") + @ParameterizedTest + @MethodSource("data") + @DisplayName("spiderLoggedTest") void spiderLoggedTest(String mail, String password, String role) { //140 + 28 set up +13 lines teardown = 181 this.slowLogin(user, mail, password); //*navigate from home*//* @@ -66,7 +59,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/UnLoggedLinksTests.java b/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/UnLoggedLinksTests.java index d3ae0a7..c53d9be 100644 --- a/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/UnLoggedLinksTests.java +++ b/src/test/java/com/fullteaching/e2e/no_elastest/functional/test/UnLoggedLinksTests.java @@ -6,11 +6,11 @@ import com.fullteaching.e2e.no_elastest.utils.ParameterLoader; import giis.retorch.annotations.AccessMode; import giis.retorch.annotations.Resource; +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.WebElement; -import org.slf4j.Logger; import java.io.IOException; import java.util.ArrayList; @@ -19,9 +19,7 @@ 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; class UnLoggedLinksTests extends BaseLoggedTest { @@ -30,17 +28,18 @@ public UnLoggedLinksTests() { } public static Stream data() throws IOException { - return ParameterLoader.getTestUsers(); + return ParameterLoader.getTestTeachers(); } - @ParameterizedTest - @MethodSource("data") @Resource(resID = "LoginService", replaceable = {}) @AccessMode(resID = "LoginService", concurrency = 10, sharing = true, accessMode = "READONLY") @Resource(resID = "OpenVidu", replaceable = {"OpenViduMock"}) @AccessMode(resID = "OpenVidu", concurrency = 10, sharing = true, accessMode = "NOACCESS") @Resource(resID = "Course", replaceable = {}) @AccessMode(resID = "Course", concurrency = 15, sharing = true, accessMode = "READWRITE") + @ParameterizedTest + @MethodSource("data") + @DisplayName("spiderUnloggedTest") void spiderUnloggedTest(String mail, String password, String role) { //125 lines + 28 set up +13 lines teardown = 166 userMail = "nonloged@gmail.com"; 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..2b1184a 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 @@ -9,6 +9,7 @@ import giis.retorch.annotations.AccessMode; import giis.retorch.annotations.Resource; import io.github.bonigarcia.seljup.SeleniumJupiter; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; @@ -33,23 +34,23 @@ public static Stream data() throws IOException { * This test is a simple logging acknowledgement, that checks if the current logged user * was logged correctly */ - - @ParameterizedTest - @MethodSource("data") @Resource(resID = "LoginService", replaceable = {}) @AccessMode(resID = "LoginService", concurrency = 10, sharing = true, accessMode = "READONLY") @Resource(resID = "OpenVidu", replaceable = {"OpenViduMock"}) @AccessMode(resID = "OpenVidu", concurrency = 10, sharing = true, accessMode = "NOACCESS") + @ParameterizedTest + @MethodSource("data") + @DisplayName("loginTest") 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 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 { 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 4773642..16b3a1f 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,24 @@ 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.net.MalformedURLException; +import java.net.URISyntaxException; 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. @@ -44,19 +47,15 @@ @Tag("e2e") @DisplayName("E2E tests for FullTeaching chat") -@ExtendWith(SeleniumJupiter.class) 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") @@ -64,12 +63,15 @@ 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 ) throws URISyntaxException, MalformedURLException { //197 Lines of code + int numberpriormessages; // TEACHER - this.slowLogin(user, teacherMail, teacherPass);//24 + this.slowLogin(user, mail, password);//24 log.info("{} entering first course", user.getClientData()); user.getWaiter().until(ExpectedConditions.presenceOfElementLocated( @@ -89,6 +91,8 @@ void oneToOneChatInSessionChrome() { //197 Lines of code checkSystemMessage("Connected", user, 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( @@ -170,61 +174,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 32fa771..7024a20 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; @@ -47,17 +50,18 @@ //@Disabled @Tag("e2e") @DisplayName("E2E tests for FullTeaching REST CRUD operations") -@ExtendWith(SeleniumJupiter.class) 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(); } @@ -70,17 +74,19 @@ 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 } - private void loginAndCreateNewCourse() throws ElementNotFoundException { - slowLogin(user, TEACHER_MAIL, TEACHER_PASS); + private void loginAndCreateNewCourse(String mail, String password) throws ElementNotFoundException { + slowLogin(user, mail, password); CourseNavigationUtilities.newCourse(user.getDriver(), COURSE_NAME); } @@ -104,9 +110,11 @@ 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"); log.info("Editing course information"); @@ -126,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(); @@ -207,9 +217,11 @@ 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 @@ -279,9 +291,11 @@ 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")), @@ -380,9 +394,11 @@ 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), 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..b7f6bf1 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,32 +6,33 @@ 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; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; +import java.net.URISyntaxException; 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 +40,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,11 +60,13 @@ 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, URISyntaxException { String sessionName = "Today's Session"; courseName = "Pseudoscientific course for treating the evil eye"; - this.slowLogin(this.user, "teacher@gmail.com", "pass"); + this.slowLogin(this.user, mail, password); initializeStudents("src/test/resources/inputs/default_user_LoggedVideoStudents.csv"); createNewSession(sessionName); joinSession(sessionName, this.user); @@ -75,7 +81,8 @@ void sessionTest() throws ElementNotFoundException, IOException { * @param pathData the path to the CSV file containing student data * @throws IOException if there is an error reading the file */ - private void initializeStudents(String pathData) throws IOException { + private void initializeStudents(String pathData) throws IOException, URISyntaxException { + log.info("Initializing students"); String users_data = loadStudentsData(pathData); studentNameList = new ArrayList<>(); studentPassList = new ArrayList<>(); @@ -94,6 +101,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, @@ -225,29 +233,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 2d6d0c8..5f660d2 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,36 +19,36 @@ 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.net.MalformedURLException; +import java.net.URISyntaxException; +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*/ @Disabled @Tag("e2e") @DisplayName("E2E tests for FullTeaching video session") -@ExtendWith(SeleniumJupiter.class) 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(); @@ -61,14 +61,13 @@ 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) throws URISyntaxException, MalformedURLException { //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(user, mail, password);//24 log.info("{} entering first course", user.getClientData()); user.getWaiter().until( @@ -98,6 +97,7 @@ void oneToOneVideoAudioSessionChrome() { //124+ 232+ 20 set up +8 lines teardown .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); @@ -164,7 +164,7 @@ void oneToOneVideoAudioSessionChrome() { //124+ 232+ 20 set up +8 lines teardown checkVideoPlaying(user, user.getDriver() .findElement(By.cssSelector(("div.participant video"))), - "div.participant");//30 lines waitSeconds(5); + "div.participant"); // Teacher stops student intervention user.getWaiter().until(ExpectedConditions.elementToBeClickable( By.xpath("//a[contains(@class, 'usr-btn')]"))); @@ -184,71 +184,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..126141e 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 @@ -8,8 +8,7 @@ import com.fullteaching.e2e.no_elastest.utils.Wait; 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.api.DisplayName; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; @@ -25,7 +24,6 @@ import static org.junit.jupiter.api.Assertions.fail; -@ExtendWith(SeleniumJupiter.class) class CourseStudentTest extends BaseLoggedTest { @@ -46,6 +44,7 @@ public static Stream data() throws IOException { @AccessMode(resID = "LoginService", concurrency = 10, sharing = true, accessMode = "READONLY") @Resource(resID = "OpenVidu", replaceable = {"OpenViduMock"}) @AccessMode(resID = "OpenVidu", concurrency = 10, sharing = true, accessMode = "NOACCESS") + @DisplayName("studentCourseMainTest") @ParameterizedTest @MethodSource("data") void studentCourseMainTest(String userMail, String password, String role) {//45+ 107+28 set up +13 lines teardown =193 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..6a40448 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 @@ -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")); @@ -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");