Index: lams_tests/tests/org/lamsfoundation/lams/pages/author/FLAPage.java =================================================================== RCS file: /usr/local/cvsroot/lams_tests/tests/org/lamsfoundation/lams/pages/author/FLAPage.java,v diff -u -r1.8 -r1.9 --- lams_tests/tests/org/lamsfoundation/lams/pages/author/FLAPage.java 28 Oct 2014 12:58:40 -0000 1.8 +++ lams_tests/tests/org/lamsfoundation/lams/pages/author/FLAPage.java 13 Feb 2015 15:00:14 -0000 1.9 @@ -30,6 +30,7 @@ import org.lamsfoundation.lams.author.util.AuthorConstants; import org.lamsfoundation.lams.pages.AbstractPage; +import org.lamsfoundation.lams.pages.tool.forum.AuthorPage; import org.openqa.selenium.Alert; import org.openqa.selenium.By; import org.openqa.selenium.Point; @@ -1024,7 +1025,59 @@ return txt; } + + /* Open specific tool authoring windows*/ + + /** + * Opens Forum Authoring + * + * @param activityName the name of the activity to open + * @return abstractPage factory so it can be manipulated. + * + */ + public AuthorPage openForumAuthoring(String activityName) { + + WebElement act = getActivityElement(activityName); + + Actions openAct = new Actions(driver); + openAct.doubleClick(act).build().perform();; + + String popUpWindow = getPopUpWindowId(driver); + + driver.switchTo().window(popUpWindow); + + return PageFactory.initElements(driver, AuthorPage.class); + + + } + + + + + + + + + + + + + + + + + + + + + + + + + + + /** * Returns the correct popup id * * @param driver Index: lams_tests/tests/org/lamsfoundation/lams/pages/tool/forum/AdvancedTab.java =================================================================== RCS file: /usr/local/cvsroot/lams_tests/tests/org/lamsfoundation/lams/pages/tool/forum/AdvancedTab.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_tests/tests/org/lamsfoundation/lams/pages/tool/forum/AdvancedTab.java 13 Feb 2015 15:00:14 -0000 1.1 @@ -0,0 +1,369 @@ +/**************************************************************** + * 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.tool.forum; + +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.ui.Select; + +public class AdvancedTab extends AbstractPage { + + /** + * Forum author advanced tab page properties + */ + + @FindBy(name="forum.lockWhenFinished") + private WebElement lockWhenFinished; + + @FindBy(name="forum.allowEdit") + private WebElement allowEdit; + + @FindBy(name="forum.allowRateMessages") + private WebElement allowRateMessages; + + @FindBy(id="minimumRate") + private WebElement minimumRate; + + @FindBy(id="maximumRate") + private WebElement maximumRate; + + @FindBy(name="forum.allowUpload") + private WebElement allowUpload; + + @FindBy(name="forum.allowRichEditor") + private WebElement allowRichEditor; + + @FindBy(name="forum.limitedMinCharacters") + private WebElement limitedMinCharacters; + + @FindBy(name="forum.minCharacters") + private WebElement minCharacters; + + @FindBy(name="forum.limitedMaxCharacters") + private WebElement limitedMaxCharacters; + + @FindBy(name="forum.maxCharacters") + private WebElement maxCharacters; + + @FindBy(name="forum.notifyLearnersOnForumPosting") + private WebElement notifyLearnersOnForumPosting; + + @FindBy(name="forum.notifyTeachersOnForumPosting") + private WebElement notifyTeachersOnForumPosting; + + @FindBy(name="forum.notifyLearnersOnMarkRelease") + private WebElement notifyLearnersOnMarkRelease; + + @FindBy(name="forum.reflectOnActivity") + private WebElement reflectOnActivity; + + @FindBy(name="forum.reflectInstructions") + private WebElement reflectInstructions; + + @FindBy(name="forum.allowNewTopic") + private WebElement allowNewTopic; + + @FindBy(name="forum.minimumReply") + private WebElement minimumReply; + + @FindBy(name="forum.maximumReply") + private WebElement maximumReply; + + + public AdvancedTab(WebDriver driver) { + super(driver); + // TODO Auto-generated constructor stub + } + + public void setLockedWhenFinished(boolean value) { + + if(value && !lockWhenFinished.isSelected()){ + + lockWhenFinished.click(); + + } else if (lockWhenFinished.isSelected() && !value) { + + lockWhenFinished.click(); + } + + } + + public boolean isLockWhenFinished() { + + return lockWhenFinished.isSelected(); + + } + + public void setAllowEdit(boolean value) { + + if(value && !allowEdit.isSelected()) { + + allowEdit.click(); + + } else if(allowEdit.isSelected() && !value) { + + allowEdit.click(); + + } + } + + public boolean isAllowEdit() { + + return allowEdit.isSelected(); + + } + + public void setAllowRateMessages(boolean value) { + + if(value && !allowRateMessages.isSelected()) { + + allowRateMessages.click(); + + } else if(allowRateMessages.isSelected() && !value) { + + allowRateMessages.click(); + + } + } + + + public boolean isAllowRateMessages() { + + return allowRateMessages.isSelected(); + + } + + public void setMinimumRate(String value) { + + if(allowRateMessages.isEnabled()) { + minimumRate.sendKeys(value); + } + + } + + public String getMinimumRate() { + WebElement selectMinRate = minimumRate; + Select select = new Select(selectMinRate); + + return select.getFirstSelectedOption().getText(); + } + + + public void setMaximumRate(String value) { + + if(allowRateMessages.isEnabled()) { + maximumRate.sendKeys(value); + } + + } + + public String getMaximumRate() { + WebElement selectMaxRate = maximumRate; + Select select = new Select(selectMaxRate); + + return select.getFirstSelectedOption().getText(); + } + + public void setAllowUpload(Boolean value) { + + if(value && !allowUpload.isSelected()) { + + allowUpload.click(); + + } else if(allowUpload.isSelected() && !value) { + + allowUpload.click(); + + } + } + + public boolean isAllowUpload() { + + return allowUpload.isSelected(); + } + + public void setAllowRichText(Boolean value) { + + if(value && !allowRichEditor.isSelected()) { + + allowRichEditor.click(); + + } else if(allowRichEditor.isSelected() && !value) { + + allowRichEditor.click(); + + } + } + + + public boolean isAllowRichEditor() { + + return allowRichEditor.isSelected(); + + } + + public void setLimitedMinCharacters(Boolean value) { + + if(value && !limitedMinCharacters.isSelected()) { + + limitedMinCharacters.click(); + + } else if(limitedMinCharacters.isSelected() && !value) { + + limitedMinCharacters.click(); + + } + } + + public boolean isLimitedMinCharacters() { + + return limitedMinCharacters.isSelected(); + } + + + public void setMinCharacters(String value) { + + if(isLimitedMinCharacters()) { + minCharacters.clear(); + minCharacters.sendKeys(value); + + } + + } + + public String getMinCharacters() { + + return minCharacters.getAttribute("value").trim(); + + } + + + + public void setLimitedMaxCharacters(Boolean value) { + + if(value && !limitedMaxCharacters.isSelected()) { + + limitedMaxCharacters.click(); + + } else if(limitedMaxCharacters.isSelected() && !value) { + + limitedMaxCharacters.click(); + + } + } + + public boolean isLimitedMaxCharacters() { + + return limitedMaxCharacters.isSelected(); + } + + public void setMaxCharacters(String value) { + + if(isLimitedMaxCharacters()) { + + maxCharacters.clear(); + maxCharacters.sendKeys(value); + + } + + } + + public String getMaxCharacters() { + + return maxCharacters.getAttribute("value").trim(); + + } + + public void setNotifyLearnersOnForumPosting(Boolean value) { + + if(value && !notifyLearnersOnForumPosting.isSelected()) { + + notifyLearnersOnForumPosting.click(); + + } else if(notifyLearnersOnForumPosting.isSelected() && !value) { + + notifyLearnersOnForumPosting.click(); + + } + + } + + + public boolean isNotifyLearnersOnForumPosting() { + + return notifyLearnersOnForumPosting.isSelected(); + + } + + public void setNotifyTeachersOnForumPosting(Boolean value) { + + if(value && !notifyTeachersOnForumPosting.isSelected()) { + + notifyTeachersOnForumPosting.click(); + + } else if(notifyTeachersOnForumPosting.isSelected() && !value) { + + notifyTeachersOnForumPosting.click(); + + } + + } + + public boolean isNotifyTeachersOnForumPosting() { + + return notifyTeachersOnForumPosting.isSelected(); + + } + + public void setNotifyLearnersOnMarkRelease(Boolean value) { + + if(value && !notifyLearnersOnMarkRelease.isSelected()) { + + notifyLearnersOnMarkRelease.click(); + + } else if(notifyLearnersOnMarkRelease.isSelected() && !value) { + + notifyLearnersOnMarkRelease.click(); + + } + + } + + public boolean isNotifyLearnersOnMarkRelease() { + + return notifyLearnersOnMarkRelease.isSelected(); + } + + public boolean isReflectOnActivity() { + + return reflectOnActivity.isSelected(); + } + + + public boolean isAllowNewTopic() { + + return allowNewTopic.isSelected(); + } +} Index: lams_tests/tests/org/lamsfoundation/lams/pages/tool/forum/AuthorPage.java =================================================================== RCS file: /usr/local/cvsroot/lams_tests/tests/org/lamsfoundation/lams/pages/tool/forum/AuthorPage.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_tests/tests/org/lamsfoundation/lams/pages/tool/forum/AuthorPage.java 13 Feb 2015 15:00:14 -0000 1.1 @@ -0,0 +1,154 @@ +/**************************************************************** + * 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.tool.forum; + +import java.util.Iterator; +import java.util.Set; + +import org.lamsfoundation.lams.pages.AbstractPage; +import org.openqa.selenium.Alert; +import org.openqa.selenium.JavascriptExecutor; +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; + +/** + * @author Ernie Ghiglione (ernieg@lamsfoundation.org) + * + */ +public class AuthorPage extends AbstractPage { + + /** + * Forum author page properties + */ + + @FindBy(id = "tab-middle-link-1") + private WebElement basicTab; + + @FindBy(id = "tab-middle-link-2") + private WebElement advancedTab; + + @FindBy(id = "tab-middle-link-3") + private WebElement conditionsTab; + + @FindBy(id = "cancelButton") + private WebElement cancelButton; + + @FindBy(id = "saveButton") + private WebElement saveButton; + + @FindBy(className="close") + private WebElement closeButton; + + @FindBy(className="editForm") + private WebElement reEdit; + + public AuthorPage(WebDriver driver) { + super(driver); + // TODO Auto-generated constructor stub + } + + + /** + * Open basic tab + * + * @return + */ + public BasicTab openBasicTab() { + basicTab.click(); + + return PageFactory.initElements(driver, BasicTab.class); + } + + /** + * Open advanced tab + * + * @return + */ + public AdvancedTab openAdvancedTab() { + advancedTab.click(); + + return PageFactory.initElements(driver, AdvancedTab.class); + } + + + public void cancel(String windowHandler) { + + cancelButton.click(); + getAlertText(); + driver.switchTo().window(windowHandler); + + } + + public void save() { + saveButton.click(); + } + + public void close(String windowHandler) { + closeButton.click(); + driver.switchTo().window(windowHandler); + } + + public void reEdit() { + reEdit.click(); + } + + /** + * Clicks OK on the alert javascript popup and returns text + * + * @return text from popup + */ + private String getAlertText() { + + String txt = null; + + try { + WebDriverWait wait = new WebDriverWait(driver, 2); + wait.until(ExpectedConditions.alertIsPresent()); + Alert alert = driver.switchTo().alert(); + txt = alert.getText(); + alert.accept(); + + } catch (Exception e) { + } + return txt; + } + + public String getPopUpWindowId(WebDriver driver) { + + String authorToolWindow = null; + Set handles = driver.getWindowHandles(); + Iterator iterator = handles.iterator(); + + while (iterator.hasNext()){ + authorToolWindow = iterator.next(); + System.out.println("handle: " + authorToolWindow); + } + + return authorToolWindow; +} + +} Index: lams_tests/tests/org/lamsfoundation/lams/pages/tool/forum/BasicTab.java =================================================================== RCS file: /usr/local/cvsroot/lams_tests/tests/org/lamsfoundation/lams/pages/tool/forum/BasicTab.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_tests/tests/org/lamsfoundation/lams/pages/tool/forum/BasicTab.java 13 Feb 2015 15:00:14 -0000 1.1 @@ -0,0 +1,148 @@ +/**************************************************************** + * 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.tool.forum; + +import org.lamsfoundation.lams.pages.AbstractPage; +import org.openqa.selenium.By.ById; +import org.openqa.selenium.Alert; +import org.openqa.selenium.By; +import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; + +public class BasicTab extends AbstractPage { + + /** + * Forum author basic tab page properties + */ + + @FindBy(name="forum.title") + private WebElement forumTitle; + + @FindBy(id = "messageListArea") + private WebElement messageListArea; + + @FindBy(id = "addTopic") + private WebElement addTopic; + + + @FindBy(name="message.subject") + private WebElement messsageSubject; + + @FindBy(id="cancelMsg") + private WebElement cancelMessage; + + @FindBy(id="addMsg") + private WebElement addMessage; + + + + public BasicTab(WebDriver driver) { + super(driver); + // TODO Auto-generated constructor stub + } + + public String getTitle() { + + return forumTitle.getAttribute("value").trim(); + + } + + public String getIntructions() { + + String getText = (String) ((JavascriptExecutor) + driver).executeScript("return (CKEDITOR.instances['forum.instructions'].getData());"); + + getText = getText.replaceAll("[\n\r]", ""); + return getText; + } + + public void addTopic() { + + addTopic.click(); + driver.switchTo().frame("messageArea"); + + } + + public void setMessageSubject(String subject) { + + messsageSubject.sendKeys(subject); + + } + + public void setMessageBody(String body) { + + // Insert text to CKEditor via javascript + ((JavascriptExecutor) + driver).executeScript("CKEDITOR.instances['message.body'].setData('" + body +"');"); + + + + } + + public void addMessage() { + + addMessage.click(); + driver.switchTo().defaultContent(); + } + + public boolean messageExists(String topicTitle) { + + return messageListArea.getText().contains(topicTitle); + + } + + public void deleteMesage(Integer number) { + + driver.findElement(By.id("delete"+number)).click(); + getAlertText(); + + } + + + /** + * Clicks OK on the alert javascript popup and returns text + * + * @return text from popup + */ + public String getAlertText() { + + String txt = null; + + try { + WebDriverWait wait = new WebDriverWait(driver, 2); + wait.until(ExpectedConditions.alertIsPresent()); + Alert alert = driver.switchTo().alert(); + txt = alert.getText(); + + alert.accept(); + } catch (Exception e) { + } + return txt; + } + + +} Index: lams_tests/tests/org/lamsfoundation/lams/pages/tool/forum/util/ForumConstants.java =================================================================== RCS file: /usr/local/cvsroot/lams_tests/tests/org/lamsfoundation/lams/pages/tool/forum/util/ForumConstants.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_tests/tests/org/lamsfoundation/lams/pages/tool/forum/util/ForumConstants.java 13 Feb 2015 15:00:14 -0000 1.1 @@ -0,0 +1,37 @@ +/**************************************************************** + * 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.tool.forum.util; + +public class ForumConstants { + + // Constants + + // Default values (English AU) + + public static final String FORUM_TITLE = "Forum"; + public static final String FORUM_INSTRUCTIONS = "
Instructions
"; + + public static final String FORUM_BODY_TXT = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin elementum est ut facilisis ornare. Suspendisse potenti. Donec non lectus aliquet, aliquam felis vel, elementum eros. Sed dictum ac elit vel porta. Praesent sodales nisi ut lorem feugiat finibus. Fusce aliquam viverra condimentum. Vestibulum ligula nunc, ullamcorper vel augue eu, sodales imperdiet nunc. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed egestas libero sit amet lacinia tristique. Sed consequat arcu nec neque scelerisque sollicitudin. Fusce eget bibendum mauris, interdum laoreet enim. Duis auctor rhoncus mi. Phasellus semper vitae nulla in facilisis. Phasellus gravida euismod nunc at tempus. Mauris sodales turpis at tortor lobortis, consequat maximus ex malesuada. Nulla varius efficitur lacinia. Nunc condimentum ex ac fringilla finibus. Ut placerat efficitur tortor vehicula euismod. Aliquam vel tempor purus, sit amet sodales orci. Proin mattis mollis diam ac rhoncus. Nulla in malesuada odio, id pellentesque ligula. Sed rutrum quis ipsum eu luctus. In hac habitasse platea dictumst. Vivamus id ex ac dui accumsan bibendum nec eget mauris. Quisque eu dui leo. Vestibulum vitae lacus vitae nisl blandit ultrices pharetra at dolor. Fusce ac ipsum sed odio porta tincidunt eu iaculis ligula. Proin et lacus nibh. Aenean arcu magna, sodales eu mi non, consequat sodales ligula. Integer in lacinia ex, eget egestas dui. Aliquam lacus est, sodales sed fringilla eget, semper ac dolor. Nulla sed ante id orci bibendum tempor quis sed orci. Etiam tincidunt arcu ligula, sed auctor turpis sollicitudin non. Pellentesque nunc ex, luctus sed rhoncus sed, commodo vel purus. Maecenas maximus varius leo id dignissim. In hac habitasse platea dictumst. Donec ac mattis nisl, in cursus nibh. Donec ut ante dignissim ligula hendrerit faucibus. In fermentum faucibus massa sit amet varius. Praesent quis lorem at eros mattis interdum a tristique risus. Suspendisse gravida tellus quam, sed tempus."; + public static final String FORUM_DEFAULT_TOPIC = "Topic Heading"; + +} Index: lams_tests/tests/org/lamsfoundation/org/lams/tool/forum/AuthorTests.java =================================================================== RCS file: /usr/local/cvsroot/lams_tests/tests/org/lamsfoundation/org/lams/tool/forum/Attic/AuthorTests.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_tests/tests/org/lamsfoundation/org/lams/tool/forum/AuthorTests.java 13 Feb 2015 15:00:14 -0000 1.1 @@ -0,0 +1,575 @@ +/**************************************************************** + * 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.org.lams.tool.forum; + +import java.util.List; +import java.util.concurrent.TimeUnit; + +import org.lamsfoundation.lams.author.util.AuthorConstants; +import org.lamsfoundation.lams.pages.IndexPage; +import org.lamsfoundation.lams.pages.LoginPage; +import org.lamsfoundation.lams.pages.author.FLAPage; +import org.lamsfoundation.lams.pages.tool.forum.AuthorPage; +import org.lamsfoundation.lams.pages.tool.forum.BasicTab; +import org.lamsfoundation.lams.pages.tool.forum.AdvancedTab; +import org.lamsfoundation.lams.pages.tool.forum.util.ForumConstants; +import org.lamsfoundation.lams.util.LamsUtil; +import org.openqa.selenium.WebDriver; +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; + + +/** + * + * Add lesson tests + * + * @author Ernie Ghiglione (ernieg@lamsfoundation.org) + * + * + * Tests to add: + * - Check default settings + * - Change title, instructions + * - Check title, instructions after save + * - Add new threads + * - Change d + * + * + * + * + * + * + */ + + +public class AuthorTests { + + + private static final String RANDOM_INT = LamsUtil.randInt(0, 9999); + + private LoginPage onLogin; + private IndexPage index; + private FLAPage fla; + private AuthorPage forumAuthorPage; + + public String flaHandler; + + 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); + fla = PageFactory.initElements(driver, FLAPage.class); + forumAuthorPage = PageFactory.initElements(driver, AuthorPage.class); + onLogin.navigateToLamsLogin().loginAs("test3", "test3"); + + } + + + /** + * Opens FLA interface + */ + @Test + public void openFLA() { + + FLAPage fla = new FLAPage(driver); + fla = index.openFla(); + flaHandler = driver.getWindowHandle(); + fla.maximizeWindows(); + Assert.assertEquals(AuthorConstants.FLA_TITLE, fla.getTitle(), "The expected title is not present"); + + } + + /** + * Drop a forum in the canvas + */ + @Test(dependsOnMethods={"openFLA"}) + public void dragForumToCanvas() { + + String forumTitle = ForumConstants.FORUM_TITLE + "Basic " + RANDOM_INT; + + // Drop activities in canvas + fla.dragActivityToCanvasPosition(AuthorConstants.FORUM_TITLE, 100, 100) + .changeActivityTitle(AuthorConstants.FORUM_TITLE, forumTitle); + + // Now get all the activity titles + List allActivityTitles = fla.getAllActivityNames(); + + // Assert that all of them are in the design + + Assert.assertTrue(allActivityTitles.contains(forumTitle), + "The title " + forumTitle + " was not found as an activity in the design"); + + } + + /** + * Open forum authoring + */ + @Test(dependsOnMethods={"dragForumToCanvas"}) + public void openForumAuthoring() { + + // open forum author + AuthorPage forumAuthorPage = fla.openForumAuthoring(ForumConstants.FORUM_TITLE); + + String forumWindowTitle = forumAuthorPage.getWindowTitle(); + + // Assert forum window title + Assert.assertEquals(forumWindowTitle, ForumConstants.FORUM_TITLE); + + } + + /** + * Check forum default values basic tab + */ + @Test(dependsOnMethods={"openForumAuthoring"}) + public void checkBasicTabDefaultValues() { + + BasicTab basicTab = forumAuthorPage.openBasicTab(); + + // Get default title and instructions + String forumTitle = basicTab.getTitle(); + String forumInstructions = basicTab.getIntructions(); + + // Assert forum defaults (basic tab) + + Assert.assertEquals(forumTitle, ForumConstants.FORUM_TITLE); + Assert.assertEquals(forumInstructions, ForumConstants.FORUM_INSTRUCTIONS); + + } + + /** + * Check forum default values advanced tab + */ + @Test(dependsOnMethods={"checkBasicTabDefaultValues"}) + public void checkAdvancedTabDefaultValues() { + + AdvancedTab advancedTab = forumAuthorPage.openAdvancedTab(); + + // Get default values + Boolean isLockWhenFinished = advancedTab.isLockWhenFinished(); + Boolean isAllowEdit = advancedTab.isAllowEdit(); + Boolean isAllowRateMessages = advancedTab.isAllowRateMessages(); + Boolean isAllowUploads = advancedTab.isAllowUpload(); + Boolean isAllowRichEditor = advancedTab.isAllowRichEditor(); + Boolean isLimitedMinCharacters = advancedTab.isLimitedMinCharacters(); + Boolean isLimitedMaxCharacters = advancedTab.isLimitedMaxCharacters(); + Boolean isNotifyLearnersOnForumPosting = advancedTab.isNotifyLearnersOnForumPosting(); + Boolean isNotifyTeachersOnForumPosting = advancedTab.isNotifyTeachersOnForumPosting(); + Boolean isNotifyLearnersOnMarkRelease = advancedTab.isNotifyLearnersOnMarkRelease(); + Boolean isReflectOnActivity = advancedTab.isReflectOnActivity(); + Boolean isAllowNewTopic = advancedTab.isAllowNewTopic(); + + Assert.assertFalse(isLockWhenFinished, "Locked when finish should be false by default"); + Assert.assertTrue(isAllowEdit, "Allow learners to change their posting should be true by default"); + Assert.assertFalse(isAllowRateMessages, "Rate messages should be false by default"); + Assert.assertFalse(isAllowUploads, "Learners attacchments should be false by default"); + Assert.assertFalse(isAllowRichEditor, "CKEditor should be false by default"); + Assert.assertFalse(isLimitedMinCharacters, "There's no minimum number of characters by default"); + Assert.assertTrue(isLimitedMaxCharacters, "There should be a limit in the max number of characters by default"); + Assert.assertFalse(isNotifyLearnersOnForumPosting, "Option to notify learners should be off by default "); + Assert.assertFalse(isNotifyTeachersOnForumPosting, "Option to notify teacher should be false by default"); + Assert.assertFalse(isNotifyLearnersOnMarkRelease, "Notify learners on mark release should be false by default"); + Assert.assertFalse(isReflectOnActivity, "Reflection should false by default"); + Assert.assertTrue(isAllowNewTopic, "Allow new topics should be true by default"); + + } + + + /** + * Add topic + */ + @Test(dependsOnMethods={"checkAdvancedTabDefaultValues"}) + public void addTopic() { + + String msgTitle = "Topic# " + RANDOM_INT; + String msgBody = "" + RANDOM_INT + "" + "

" + ForumConstants.FORUM_BODY_TXT + "

" + ForumConstants.FORUM_BODY_TXT + "

"; + + BasicTab basicTab = forumAuthorPage.openBasicTab(); + + basicTab.addTopic(); + basicTab.setMessageSubject(msgTitle); + basicTab.setMessageBody(msgBody); + basicTab.addMessage(); + + forumAuthorPage.save(); + + // Check that the message was saved appropriately + + forumAuthorPage.reEdit(); + + boolean topicExists = basicTab.messageExists(msgTitle); + Assert.assertTrue(topicExists, "For some reason message title " + msgTitle + " didn't save");; + + } + + /** + * Delete topic + */ + @Test(dependsOnMethods={"addTopic"}) + public void deleteTopic() { + + // Delete the first default message + BasicTab basicTab = forumAuthorPage.openBasicTab(); + basicTab.deleteMesage(0); + + forumAuthorPage.save(); + forumAuthorPage.reEdit(); + + // Assert that default message was deleted + boolean msgExists = basicTab.messageExists(ForumConstants.FORUM_DEFAULT_TOPIC); + + Assert.assertFalse(msgExists, "Default message still exists"); + + forumAuthorPage.cancel(flaHandler); + + } + + + + /** + * Add forum with Locked when finished + */ + @Test(dependsOnMethods={"deleteTopic"}) + public void addForumLockedWhenFinished() { + + String forumTitle = "Locked " + RANDOM_INT; + + // Drop activities in canvas + fla.dragActivityToCanvasPosition(AuthorConstants.FORUM_TITLE, 300, 100) + .changeActivityTitle("Forum", forumTitle); + + // Assert new forum activity title + + // Now get all the activity titles + List allActivityTitles = fla.getAllActivityNames(); + + // Assert that all of them are in the design + + Assert.assertTrue(allActivityTitles.contains(forumTitle), + "The title " + forumTitle + " was not found as an activity in the design"); + + forumAuthorPage = fla.openForumAuthoring(forumTitle); + + forumAuthorPage.openAdvancedTab().setLockedWhenFinished(true); + + forumAuthorPage.save(); + + // Assert locked when finished was saved + + forumAuthorPage.reEdit(); + + boolean isLockedWhenFinshed = forumAuthorPage.openAdvancedTab().isLockWhenFinished(); + + Assert.assertTrue(isLockedWhenFinshed, "Option locked when finished is not set"); + + forumAuthorPage.cancel(flaHandler); + } + + /** + * Add forum with no re-edits allowed + */ + @Test(dependsOnMethods={"addForumLockedWhenFinished"}) + public void addForumEditNotAllowed() { + + String forumTitle = "NoEdit " + RANDOM_INT; + + // Drop activities in canvas + fla.dragActivityToCanvasPosition(AuthorConstants.FORUM_TITLE, 500, 100) + .changeActivityTitle("Forum", forumTitle); + + // Assert new forum activity title + // Now get all the activity titles + List allActivityTitles = fla.getAllActivityNames(); + + // Assert that all of them are in the design + + Assert.assertTrue(allActivityTitles.contains(forumTitle), + "The title " + forumTitle + " was not found as an activity in the design"); + + forumAuthorPage = fla.openForumAuthoring(forumTitle); + + forumAuthorPage.openAdvancedTab().setAllowEdit(false); + + forumAuthorPage.save(); + + // Assert edits are not allowed + + forumAuthorPage.reEdit(); + + boolean isAllowEdit = forumAuthorPage.openAdvancedTab().isAllowEdit(); + + Assert.assertFalse(isAllowEdit, "Option Allow Edit is still set"); + + forumAuthorPage.cancel(flaHandler); + } + + /** + * Add forum with ratings + */ + @Test(dependsOnMethods={"addForumEditNotAllowed"}) + public void addForumRatings() { + + String forumTitle = "Ratings " + RANDOM_INT; + String minimumRate = "1"; + String maximumRate = "5"; + + // Drop activities in canvas + fla.dragActivityToCanvasPosition(AuthorConstants.FORUM_TITLE, 700, 100) + .changeActivityTitle("Forum", forumTitle); + + // Assert new forum activity title + // Now get all the activity titles + List allActivityTitles = fla.getAllActivityNames(); + + // Assert that all of them are in the design + + Assert.assertTrue(allActivityTitles.contains(forumTitle), + "The title " + forumTitle + " was not found as an activity in the design"); + + forumAuthorPage = fla.openForumAuthoring(forumTitle); + + forumAuthorPage.openAdvancedTab().setAllowRateMessages(true); + forumAuthorPage.openAdvancedTab().setMinimumRate(minimumRate); + forumAuthorPage.openAdvancedTab().setMaximumRate(maximumRate); + + forumAuthorPage.save(); + + // Assert rating is on and the min and max are set + + forumAuthorPage.reEdit(); + + boolean isAllowEdit = forumAuthorPage.openAdvancedTab().isAllowRateMessages(); + String minRate = forumAuthorPage.openAdvancedTab().getMinimumRate(); + String maxRate = forumAuthorPage.openAdvancedTab().getMaximumRate(); + + Assert.assertTrue(isAllowEdit, "Option Allow Edit is still set"); + Assert.assertEquals(minRate, minimumRate, "Minimum rate is not the same"); + Assert.assertEquals(maxRate, maximumRate, "Maximum rate is not the same"); + + forumAuthorPage.cancel(flaHandler); + } + + /** + * Add forum with allow uploads on + */ + @Test(dependsOnMethods={"addForumRatings"}) + public void addForumUploads() { + + String forumTitle = "Upload " + RANDOM_INT; + + // Drop activities in canvas + fla.dragActivityToCanvasPosition(AuthorConstants.FORUM_TITLE,900, 100) + .changeActivityTitle("Forum", forumTitle); + + // Assert new forum activity title + // Now get all the activity titles + List allActivityTitles = fla.getAllActivityNames(); + + // Assert that all of them are in the design + + Assert.assertTrue(allActivityTitles.contains(forumTitle), + "The title " + forumTitle + " was not found as an activity in the design"); + + forumAuthorPage = fla.openForumAuthoring(forumTitle); + + forumAuthorPage.openAdvancedTab().setAllowUpload(true); + + forumAuthorPage.save(); + + // Assert that uploads was set properly + + forumAuthorPage.reEdit(); + + boolean isAllowUpload = forumAuthorPage.openAdvancedTab().isAllowUpload(); + + + Assert.assertTrue(isAllowUpload, "Option Allow Upload is not set"); + + + forumAuthorPage.cancel(flaHandler); + } + + /** + * Add forum with Rich Text editor + */ + @Test(dependsOnMethods={"addForumUploads"}) + public void addForumRichText() { + + String forumTitle = "RichText " + RANDOM_INT; + + // Drop activities in canvas + fla.dragActivityToCanvasPosition(AuthorConstants.FORUM_TITLE,900,250) + .changeActivityTitle("Forum", forumTitle); + + // Assert new forum activity title + // Now get all the activity titles + List allActivityTitles = fla.getAllActivityNames(); + + // Assert that all of them are in the design + + Assert.assertTrue(allActivityTitles.contains(forumTitle), + "The title " + forumTitle + " was not found as an activity in the design"); + + forumAuthorPage = fla.openForumAuthoring(forumTitle); + + forumAuthorPage.openAdvancedTab().setAllowRichText(true); + + forumAuthorPage.save(); + + + // Assert rich text editor is set + + forumAuthorPage.reEdit(); + + boolean isAllowRichText = forumAuthorPage.openAdvancedTab().isAllowRichEditor(); + + Assert.assertTrue(isAllowRichText, "Option Allow rich text editor is not set"); + + forumAuthorPage.cancel(flaHandler); + } + + /** + * Add forum with limited character restrictions + */ + @Test(dependsOnMethods={"addForumRichText"}) + public void addForumMinMaxCharacters() { + + String forumTitle = "MinMax " + RANDOM_INT; + String minChar = "10"; + String maxChar = "100"; + + // Drop activities in canvas + fla.dragActivityToCanvasPosition(AuthorConstants.FORUM_TITLE,700,250) + .changeActivityTitle("Forum", forumTitle); + + // Assert new forum activity title + // Now get all the activity titles + List allActivityTitles = fla.getAllActivityNames(); + + // Assert that all of them are in the design + + Assert.assertTrue(allActivityTitles.contains(forumTitle), + "The title " + forumTitle + " was not found as an activity in the design"); + + forumAuthorPage = fla.openForumAuthoring(forumTitle); + + // Set minimum characters + forumAuthorPage.openAdvancedTab().setLimitedMinCharacters(true); + forumAuthorPage.openAdvancedTab().setMinCharacters(minChar); + + // set maximum characters + forumAuthorPage.openAdvancedTab().setLimitedMaxCharacters(true); + forumAuthorPage.openAdvancedTab().setMaxCharacters(maxChar); + + forumAuthorPage.save(); + + // Assert Min and max characters are set + + forumAuthorPage.reEdit(); + + // Assert min char limits + boolean isMinLimit = forumAuthorPage.openAdvancedTab().isLimitedMinCharacters(); + String minCharacters = forumAuthorPage.openAdvancedTab().getMinCharacters(); + + Assert.assertTrue(isMinLimit, "Option for minimum characters is not set"); + Assert.assertEquals(minCharacters, minChar, "Minimal characters are not set properly"); + + + // Assert max char limits + boolean isMaxLimit = forumAuthorPage.openAdvancedTab().isLimitedMaxCharacters(); + String maxCharacters = forumAuthorPage.openAdvancedTab().getMaxCharacters(); + + Assert.assertTrue(isMaxLimit, "Option for minimum characters is not set"); + Assert.assertEquals(maxCharacters, maxChar, "Minimal characters are not set properly"); + + forumAuthorPage.cancel(flaHandler); + } + + + /** + * Add forum with notifications on postings for learners and teachers and on mark release + */ + @Test(dependsOnMethods={"addForumMinMaxCharacters"}) + public void addForumNotifications() { + + String forumTitle = "Notifications " + RANDOM_INT; + + // Drop activities in canvas + fla.dragActivityToCanvasPosition(AuthorConstants.FORUM_TITLE,500,250) + .changeActivityTitle("Forum", forumTitle); + + fla.drawTransitionBtwActivities(); + + // Assert new forum activity title + // Now get all the activity titles + List allActivityTitles = fla.getAllActivityNames(); + + // Assert that all of them are in the design + + Assert.assertTrue(allActivityTitles.contains(forumTitle), + "The title " + forumTitle + " was not found as an activity in the design"); + + forumAuthorPage = fla.openForumAuthoring(forumTitle); + + // Set notifications + forumAuthorPage.openAdvancedTab().setNotifyLearnersOnForumPosting(true); + forumAuthorPage.openAdvancedTab().setNotifyTeachersOnForumPosting(true); + forumAuthorPage.openAdvancedTab().setNotifyLearnersOnMarkRelease(true); + + forumAuthorPage.save(); + + // Assert Notifications + + forumAuthorPage.reEdit(); + + // Assert notifications + boolean learnerOnPosting = forumAuthorPage.openAdvancedTab().isNotifyLearnersOnForumPosting(); + boolean teacherOnPosting = forumAuthorPage.openAdvancedTab().isNotifyTeachersOnForumPosting(); + boolean learneronMark = forumAuthorPage.openAdvancedTab().isNotifyLearnersOnMarkRelease(); + + Assert.assertTrue(learnerOnPosting, "Option for learners notification on posting is not set"); + Assert.assertTrue(teacherOnPosting, "Option for teachers notification on posting is not set"); + Assert.assertTrue(learneronMark, "Option for learners notification on mark release is not set"); + + forumAuthorPage.cancel(flaHandler); + } + + + + + + @AfterClass + public void afterClass() { + //driver.quit(); + } + + + +}