Index: lams_tests/tests/org/lamsfoundation/lams/monitor/AddLessonTests.java =================================================================== diff -u --- lams_tests/tests/org/lamsfoundation/lams/monitor/AddLessonTests.java (revision 0) +++ lams_tests/tests/org/lamsfoundation/lams/monitor/AddLessonTests.java (revision 4dea7ee858c3b437aebe1d0afe4f374b7ec0dd94) @@ -0,0 +1,325 @@ +/**************************************************************** + * 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.monitor; + +import java.util.List; +import java.util.concurrent.TimeUnit; + +import org.lamsfoundation.lams.pages.IndexPage; +import org.lamsfoundation.lams.pages.LoginPage; +import org.lamsfoundation.lams.pages.monitor.addlesson.AddLessonPage; +import org.lamsfoundation.lams.pages.monitor.addlesson.LessonTab; +import org.lamsfoundation.lams.util.LamsUtil; +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.Test; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.AfterClass; + +public class AddLessonTests { + + private static final String RANDOM_INT = LamsUtil.randInt(0, 9999); + + private LoginPage onLogin; + private IndexPage index; + private AddLessonPage addLesson; + + WebDriver driver; + + + @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); + addLesson = PageFactory.initElements(driver, AddLessonPage.class); + onLogin.navigateToLamsLogin().loginAs("test3", "test3"); + + } + + @AfterClass + public void afterClass() { + //driver.quit(); + } + + /** + * Opens Add lesson interface + */ + @Test + public void openAddLesson() { + + final String addButton= "Add now"; + + AddLessonPage addLesson = new AddLessonPage(driver); + addLesson = openDialog(index); + + String assertFrameOpen = addLesson.checkAddLessonButton(); + + Assert.assertEquals(assertFrameOpen, addButton, + "It doesn't seem that the add lesson UI has loaded properly"); + + } + + + @Test(dependsOnMethods="openAddLesson") + public void checksLandingtTab() { + + String lessonTabTitle = addLesson.openLessontab().getLessonTabTitle(); + + Assert.assertEquals(lessonTabTitle, LessonTab.lessonTitle, + "It doesn't seem that we are in the lesson tab."); + + } + + @Test(dependsOnMethods="checksLandingtTab") + public void getUserDesigns() { + + List designs = addLesson.openLessontab().getFolderNodes("user"); + + for (WebElement design : designs) { + + design.click(); + + Assert.assertTrue(addLesson.openLessontab().isDesignImageDisplayed(), + "Design image is not displayed"); + + } + + } + + /** + * Lesson tab tests + */ + + /** + * Creates a lesson picking up the first design and gives it a name + * + */ + @Test(dependsOnMethods="getUserDesigns") + public void createLessonWithFirstDesign() { + + String lessonName = "First lesson " + RANDOM_INT; + + // Gets all the nodes in the user's folder + List designs = addLesson.openLessontab().getFolderNodes("user"); + + // pick the first design + WebElement firstDesign = designs.get(0); + + // Select design + addLesson + .openLessontab() + .clickDesign(firstDesign) + .setLessonName(lessonName); + + + // Assert if design image is displayed + boolean isImageDisplayed = addLesson.openLessontab().isDesignImageDisplayed(); + Assert.assertTrue(isImageDisplayed, + "Design image is not displayed"); + + // Add lesson + addLesson + .addLessonNow(); + + // Assert that lesson was created + boolean wasLessonCreated = index.isLessonPresent(lessonName); + + Assert.assertTrue(wasLessonCreated, "Lesson " + lessonName + " was not found!"); + + + } + + /** + * Class tab tests + */ + + /** + * By default LAMS monitor only includes the user that + * is starting the lesson as monitor + */ + @Test(dependsOnMethods="createLessonWithFirstDesign") + public void checkOnlyOneMonitorSelected() { + + int expectedNumberOfMonitors = 1; + addLesson = openDialog(index); + + int selectedMonitorsAtStart = addLesson + .openClasstab() + .getNumberSelectedMonitors(); + + // Asserts + Assert.assertEquals(selectedMonitorsAtStart, expectedNumberOfMonitors, + "There was more than one monitor by default"); + + } + + @Test(dependsOnMethods="checkOnlyOneMonitorSelected") + public void checkOnlyAllLearnersSelected() { + + int expectedUnselectedLearners = 0; + + int unSelectedLearners = addLesson + .openClasstab() + .getNumberUnselectedLearners(); + + // Assert + Assert.assertEquals(unSelectedLearners, expectedUnselectedLearners, + "There shouldn't be any unselected learners"); + + // addLesson.closeDialog(); + } + + @Test(dependsOnMethods="checkOnlyAllLearnersSelected") + public void createLessonWithAllMonitors() { + + String lessonName = "All in " + RANDOM_INT; + + int selectedMonitorsAtStart = addLesson + .openClasstab() + .getNumberSelectedMonitors(); + + int unSelectedMonitorsAtStart = addLesson + .openClasstab() + .getNumberUnselectedMonitors(); + + selectRandomDesign(addLesson, lessonName); + + // Asserts that there's only one monitor in the selected side + // By default we only include one and only one monitor to a lesson + Assert.assertTrue(selectedMonitorsAtStart == 1, + "There was more than one monitor by default"); + + // Add all monitors to lesson (one by one) + addLesson + .openClasstab() + .addAllMonitorsToLesson(); + + int selectedMonitors = addLesson + .openClasstab() + .getNumberSelectedMonitors(); + + // Assert that now all monitors should be in the selected list + int allMonitors = selectedMonitorsAtStart + unSelectedMonitorsAtStart; + Assert.assertEquals(selectedMonitors, allMonitors, "All monitors should have been selected"); + + // Add lesson + addLesson + .addLessonNow(); + + // Assert that lesson was created + boolean wasLessonCreated = index.isLessonPresent(lessonName); + + Assert.assertTrue(wasLessonCreated, "Lesson " + lessonName + " was not found!"); + } + + + private void selectRandomDesign(AddLessonPage addLesson, String lessonName) { + + // Gets all the nodes in the user's folder + List designs = addLesson.openLessontab().getFolderNodes("user"); + + int randomDesign = Integer.parseInt(LamsUtil.randInt(1, designs.size()-1)); + + addLesson + .openLessontab() + .clickDesign(designs.get(randomDesign)) + .setLessonName(lessonName); + + } + + @Test(dependsOnMethods="createLessonWithAllMonitors") + public void createLessonWithOnlyOneLearner() { + + } + + + /** + * Advanced tab tests + */ + + @Test(dependsOnMethods="createLessonWithOnlyOneLearner") + public void createLessonWithIntro() { + + } + + @Test(dependsOnMethods="createLessonWithIntro") + public void createLessonStartInMonitor() { + + } + + @Test(dependsOnMethods="createLessonStartInMonitor") + public void createLessonStartAlwaysFirstActivity() { + + } + + @Test(dependsOnMethods="createLessonStartInMonitor") + public void createLessonWithOutLiveEdit() { + + } + + @Test(dependsOnMethods="createLessonWithOutLiveEdit") + public void createLessonStartWithOutLessonNotifications() { + + } + + @Test(dependsOnMethods="createLessonStartWithOutLessonNotifications") + public void createLessonEnableExportPortfolio() { + + } + + @Test(dependsOnMethods="createLessonEnableExportPortfolio") + public void createLessonEnableWhosOnline() { + + } + + @Test(dependsOnMethods="createLessonEnableWhosOnline") + public void createLessonEnableIM() { + + } + + @Test(dependsOnMethods="createLessonEnableIM") + public void createLessonSplitInMultiple() { + + } + + @Test(dependsOnMethods="createLessonEnableIM") + public void createLessonScheduleStart() { + + } + + + private AddLessonPage openDialog(IndexPage index) { + addLesson = index.addLesson(); + //driver.switchTo().frame("dialogFrame"); + + return addLesson; + } + + +} Index: lams_tests/tests/org/lamsfoundation/lams/pages/IndexPage.java =================================================================== diff -u -r077b9d360fde841db54cae0b4df5db8ed3f4049e -r4dea7ee858c3b437aebe1d0afe4f374b7ec0dd94 --- lams_tests/tests/org/lamsfoundation/lams/pages/IndexPage.java (.../IndexPage.java) (revision 077b9d360fde841db54cae0b4df5db8ed3f4049e) +++ lams_tests/tests/org/lamsfoundation/lams/pages/IndexPage.java (.../IndexPage.java) (revision 4dea7ee858c3b437aebe1d0afe4f374b7ec0dd94) @@ -23,10 +23,14 @@ package org.lamsfoundation.lams.pages; import org.lamsfoundation.lams.pages.author.FLAPage; +import org.lamsfoundation.lams.pages.monitor.addlesson.AddLessonPage; +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; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; /** * IndexPage @@ -42,6 +46,10 @@ @FindBy(id = "My Profile") private WebElement myProfileTab; + @FindBy(className = "add-lesson-button") + private WebElement addLessonButton; + + public IndexPage(WebDriver driver) { super(driver); } @@ -52,5 +60,20 @@ return PageFactory.initElements(driver, FLAPage.class); } - + public AddLessonPage addLesson() { + + addLessonButton.click(); + WebDriverWait wait = new WebDriverWait(driver, 2); + wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.id("dialogFrame"))); + + return PageFactory.initElements(driver, AddLessonPage.class); + } + + public Boolean isLessonPresent(String lessonName) { + + return ((driver.findElements(By.linkText(lessonName)).size() > 0) ? true : false); + + + } + } Index: lams_tests/tests/org/lamsfoundation/lams/pages/monitor/addlesson/AddLessonPage.java =================================================================== diff -u --- lams_tests/tests/org/lamsfoundation/lams/pages/monitor/addlesson/AddLessonPage.java (revision 0) +++ lams_tests/tests/org/lamsfoundation/lams/pages/monitor/addlesson/AddLessonPage.java (revision 4dea7ee858c3b437aebe1d0afe4f374b7ec0dd94) @@ -0,0 +1,103 @@ +/**************************************************************** + * 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.monitor.addlesson; + +import org.lamsfoundation.lams.pages.AbstractPage; +import org.lamsfoundation.lams.pages.IndexPage; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; +import org.openqa.selenium.support.PageFactory; + +public class AddLessonPage extends AbstractPage { + + /** + * Tabs & buttons + * These are the menu buttons and tabs on this interface + */ + + + @FindBy(id = "tabLessonLink") + private WebElement tabLessonLink; + + @FindBy(id = "tabClassLink") + private WebElement tabClassLink; + + @FindBy(id = "tabAdvanceHeader") + private WebElement tabAdvanceHeader; + + @FindBy(id = "tabConditionsLink") + private WebElement tabConditionsLink; + + @FindBy(id = "addButton") + private WebElement addButton; + + @FindBy(id = "closeButton") + private WebElement closeButton; + + + + public AddLessonPage(WebDriver driver) { + super(driver); + + } + + /** + * Returns the text within the add lesson button + * @return text within the Add lesson button + */ + public String checkAddLessonButton() { + + return addButton.getText().trim(); + + } + + public LessonTab openLessontab() { + + tabLessonLink.click(); + + return PageFactory.initElements(driver, LessonTab.class); + } + + public ClassTab openClasstab() { + + tabClassLink.click(); + + return PageFactory.initElements(driver, ClassTab.class); + } + + public IndexPage addLessonNow() { + + addButton.click(); + driver.switchTo().defaultContent(); + return PageFactory.initElements(driver, IndexPage.class); + } + + public IndexPage closeDialog() { + + closeButton.click(); + driver.switchTo().defaultContent(); + return PageFactory.initElements(driver, IndexPage.class); + + } +} Index: lams_tests/tests/org/lamsfoundation/lams/pages/monitor/addlesson/ClassTab.java =================================================================== diff -u --- lams_tests/tests/org/lamsfoundation/lams/pages/monitor/addlesson/ClassTab.java (revision 0) +++ lams_tests/tests/org/lamsfoundation/lams/pages/monitor/addlesson/ClassTab.java (revision 4dea7ee858c3b437aebe1d0afe4f374b7ec0dd94) @@ -0,0 +1,111 @@ +/**************************************************************** + * 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.monitor.addlesson; + +import java.util.List; + +import org.lamsfoundation.lams.pages.AbstractPage; +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; + +public class ClassTab extends AbstractPage { + + + public static final String classTabTitle = "Please use drag n' drop to select or unselect monitors and learners"; + + /** + * Lesson tab attributes + */ + + @FindBy(id = "tabClassTitle") + private WebElement tabClassTitle; + + @FindBy(id = "unselected-monitors") + private WebElement unselectedMonitors; + + @FindBy(id = "monitorMoveToRight") + private WebElement monitorMoveToRight; + + @FindBy(id = "monitorMoveToLeft") + private WebElement monitorMoveToLeft; + + @FindBy(id = "selected-monitors") + private WebElement selectedMonitors; + + @FindBy(id = "unselected-learners") + private WebElement unselectedLearners; + + @FindBy(id = "learnerMoveToRight") + private WebElement learnerMoveToRight; + + @FindBy(id = "learnerMoveToLeft") + private WebElement learnerMoveToLeft; + + @FindBy(id = "selected-learners") + private WebElement selectedLearners; + + public ClassTab(WebDriver driver) { + super(driver); + + } + + public ClassTab addAllMonitorsToLesson() { + + List monitorsAvailable = unselectedMonitors.findElements(By.tagName("div")); + + for (WebElement monitor : monitorsAvailable) { + + monitor.click(); + monitorMoveToRight.click(); + + } + + return PageFactory.initElements(driver, ClassTab.class); + } + + public int getNumberSelectedMonitors() { + + return selectedMonitors.findElements(By.tagName("div")).size(); + } + + public int getNumberUnselectedMonitors() { + + return unselectedMonitors.findElements(By.tagName("div")).size(); + + } + + public int getNumberSelectedLearners() { + + return selectedLearners.findElements(By.tagName("div")).size(); + } + + public int getNumberUnselectedLearners() { + + return unselectedLearners.findElements(By.tagName("div")).size(); + } + + +} Index: lams_tests/tests/org/lamsfoundation/lams/pages/monitor/addlesson/LessonTab.java =================================================================== diff -u --- lams_tests/tests/org/lamsfoundation/lams/pages/monitor/addlesson/LessonTab.java (revision 0) +++ lams_tests/tests/org/lamsfoundation/lams/pages/monitor/addlesson/LessonTab.java (revision 4dea7ee858c3b437aebe1d0afe4f374b7ec0dd94) @@ -0,0 +1,237 @@ +/**************************************************************** + * 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.monitor.addlesson; + +import java.util.ArrayList; +import java.util.List; + +import org.lamsfoundation.lams.pages.AbstractPage; +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; + +public class LessonTab extends AbstractPage { + + public static final String lessonTitle = "Select the sequence to add a lesson, and click on Add now"; + + + /** + * Lesson tab attributes + */ + + @FindBy(id = "tabLessonTitle") + private WebElement tabLessonTitle; + + @FindBy(id = "lessonNameInput") + private WebElement lessonNameInput; + + + /** + * LD Tree attributes + */ + + @FindBy(id = "ygtvc0") + private WebElement ldTreeRoot; + + @FindBy(id = "ygtvt1") + private WebElement openCloseUserFolder; + + @FindBy(id = "ygtvlabelel1") + private WebElement userFolderName; + + @FindBy(id = "ygtvc1") + private WebElement userFolderNodes; + + @FindBy(id = "ygtvt2") + private WebElement openCloseMyCourseFolder; + + @FindBy(id = "ygtvlabelel2") + private WebElement myCourseFolderName; + + @FindBy(id = "ygtvc2") + private WebElement myCourseFolderNodes; + + @FindBy(id = "ygtvt3") + private WebElement openClosePublicFolder; + + @FindBy(id = "ygtvlabelel3") + private WebElement publicFolderName; + + @FindBy(id = "ygtvc3") + private WebElement publicFolderNodes; + + @FindBy(id = "ldScreenshotAuthor") + private WebElement imgDesign; + + + + public LessonTab(WebDriver driver) { + super(driver); + + } + + + /** + * Returns lessonTab title + * + * This is just static text to check that you are in + * the correct tab. + * + * @return lessonTab title + */ + public String getLessonTabTitle() { + + return tabLessonTitle.getText(); + + } + + /** + * Sets the lesson name + * @param lessonName + * @return {@link LessonTab} + */ + public LessonTab setLessonName(String lessonName) { + + lessonNameInput.click(); + lessonNameInput.clear(); + lessonNameInput.sendKeys(lessonName); + + return PageFactory.initElements(driver, LessonTab.class); + } + + /** + * Returns lesson name + * @return lesson name + */ + public String getLessonName() { + + return lessonNameInput.getAttribute("value"); + } + + + /** + * Collapses / open folders + * + * Gets a folder name and clicks on it to open/collapse it. + * + * @param folder + * @return {@link LessonTab} + */ + public LessonTab clickFolder(String folder) { + + switch (folder) { + case "user": + + openCloseUserFolder.click(); + + break; + + case "courses": + + openCloseMyCourseFolder.click(); + + break; + + case "public": + + openClosePublicFolder.click(); + + break; + } + + return PageFactory.initElements(driver, LessonTab.class); + } + + + /** + * Returns the nodes for the designs + * + * This is probably not the best way to do this as it exposes + * WebElement objects to the test layer. But at the same time + * for the purpose of testing it does a fine job. + * + * @param folder + * @return List of nodes as WebElements + */ + public List getFolderNodes(String folder) { + + List designs = new ArrayList(); + + switch (folder) { + case "user": + + designs = userFolderNodes.findElements(By.tagName("span")); + + break; + + case "courses": + + designs = myCourseFolderNodes.findElements(By.tagName("span")); + + break; + + case "public": + + designs = publicFolderNodes.findElements(By.tagName("span")); + + break; + } + return designs; + + } + + + /** + * Checks if when the design is selected, the image for the design + * is displayed. + * + * @return + */ + public boolean isDesignImageDisplayed() { + + String imageURL = ""; + + imageURL = imgDesign.getAttribute("src"); + + return (imageURL.isEmpty() ? false : true); + } + + + /** + * Clicks on design to create a lesson with. + * + * @param design + * @return {@link LessonTab} + */ + public LessonTab clickDesign(WebElement design) { + + design.click(); + + return PageFactory.initElements(driver, LessonTab.class); + } + + + +}