Index: lams_tests/tests/org/lamsfoundation/lams/admin/AccessControlTests.java =================================================================== RCS file: /usr/local/cvsroot/lams_tests/tests/org/lamsfoundation/lams/admin/AccessControlTests.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_tests/tests/org/lamsfoundation/lams/admin/AccessControlTests.java 4 Nov 2014 21:46:22 -0000 1.1 @@ -0,0 +1,548 @@ +/**************************************************************** + * Copyright (C) 2014 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + +package org.lamsfoundation.lams.admin; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import java.util.concurrent.TimeUnit; + +import org.lamsfoundation.lams.admin.util.AdminConstants; +import org.lamsfoundation.lams.author.util.AuthorConstants; +import org.lamsfoundation.lams.pages.AbstractPage; +import org.lamsfoundation.lams.pages.IndexPage; +import org.lamsfoundation.lams.pages.LoginPage; +import org.lamsfoundation.lams.pages.admin.CourseManagementPage; +import org.lamsfoundation.lams.pages.author.FLAPage; +import org.lamsfoundation.lams.pages.monitor.addlesson.AddLessonPage; +import org.lamsfoundation.lams.util.LamsUtil; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.support.PageFactory; +import org.testng.Assert; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.AfterClass; + +/** + * LAMS Security tests + * + * - creates a course + * - creates three users within a course: + * * author + * * monitor + * * learner + * - login as Author + * - create a lesson + * - start lesson + * + * Author checks + * - can access lesson (shouldn't) + * + * + * Learner checks can access: + * - author (shouldn't) + * - monitor dialog + * - notifications + * - lesson gradebook + * - conditions + * - sysadmin menu + * + * @author Ernie Ghiglione (ernieg@lamsfoundation.org) + * + */ +public class AccessControlTests { + + private static final String NO_ROLE_RESPONSE = "Your current role does not allow you to view this page"; + private static final String RANDOM_INT = LamsUtil.randInt(0, 9999); + + private static final String COURSE_NAME = "Course " + RANDOM_INT; + private static final String AUTHOR_USER = "author" + RANDOM_INT; + private static final String MONITOR_USER = "monitor" + RANDOM_INT; + private static final String LEARNER_USER = "learner" + RANDOM_INT; + private static final String DESIGN_NAME = "design" + RANDOM_INT; + + + private static WebDriver driver = null; + private LoginPage onLogin; + private IndexPage index; + private FLAPage fla; + private AddLessonPage addLesson; + private AbstractPage sysAdmin; + private CourseManagementPage cMgt; + + @BeforeClass + public void beforeClass() { + + driver = new FirefoxDriver(); + driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); + + onLogin = PageFactory.initElements(driver, LoginPage.class); + index = PageFactory.initElements(driver, IndexPage.class); + cMgt = PageFactory.initElements(driver, CourseManagementPage.class); + fla = PageFactory.initElements(driver, FLAPage.class); + addLesson = PageFactory.initElements(driver, AddLessonPage.class); + sysAdmin = PageFactory.initElements(driver, AbstractPage.class); + onLogin.navigateToLamsLogin().loginAs("sysadmin", "sysadmin"); + + + } + + @AfterClass + public void afterClass() { + driver.quit(); + } + + /** + * Opens Course management interface + */ + @Test + public void openCourseMgt() { + + CourseManagementPage cMgt = new CourseManagementPage(driver); + cMgt = index.openCourseManagement(); + cMgt.maximizeWindows(); + Assert.assertEquals(cMgt.getTitle(), AdminConstants.COURSE_MGT_TITLE, + "The expected title is not present"); + + } + + /** + * Creates a new course + */ + @Test(dependsOnMethods="openCourseMgt") + public void createCourse() { + + String courseCode = "CF" + RANDOM_INT; + String courseDescription = "Some description " + RANDOM_INT; + String courseLocale = "English (Australia)"; + String status = "Active"; + + cMgt.createEditCourse() + .setCourseName(COURSE_NAME) + .setCourseCode(courseCode) + .setDescription(courseDescription) + .setLocale(courseLocale) + .setStatus(status) + .setEnableCourseNotifications() + .setEnableGradebookForMonitors() + .setEnableGradebookForLearners() + .setEnableSingleActivityLessons() + .save(); + + cMgt.clickIdSorter(); + cMgt.clickIdSorter(); + + + Boolean assertExists = cMgt.courseExists(COURSE_NAME); + Assert.assertTrue(assertExists, "Course doesn't exist!"); + + } + + /** + * Data provider to create users + * + */ + @DataProvider(name = "Users") + public static Object[][] users() { + return new Object[][] { + new Object[] { AUTHOR_USER, "Author", "User", "author@lams.com" }, + { MONITOR_USER, "Monitor", "User", "monitor@lams.com" }, + { LEARNER_USER, "Learner", "User", "learner@lams.com" } + }; + } + + + /** + * Creates users based on data provider + * + * @param login + * @param firstName + * @param lastName + * @param email + */ + @Test(dependsOnMethods="createCourse", dataProvider="Users") + public void createUser(String login, String firstName, String lastName, String email) { + + cMgt.createEditUser() + .setLogin(login) + .setPassword(RANDOM_INT) + .setPasswordConfirmation(RANDOM_INT) + .setFirstName(firstName) + .setLastName(lastName) + .setEmail(email) + .save() + .manageCourses() + .clickIdSorter() + .clickIdSorter(); + + + + } + + /** + * Data provider to create users + * + */ + @DataProvider(name = "UsersRoles") + public static Object[][] usersRoles() { + return new Object[][] { + new Object[] { AUTHOR_USER, "Author Monitor"}, + { MONITOR_USER, "Monitor" }, + { LEARNER_USER, "Learner"} + }; + } + + /** + * Add users to course with specific roles + * + * @param login username + * @param roles List of roles + */ + @Test(dependsOnMethods="createUser", dataProvider="UsersRoles") + public void addUserToCourse(String login, String roles) { + + List roleList = new ArrayList(); + + for (String role : roles.split(" ")) { + roleList.add(role); + } + + cMgt.getCourse(COURSE_NAME) + .manageUsers() + .addRemoveUser(login, roleList); + + + } + + /** + * Logins as Author and creates a one activity design + */ + + @Test(dependsOnMethods="addUserToCourse") + public void createDesign() { + + cMgt.closeWindow(); + String windowHandle = getPopUpWindowId(driver); + + driver.switchTo().window(windowHandle); + index.logOut(); + onLogin.loginAs(AUTHOR_USER, RANDOM_INT); + + fla = index.openFla(); + fla.maximizeWindows(); + Assert.assertEquals(AuthorConstants.FLA_TITLE, fla.getTitle(), + "The expected title is not present"); + + fla.dragActivityToCanvas(AuthorConstants.FORUM_TITLE); + + String saveResult = fla.saveAsDesign(DESIGN_NAME); + + Assert.assertTrue(saveResult.contains(AuthorConstants.SAVE_SEQUENCE_SUCCESS_MSG), + "There was an error saving the design " + saveResult ); + + fla.closeWindow(); + } + + /** + * Starts lesson based on design + */ + @Test(dependsOnMethods="createDesign") + public void startLesson() { + + String windowHandle = getPopUpWindowId(driver); + + driver.switchTo().window(windowHandle); + + addLesson = index.addLesson(); + + List designNodes = addLesson + .openLessontab() + .getFolderNodes("user"); + + addLesson + .openLessontab() + .clickDesign(designNodes.get(0)); + + addLesson.addLessonNow(); + + boolean assertLessonExists = index.isLessonPresent(DESIGN_NAME); + + Assert.assertTrue(assertLessonExists, + "The lesson is not present"); + + } + + /** + * Author test if it can access lesson as learner via JS + * + */ + @Test(dependsOnMethods="startLesson") + public void authorAccessLesson() { + + // This checks if the lesson is available to Author in the page + // essentially if the link is clickable + + boolean assertAccessLessonAsLearner = index.isLessonAvailableAsLearner(DESIGN_NAME); + + Assert.assertFalse(assertAccessLessonAsLearner, + "The lesson is accessible to author as learner. It shouldn't"); + + + // now we do the check if we can access this via JS: + + AbstractPage learnerPage = index.openLessonAsLearnerJS(DESIGN_NAME); + + String windowHandle = getPopUpWindowId(driver); + driver.switchTo().window(windowHandle); + + String assertError = driver.findElement(By.tagName("h1")).getText(); + + Assert.assertTrue(assertError.contains(NO_ROLE_RESPONSE), + "Sysadmin access didn't return the correct error message"); + + + learnerPage.closeWindow(); + + windowHandle = getPopUpWindowId(driver); + driver.switchTo().window(windowHandle); + index.logOut(); + + + } + + /** + * Security learner tests + * + * - attempt to access: + * + Author + * + Monitor + * + Gradebook + * + Notifications + * + Conditions + * + Sysadmin menus + * + */ + + + /** + * Is lesson accessible to learner? + */ + @Test(dependsOnMethods="startLesson") + public void learnerLessonAccess() { + + //index.logOut(); + String windowHandle = getPopUpWindowId(driver); + + driver.switchTo().window(windowHandle); + onLogin.loginAs(LEARNER_USER, RANDOM_INT); + + // First assertion: + + boolean assertAccessLessonAsLearner = index.isLessonAvailableAsLearner(DESIGN_NAME); + + Assert.assertTrue(assertAccessLessonAsLearner, + "The lesson is not accessible to leaner. It should"); + + + } + + + /** + * Learner able to jump as Author + */ + @Test(dependsOnMethods="learnerLessonAccess") + public void learnerAuthorAccess() { + + // we check first if the author tab is visible + boolean assertAuthorVisible = index.isAuthorLinkVisible(); + + Assert.assertFalse(assertAuthorVisible, "Author link visible for learner"); + + + // Now check if we are able to open FLA + // We've do this temporarily as this will change once we switch to proper FLA + fla = index.openFlaJS(); + + driver.switchTo().window("FlashlessAuthoring"); + String assertError = driver.findElement(By.tagName("h1")).getText(); + + Assert.assertTrue(assertError.contains(NO_ROLE_RESPONSE), "Author loaded! It shouldn't"); + + + fla.closeWindow(); + + + + } + + @Test(dependsOnMethods="learnerAuthorAccess") + public void leanerMonitorAccess() { + + String windowHandle = getPopUpWindowId(driver); + driver.switchTo().window(windowHandle); + + index.openMonitorLessonJS(DESIGN_NAME); + + driver.switchTo().frame("dialogFrame"); + + String assertError = driver.findElement(By.tagName("h1")).getText(); + + Assert.assertTrue(assertError.contains(NO_ROLE_RESPONSE), + "Monitor access didn't return the correct error message"); + + // we've got to use this -while it ain't pretty, to remove the frame + // as there's no other way + driver.navigate().refresh(); + + } + + @Test(dependsOnMethods="leanerMonitorAccess") + public void leanerMonitorNotifications() { + + index.openMonitorNotificationsJS(DESIGN_NAME); + + //String windowHandle = getPopUpWindowId(driver); + driver.switchTo().frame("notificationsDialogFrame"); + + String assertError = driver.findElement(By.tagName("h1")).getText(); + + Assert.assertTrue(assertError.contains(NO_ROLE_RESPONSE), + "Notifications access didn't return the correct error message"); + + + driver.navigate().refresh(); + + + } + + @Test(dependsOnMethods="leanerMonitorNotifications") + public void leanerMonitorGradebook() { + + index.openMonitorGradebookJS(DESIGN_NAME); + + //String windowHandle = getPopUpWindowId(driver); + driver.switchTo().frame("dialogFrame"); + + String assertError = driver.findElement(By.tagName("h1")).getText(); + + Assert.assertTrue(assertError.contains(NO_ROLE_RESPONSE), + "Gradebook access didn't return the correct error message"); + + + driver.navigate().refresh(); + + + } + + @Test(dependsOnMethods="leanerMonitorGradebook") + public void leanerMonitorConditions() { + + index.openMonitorConditionsJS(DESIGN_NAME); + + //String windowHandle = getPopUpWindowId(driver); + driver.switchTo().frame("dialogFrame"); + + String assertError = driver.findElement(By.tagName("h1")).getText(); + + Assert.assertTrue(assertError.contains(NO_ROLE_RESPONSE), + "Conditions access didn't return the correct error message"); + + + driver.navigate().refresh(); + + + } + + + + @Test(dependsOnMethods="leanerMonitorGradebook") + public void learnerSysadmin() { + + sysAdmin = index.openSysadminJS(); + + String windowHandle = getPopUpWindowId(driver); + driver.switchTo().window(windowHandle); + + String assertError = driver.findElement(By.tagName("h1")).getText(); + + Assert.assertTrue(assertError.contains(NO_ROLE_RESPONSE), + "Sysadmin access didn't return the correct error message"); + + + sysAdmin.closeWindow(); + + windowHandle = getPopUpWindowId(driver); + driver.switchTo().window(windowHandle); + + } + + + @Test(dependsOnMethods="learnerSysadmin") + public void learnerCourseManagement() { + + sysAdmin = index.openCourseManagementJS(); + + String windowHandle = getPopUpWindowId(driver); + driver.switchTo().window(windowHandle); + + String assertError = driver.findElement(By.tagName("h1")).getText(); + + Assert.assertTrue(assertError.contains(NO_ROLE_RESPONSE), + "Course Management access didn't return the correct error message"); + + + sysAdmin.closeWindow(); + + windowHandle = getPopUpWindowId(driver); + driver.switchTo().window(windowHandle); + + } + + + + /** + * Returns the correct popup id + * + * @param driver + * @return + */ + private String getPopUpWindowId(WebDriver driver) { + + String authorToolWindow = null; + Set handles = driver.getWindowHandles(); + Iterator iterator = handles.iterator(); + + while (iterator.hasNext()){ + authorToolWindow = iterator.next(); + } + + return authorToolWindow; + } + + +} Index: lams_tests/tests/org/lamsfoundation/lams/admin/util/AdminConstants.java =================================================================== RCS file: /usr/local/cvsroot/lams_tests/tests/org/lamsfoundation/lams/admin/util/AdminConstants.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_tests/tests/org/lamsfoundation/lams/admin/util/AdminConstants.java 4 Nov 2014 21:46:22 -0000 1.1 @@ -0,0 +1,35 @@ +/**************************************************************** + * Copyright (C) 2014 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + +package org.lamsfoundation.lams.admin.util; + +/** + * Admin constants + * + * @author Ernie Ghiglione (ernieg@lamsfoundation.org) + * + */ +public class AdminConstants { + + public static final String COURSE_MGT_TITLE = "Course/Subcourse management"; + +} Index: lams_tests/tests/org/lamsfoundation/lams/pages/IndexPage.java =================================================================== RCS file: /usr/local/cvsroot/lams_tests/tests/org/lamsfoundation/lams/pages/IndexPage.java,v diff -u -r1.3 -r1.4 --- lams_tests/tests/org/lamsfoundation/lams/pages/IndexPage.java 29 Oct 2014 20:01:06 -0000 1.3 +++ lams_tests/tests/org/lamsfoundation/lams/pages/IndexPage.java 4 Nov 2014 21:46:22 -0000 1.4 @@ -24,11 +24,15 @@ import java.util.ArrayList; import java.util.List; +import java.util.concurrent.TimeUnit; +import org.lamsfoundation.lams.pages.admin.CourseManagementPage; import org.lamsfoundation.lams.pages.author.FLAPage; import org.lamsfoundation.lams.pages.monitor.MonitorPage; import org.lamsfoundation.lams.pages.monitor.addlesson.AddLessonPage; import org.openqa.selenium.By; +import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.NoSuchElementException; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; @@ -46,6 +50,9 @@ @FindBy(id = "openFla") private WebElement flaLink; + + @FindBy(id = "Author") // Eventually this will be replace by FLA only! + private WebElement flashAuthor; @FindBy(id = "My Profile") private WebElement myProfileTab; @@ -62,6 +69,9 @@ @FindBy(className = "lesson-table") private WebElement lessonTable; + @FindBy(id = "Course Mgt") + private WebElement courseMgtButton; + public IndexPage(WebDriver driver) { super(driver); } @@ -71,7 +81,22 @@ driver.switchTo().window("FlashlessAuthoring"); return PageFactory.initElements(driver, FLAPage.class); } + + /** + * Checks if the link to Author UI is visible + * @return boolean + */ + public boolean isAuthorLinkVisible() { + + return isElementPresent(driver, flashAuthor); + } + + /** + * Opens the AddLesson UI + * + * @return {@link AddLessonPage} + */ public AddLessonPage addLesson() { addLessonButton.click(); @@ -83,7 +108,25 @@ public Boolean isLessonPresent(String lessonName) { - return ((driver.findElements(By.linkText(lessonName)).size() > 0) ? true : false); + Boolean present = false; + + int isLessonIn = driver.findElements(By.linkText(lessonName)).size(); + + if (isLessonIn > 0) { + present = true; + } + + return present; + +/* List allLessons = getAllLessonNames(); + + + Boolean isLessonInCourse = allLessons.contains(lessonName); + System.out.println("All lessons: "+ allLessons); + System.out.println("Is it true? :" + isLessonInCourse); + return isLessonInCourse; + */ + // return ((driver.findElements(By.linkText(lessonName)).size() > 0) ? true : false); } @@ -180,6 +223,12 @@ return lessonActions; } + /** + * Checks if the lesson displays as completed + * + * @param lessonName + * @return + */ public Boolean isLessonCompleted(String lessonName) { WebElement lesson = getLessonRowByName(lessonName); @@ -190,6 +239,11 @@ } + /** + * Refreshes index page with button + * + * @return {@link IndexPage} + */ public IndexPage refresh() { refreshButton.click(); @@ -203,6 +257,12 @@ } + /** + * Checks if the lesson is available to jump as learner + * + * @param lessonName + * @return true/false + */ public Boolean isLessonAvailableAsLearner(String lessonName) { WebElement lesson = getLessonRowByName(lessonName); @@ -215,7 +275,184 @@ } + /** + * Course Management + * + */ + public CourseManagementPage openCourseManagement() { + + courseMgtButton.click(); + driver.switchTo().window("omWindow"); + return PageFactory.initElements(driver, CourseManagementPage.class); + } + + + /** + * Logs out + * @return {@link LoginPage} + */ + public LoginPage logOut() { + + logoutButton.click(); + + return PageFactory.initElements(driver, LoginPage.class); + } + + + + /** + * Javascript methods + * + * We use this javascript methods to execute js on the testing browser just as if we click on an actual + * web element. + * + * The main reason we use this is to test JS but also to simulate access. For instance we can test if a + * learner user can open sysadmin menus. We can't do this by clicking as the web elements aren't there, + * but thru JS we can. (see AccessControlTests.java) + * + */ + + /** + * Uses javascript to open author + */ + public FLAPage openFlaJS() { + + ((JavascriptExecutor) + driver).executeScript("window.open('authoring/author.do?method=openAuthoring', 'FlashlessAuthoring','resizable=yes,scrollbars=yes,left=10,top=10,width=1280,height=800');"); + + return PageFactory.initElements(driver, FLAPage.class); + } + + + /** + * Attempts to open monitor lesson via Javascript + * @param string + */ + public MonitorPage openMonitorLessonJS(String lessonName) { + + String lessonId = getLessonId(lessonName); + ((JavascriptExecutor) + driver).executeScript("showMonitorLessonDialog(" + lessonId +")"); + + + return PageFactory.initElements(driver, MonitorPage.class); + + } + + + /** + * Attempts to open monitor lesson notifications + * + * Currently we return {@link AbstractPage} but one we have a page for notifications, this must + * be changed to it. + * + * @param lessonName + * @return {@link AbstractPage} + */ + public AbstractPage openMonitorNotificationsJS(String lessonName) { + + String lessonId = getLessonId(lessonName); + ((JavascriptExecutor) + driver).executeScript("showNotificationsDialog(null," + lessonId +")"); + + return PageFactory.initElements(driver, MonitorPage.class); + + } + + + + /** + * Attempts to open monitor lesson gradebook + * + * Currently we return {@link AbstractPage} but one we have a page for lesson gradebook, this must + * be changed to it. + * + * @param lessonName + * @return + */ + public AbstractPage openMonitorGradebookJS(String lessonName) { + + String lessonId = getLessonId(lessonName); + ((JavascriptExecutor) + driver).executeScript("showGradebookLessonDialog(" + lessonId +")"); + + return PageFactory.initElements(driver, MonitorPage.class); + + + } + + + /** + * Attempts to open monitor lesson conditions + * + * Currently we return {@link AbstractPage} but one we have a page for lesson conditions, this must + * be changed to it. + * + * @param lessonName + * @return + */ + public AbstractPage openMonitorConditionsJS(String lessonName) { + + String lessonId = getLessonId(lessonName); + ((JavascriptExecutor) + driver).executeScript("showConditionsDialog(" + lessonId +")"); + + return PageFactory.initElements(driver, MonitorPage.class); + + + } + + + /** + * Attempts to open sysadmin menu + * + * @return {@link AbstractPage} + */ + public AbstractPage openSysadminJS() { + + ((JavascriptExecutor) + driver).executeScript("openSysadmin()"); + + return PageFactory.initElements(driver, AbstractPage.class); + } + + + /** + * Attempts to open course management + * + * @return {@link CourseManagementPage} + */ + public CourseManagementPage openCourseManagementJS() { + + ((JavascriptExecutor) + driver).executeScript("openOrgManagement(1)"); + + return PageFactory.initElements(driver, CourseManagementPage.class); + } + + /** + * Attempts to open a lesson via JS + * + * @return {@link AbstractPage} + */ + public AbstractPage openLessonAsLearnerJS(String lessonName) { + + String lessonId = getLessonId(lessonName); + ((JavascriptExecutor) + driver).executeScript("openLearner(" + lessonId +")"); + + + return PageFactory.initElements(driver, AbstractPage.class); + + + } + + + + + + /** * Returns all the lesson nodes found on the page * * @return List of nodes @@ -226,7 +463,9 @@ } + + /** * Returns the lessonId for a given lesson name * @@ -242,7 +481,7 @@ for (WebElement lesson : allLessons) { String name = lesson.findElement(By.tagName("a")).getText().trim(); - + if (name.equals(lessonName.trim())) { lessonId = lesson.getAttribute("id"); @@ -251,7 +490,7 @@ } - + return lessonId; } @@ -275,6 +514,33 @@ return lessonTable.findElement(By.id(lessonId)); } + + private static boolean isElementPresent(WebDriver webdriver, WebElement webelement) { + boolean exists = false; + webdriver.manage().timeouts().implicitlyWait(0, TimeUnit.MILLISECONDS); + + try { + webelement.getTagName(); + exists = true; + } catch (NoSuchElementException e) { + // nothing to do. + } + + webdriver.manage().timeouts().implicitlyWait(10000, TimeUnit.MILLISECONDS); + return exists; + } + + + + + + + + + + + + } Index: lams_tests/tests/org/lamsfoundation/lams/pages/admin/CourseManagementPage.java =================================================================== RCS file: /usr/local/cvsroot/lams_tests/tests/org/lamsfoundation/lams/pages/admin/CourseManagementPage.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_tests/tests/org/lamsfoundation/lams/pages/admin/CourseManagementPage.java 4 Nov 2014 21:46:22 -0000 1.1 @@ -0,0 +1,150 @@ +/**************************************************************** + * Copyright (C) 2014 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + +package org.lamsfoundation.lams.pages.admin; + +import java.util.List; + +import org.lamsfoundation.lams.pages.AbstractPage; +import org.lamsfoundation.lams.pages.admin.CreateEditCoursePage; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; +import org.openqa.selenium.support.PageFactory; + +/** + * + * Course management page + * + * This page is for sysadmins and global course managers to create/edit courses and users. + * + * @author Ernie Ghiglione (ernieg@lamsfoundation.org) + * + */ +public class CourseManagementPage extends AbstractPage { + + /** + * Page buttons + * These are the buttons on the interface. + */ + + @FindBy(id = "userCreate") + private WebElement createUser; + + @FindBy(id = "findUsers") + private WebElement findUsers; + + @FindBy(id = "createCourse") + private WebElement createCourse; + + @FindBy(id = "manageGlobalRoles") + private WebElement manageGlobalRoles; + + @FindBy(id = "manageUsers") + private WebElement manageUsers; + + @FindBy(id = "closeLessons") + private WebElement closeLessons; + + @FindBy(id = "createNewSubcourse") + private WebElement createNewSubcourse; + + @FindBy(id = "courseStatus") + private WebElement courseStatus; + + @FindBy(id = "courseName") + private WebElement courseName; + + @FindBy(id = "idsorter") + private WebElement idSorter; + + + public CourseManagementPage(WebDriver driver) { + super(driver); + + } + + /** + * Form page to Create/Edit a course + * * + * @return {@link CreateEditCoursePage} + */ + public CreateEditCoursePage createEditCourse() { + + createCourse.click(); + + return PageFactory.initElements(driver, CreateEditCoursePage.class); + } + + /** + * Returns true if the course exists + * + * @param courseName + * @return true/false + */ + public boolean courseExists(String courseName) { + + List courses = driver.findElements(By.linkText(courseName)); + + return ((courses.size() > 0) ? true: false); + + } + + + /** + * Form page to Create/Edit a user + * + * @return {@link CreateEditUserPage} + */ + public CreateEditUserPage createEditUser() { + + createUser.click(); + + return PageFactory.initElements(driver, CreateEditUserPage.class); + } + + public CourseManagementPage getCourse(String courseName) { + + driver.findElement(By.linkText(courseName)).click(); + + return PageFactory.initElements(driver, CourseManagementPage.class); + + } + + public UserManagementPage manageUsers() { + + manageUsers.click(); + + return PageFactory.initElements(driver, UserManagementPage.class); + + } + + public CourseManagementPage clickIdSorter() { + + idSorter.click(); + + return PageFactory.initElements(driver, CourseManagementPage.class); + } + + +} Index: lams_tests/tests/org/lamsfoundation/lams/pages/admin/CreateEditCoursePage.java =================================================================== RCS file: /usr/local/cvsroot/lams_tests/tests/org/lamsfoundation/lams/pages/admin/CreateEditCoursePage.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_tests/tests/org/lamsfoundation/lams/pages/admin/CreateEditCoursePage.java 4 Nov 2014 21:46:22 -0000 1.1 @@ -0,0 +1,251 @@ +/**************************************************************** + * Copyright (C) 2014 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + +package org.lamsfoundation.lams.pages.admin; + +import org.lamsfoundation.lams.pages.AbstractPage; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; +import org.openqa.selenium.support.PageFactory; +import org.openqa.selenium.support.ui.Select; + +public class CreateEditCoursePage extends AbstractPage { + + @FindBy(name = "name") + private WebElement courseName; + + @FindBy(name = "code") + private WebElement courseCode; + + @FindBy(name = "description") + private WebElement courseDescription; + + @FindBy(name = "localeId") + private WebElement courseLocaleId; + + @FindBy(name = "stateId") + private WebElement courseStatusId; + + @FindBy(name = "courseAdminCanAddNewUsers") + private WebElement courseAdminCanAddNewUsers; + + @FindBy(name = "courseAdminCanBrowseAllUsers") + private WebElement courseAdminCanBrowseAllUsers; + + @FindBy(name = "courseAdminCanChangeStatusOfCourse") + private WebElement courseAdminCanChangeStatusOfCourse; + + @FindBy(name = "enableCourseNotifications") + private WebElement enableCourseNotifications; + + @FindBy(name = "enableGradebookForMonitors") + private WebElement enableGradebookForMonitors; + + @FindBy(name = "enableGradebookForLearners") + private WebElement enableGradebookForLearners; + + @FindBy(name = "enableSingleActivityLessons") + private WebElement enableSingleActivityLessons; + + @FindBy(id = "saveButton") + private WebElement saveButton; + + @FindBy(id = "cancelButton") + private WebElement cancelButton; + + + public CreateEditCoursePage(WebDriver driver) { + super(driver); + + } + + public CreateEditCoursePage setCourseName(String name) { + + courseName.click(); + courseName.clear(); + courseName.sendKeys(name); + + return PageFactory.initElements(driver, CreateEditCoursePage.class); + + } + + public String getCourseName() { + return courseName.getAttribute("value"); + } + + public CreateEditCoursePage setCourseCode(String code) { + + courseCode.click(); + courseCode.clear(); + courseCode.sendKeys(code); + + return PageFactory.initElements(driver, CreateEditCoursePage.class); + } + + public String getCourseCode() { + + return courseCode.getAttribute("value"); + } + + public CreateEditCoursePage setDescription(String description) { + + courseDescription.click(); + courseDescription.clear(); + courseDescription.sendKeys(description); + + return PageFactory.initElements(driver, CreateEditCoursePage.class); + } + + public String getDescription() { + + return courseDescription.getAttribute("value"); + + } + + public CreateEditCoursePage setLocale(String localeName) { + + Select inputSelector = new Select(courseLocaleId); + + inputSelector.selectByVisibleText(localeName); + + return PageFactory.initElements(driver, CreateEditCoursePage.class); + } + + public String getLocale() { + + Select inputSelector = new Select(courseLocaleId); + + return inputSelector.getFirstSelectedOption().getText(); + + } + + public CreateEditCoursePage setStatus(String status) { + + Select inputSelector = new Select(courseStatusId); + + inputSelector.selectByVisibleText(status); + + return PageFactory.initElements(driver, CreateEditCoursePage.class); + } + + public String getStatus() { + + Select inputSelector = new Select(courseStatusId); + + return inputSelector.getFirstSelectedOption().getText(); + + } + + public CreateEditCoursePage setCourseAdminCanAddNewUsers() { + + courseAdminCanAddNewUsers.click(); + + return PageFactory.initElements(driver, CreateEditCoursePage.class); + } + + public Boolean getCourseAdminCanAddNewUsers() { + + return courseAdminCanAddNewUsers.isSelected(); + } + + public CreateEditCoursePage setCourseAdminCanBrowseAllUsers() { + + courseAdminCanBrowseAllUsers.click(); + + return PageFactory.initElements(driver, CreateEditCoursePage.class); + } + + public Boolean getCourseAdminCanBrowseAllUsers() { + + return courseAdminCanBrowseAllUsers.isSelected(); + } + + + public CreateEditCoursePage setCourseAdminCanChangeStatusOfCourse() { + + courseAdminCanChangeStatusOfCourse.click(); + + return PageFactory.initElements(driver, CreateEditCoursePage.class); + } + + public Boolean getCourseAdminCanChangeStatusOfCourse() { + + return courseAdminCanChangeStatusOfCourse.isSelected(); + } + + + public CreateEditCoursePage setEnableCourseNotifications() { + + enableCourseNotifications.click(); + + return PageFactory.initElements(driver, CreateEditCoursePage.class); + } + + public Boolean getEnableCourseNotifications() { + + return enableCourseNotifications.isSelected(); + } + + + public CreateEditCoursePage setEnableGradebookForMonitors() { + + enableGradebookForMonitors.click(); + + return PageFactory.initElements(driver, CreateEditCoursePage.class); + } + + public Boolean getEnableGradebookForMonitors() { + + return enableGradebookForMonitors.isSelected(); + } + + public CreateEditCoursePage setEnableGradebookForLearners() { + + enableGradebookForLearners.click(); + + return PageFactory.initElements(driver, CreateEditCoursePage.class); + } + + public Boolean getEnableGradebookForLearners() { + + return enableGradebookForLearners.isSelected(); + } + + public CreateEditCoursePage setEnableSingleActivityLessons() { + + enableSingleActivityLessons.click(); + + return PageFactory.initElements(driver, CreateEditCoursePage.class); + } + + public Boolean getEnableSingleActivityLessons() { + + return enableSingleActivityLessons.isSelected(); + } + + public CourseManagementPage save() { + saveButton.click(); + return PageFactory.initElements(driver, CourseManagementPage.class); + } + +} Index: lams_tests/tests/org/lamsfoundation/lams/pages/admin/CreateEditUserPage.java =================================================================== RCS file: /usr/local/cvsroot/lams_tests/tests/org/lamsfoundation/lams/pages/admin/CreateEditUserPage.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_tests/tests/org/lamsfoundation/lams/pages/admin/CreateEditUserPage.java 4 Nov 2014 21:46:22 -0000 1.1 @@ -0,0 +1,481 @@ +/**************************************************************** + * Copyright (C) 2014 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + +package org.lamsfoundation.lams.pages.admin; + +import org.lamsfoundation.lams.pages.AbstractPage; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; +import org.openqa.selenium.support.PageFactory; +import org.openqa.selenium.support.ui.Select; + +/** + * Create users page + * + * @author Ernie Ghiglione (ernieg@lamsfoundation.org) + * + */ +public class CreateEditUserPage extends AbstractPage { + + /** + * Page fields + * + */ + + @FindBy(name = "login") + private WebElement login; + + @FindBy(name = "password") + private WebElement password; + + @FindBy(name = "password2") + private WebElement confirmPassword; + + @FindBy(name = "authenticationMethodId") + private WebElement authenticationMethodId; + + @FindBy(name = "title") + private WebElement title; + + @FindBy(name = "firstName") + private WebElement firstName; + + @FindBy(name = "lastName") + private WebElement lastName; + + @FindBy(name = "email") + private WebElement email; + + @FindBy(name = "addressLine1") + private WebElement addressLine1; + + @FindBy(name = "addressLine2") + private WebElement addressLine2; + + @FindBy(name = "addressLine3") + private WebElement addressLine3; + + @FindBy(name = "city") + private WebElement city; + + @FindBy(name = "postcode") + private WebElement postcode; + + @FindBy(name = "state") + private WebElement state; + + @FindBy(name = "country") + private WebElement country; + + @FindBy(name = "dayPhone") + private WebElement dayPhone; + + @FindBy(name = "eveningPhone") + private WebElement eveningPhone; + + @FindBy(name = "mobilePhone") + private WebElement mobilePhone; + + @FindBy(name = "fax") + private WebElement fax; + + @FindBy(name = "localeId") + private WebElement localeId; + + @FindBy(name = "timeZone") + private WebElement timeZone; + + @FindBy(name = "userCSSTheme") + private WebElement userCSSTheme; + + @FindBy(name = "userFlashTheme") + private WebElement userFlashTheme; + + @FindBy(id = "saveButton") + private WebElement saveButton; + + @FindBy(id = "cancelButton") + private WebElement cancelButton; + + @FindBy(className = "warning") + private WebElement errorMessages; + + + public CreateEditUserPage(WebDriver driver) { + super(driver); + + } + + public CreateEditUserPage setLogin(String userName) { + + login.click(); + login.clear(); + login.sendKeys(userName); + + return PageFactory.initElements(driver, CreateEditUserPage.class); + } + + public String getLogin() { + return login.getAttribute("value"); + } + + public CreateEditUserPage setPassword(String passwordTxt) { + + password.click(); + password.clear(); + password.sendKeys(passwordTxt); + + return PageFactory.initElements(driver, CreateEditUserPage.class); + } + + public String getPassword() { + return password.getAttribute("value"); + } + + public CreateEditUserPage setPasswordConfirmation(String passwordTxt) { + + confirmPassword.click(); + confirmPassword.clear(); + confirmPassword.sendKeys(passwordTxt); + + return PageFactory.initElements(driver, CreateEditUserPage.class); + } + + public String getPasswordConfirmation() { + return confirmPassword.getAttribute("value"); + } + + public CreateEditUserPage setAuthenticationMethod(String authenticationType) { + + Select inputSelector = new Select(authenticationMethodId); + + inputSelector.selectByVisibleText(authenticationType); + + return PageFactory.initElements(driver, CreateEditUserPage.class); + } + + public String getAuthenticationMethod() { + + Select inputSelector = new Select(authenticationMethodId); + + return inputSelector.getFirstSelectedOption().getText(); + } + + + public CreateEditUserPage setTitle(String titletxt) { + + title.click(); + title.clear(); + title.sendKeys(titletxt); + + return PageFactory.initElements(driver, CreateEditUserPage.class); + } + + public String getTitle() { + return title.getAttribute("value"); + } + + public CreateEditUserPage setFirstName(String firstNameTxt) { + + firstName.click(); + firstName.clear(); + firstName.sendKeys(firstNameTxt); + + return PageFactory.initElements(driver, CreateEditUserPage.class); + } + + public String getFirstName() { + return firstName.getAttribute("value"); + } + + + public CreateEditUserPage setLastName(String lastNameTxt) { + + lastName.click(); + lastName.clear(); + lastName.sendKeys(lastNameTxt); + + return PageFactory.initElements(driver, CreateEditUserPage.class); + } + + public String getLastName() { + return lastName.getAttribute("value"); + } + + + public CreateEditUserPage setEmail(String emailTxt) { + + email.click(); + email.clear(); + email.sendKeys(emailTxt); + + return PageFactory.initElements(driver, CreateEditUserPage.class); + } + + public String getEmail() { + return email.getAttribute("value"); + } + + public CreateEditUserPage setAddressLine1(String address1) { + + addressLine1.click(); + addressLine1.clear(); + addressLine1.sendKeys(address1); + + return PageFactory.initElements(driver, CreateEditUserPage.class); + } + + public String getAddressLine1() { + return addressLine1.getAttribute("value"); + } + + public CreateEditUserPage setAddressLine2(String address2) { + + addressLine2.click(); + addressLine2.clear(); + addressLine2.sendKeys(address2); + + return PageFactory.initElements(driver, CreateEditUserPage.class); + } + + public String getAddressLine2() { + return addressLine2.getAttribute("value"); + } + + public CreateEditUserPage setAddressLine3(String address3) { + + addressLine3.click(); + addressLine3.clear(); + addressLine3.sendKeys(address3); + + return PageFactory.initElements(driver, CreateEditUserPage.class); + } + + public String getAddressLine3() { + return addressLine3.getAttribute("value"); + } + + + public CreateEditUserPage setCity(String cityTxt) { + + city.click(); + city.clear(); + city.sendKeys(cityTxt); + + return PageFactory.initElements(driver, CreateEditUserPage.class); + } + + public String getCity() { + return city.getAttribute("value"); + } + + public CreateEditUserPage setPostcode(String postcodeTxt) { + + postcode.click(); + postcode.clear(); + postcode.sendKeys(postcodeTxt); + + return PageFactory.initElements(driver, CreateEditUserPage.class); + } + + public String getPostcode() { + return postcode.getAttribute("value"); + } + + + public CreateEditUserPage setState(String stateTxt) { + + state.click(); + state.clear(); + state.sendKeys(stateTxt); + + return PageFactory.initElements(driver, CreateEditUserPage.class); + } + + public String getState() { + return state.getAttribute("value"); + } + + + public CreateEditUserPage setCountry(String countrytxt) { + + country.click(); + country.clear(); + country.sendKeys(countrytxt); + + return PageFactory.initElements(driver, CreateEditUserPage.class); + } + + public String getCountry() { + return country.getAttribute("value"); + } + + + public CreateEditUserPage setDayPhone(String dayPhoneTxt) { + + dayPhone.click(); + dayPhone.clear(); + dayPhone.sendKeys(dayPhoneTxt); + + return PageFactory.initElements(driver, CreateEditUserPage.class); + } + + public String getDayPhone() { + return dayPhone.getAttribute("value"); + } + + + public CreateEditUserPage setEveningPhone(String eveningPhoneTxt) { + + eveningPhone.click(); + eveningPhone.clear(); + eveningPhone.sendKeys(eveningPhoneTxt); + + return PageFactory.initElements(driver, CreateEditUserPage.class); + } + + public String getEveningPhone() { + return eveningPhone.getAttribute("value"); + } + + + public CreateEditUserPage setMobilePhone(String mobilePhoneTxt) { + + mobilePhone.click(); + mobilePhone.clear(); + mobilePhone.sendKeys(mobilePhoneTxt); + + return PageFactory.initElements(driver, CreateEditUserPage.class); + } + + public String getMobilePhone() { + return mobilePhone.getAttribute("value"); + } + + + public CreateEditUserPage setFax(String faxTxt) { + + fax.click(); + fax.clear(); + fax.sendKeys(faxTxt); + + return PageFactory.initElements(driver, CreateEditUserPage.class); + } + + public String getFax() { + return fax.getAttribute("value"); + } + + + public CreateEditUserPage setLocale(String localTxt) { + + Select inputSelector = new Select(localeId); + + inputSelector.selectByVisibleText(localTxt); + + + return PageFactory.initElements(driver, CreateEditUserPage.class); + } + + public String getLocale() { + + Select inputSelector = new Select(localeId); + + return inputSelector.getFirstSelectedOption().getText(); + + } + + + public CreateEditUserPage setTimeZone(String timeZoneTxt) { + + Select inputSelector = new Select(timeZone); + + inputSelector.selectByVisibleText(timeZoneTxt); + + + return PageFactory.initElements(driver, CreateEditUserPage.class); + } + + public String getTimeZone() { + + Select inputSelector = new Select(timeZone); + + return inputSelector.getFirstSelectedOption().getText(); + + } + + + public CreateEditUserPage setHtmlTheme(String htmlThemeTxt) { + + Select inputSelector = new Select(userCSSTheme); + + inputSelector.selectByVisibleText(htmlThemeTxt); + + + return PageFactory.initElements(driver, CreateEditUserPage.class); + } + + public String getHtmlTheme() { + + Select inputSelector = new Select(userCSSTheme); + + return inputSelector.getFirstSelectedOption().getText(); + + } + + + public CreateEditUserPage setFlashTheme(String flashThemeTxt) { + + Select inputSelector = new Select(userFlashTheme); + + inputSelector.selectByVisibleText(flashThemeTxt); + + + return PageFactory.initElements(driver, CreateEditUserPage.class); + } + + public String getFlashTheme() { + + Select inputSelector = new Select(userFlashTheme); + + return inputSelector.getFirstSelectedOption().getText(); + + } + + public CreateEditUserPage saveTest() { + + saveButton.click(); + + return PageFactory.initElements(driver, CreateEditUserPage.class); + } + + + public FindUsersPage save() { + + saveButton.click(); + + return PageFactory.initElements(driver, FindUsersPage.class); + } + + +} Index: lams_tests/tests/org/lamsfoundation/lams/pages/admin/FindUsersPage.java =================================================================== RCS file: /usr/local/cvsroot/lams_tests/tests/org/lamsfoundation/lams/pages/admin/FindUsersPage.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_tests/tests/org/lamsfoundation/lams/pages/admin/FindUsersPage.java 4 Nov 2014 21:46:22 -0000 1.1 @@ -0,0 +1,50 @@ +/**************************************************************** + * Copyright (C) 2014 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + +package org.lamsfoundation.lams.pages.admin; + +import org.lamsfoundation.lams.pages.AbstractPage; +import org.lamsfoundation.lams.pages.monitor.MonitorPage; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; +import org.openqa.selenium.support.PageFactory; + +public class FindUsersPage extends AbstractPage { + + @FindBy(linkText= "Manage courses") + private WebElement manageCoursesLink; + + + public FindUsersPage(WebDriver driver) { + super(driver); + + } + + public CourseManagementPage manageCourses() { + manageCoursesLink.click(); + + return PageFactory.initElements(driver, CourseManagementPage.class); + } + + +} Index: lams_tests/tests/org/lamsfoundation/lams/pages/admin/UserManagementPage.java =================================================================== RCS file: /usr/local/cvsroot/lams_tests/tests/org/lamsfoundation/lams/pages/admin/UserManagementPage.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_tests/tests/org/lamsfoundation/lams/pages/admin/UserManagementPage.java 4 Nov 2014 21:46:22 -0000 1.1 @@ -0,0 +1,114 @@ +/**************************************************************** + * Copyright (C) 2014 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + +package org.lamsfoundation.lams.pages.admin; + +import java.util.List; + +import org.lamsfoundation.lams.pages.AbstractPage; +import org.openqa.selenium.By; +import org.openqa.selenium.Keys; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; + +/** + * User management page + * + * This also includes the user/course enrollment page + * + * + * @author Ernie Ghiglione (ernieg@lamsfoundation.org) + * + */ +public class UserManagementPage extends AbstractPage { + + @FindBy(id = "addRemoveUsers") + private WebElement addRemoveUsers; + + @FindBy(id = "term") + private WebElement searchField; + + @FindBy(id = "potential") + private WebElement potentialUsers; + + @FindBy(id = "nextButton") + private WebElement nextButton; + + + public UserManagementPage(WebDriver driver) { + super(driver); + + } + + /** + * Enrolls a user into a course based on the roles given. + * + * @param login username + * @param roles roles' list + */ + public void addRemoveUser(String login, List roles) { + + addRemoveUsers.click(); + searchField.click(); + searchField.clear(); + searchField.sendKeys(login); + searchField.sendKeys(Keys.ENTER); + + List users = potentialUsers.findElements(By.tagName("a")); + + + for (WebElement user : users) { + + user.click(); + + } + + nextButton.click(); + + + for (String role : roles) { + + if (role.contains("Author")) { + driver.findElement(By.id(login + "Role3")).click(); + + } else if (role.contains("Monitor")) { + driver.findElement(By.id(login + "Role4")).click(); + + } else if (role.contains("Learner")) { + driver.findElement(By.id(login + "Role5")).click(); + + } else if (role.contains("Course Admin")) { + driver.findElement(By.id(login + "Role6")).click(); + + } else if (role.contains("Course Manager")) { + driver.findElement(By.id(login + "Role2")).click(); + } + + } + + driver.findElement(By.id("saveButton")).click(); + + + } + +}