Index: lams_tests/tests/org/lamsfoundation/lams/learner/util/LearnerConstants.java =================================================================== diff -u --- lams_tests/tests/org/lamsfoundation/lams/learner/util/LearnerConstants.java (revision 0) +++ lams_tests/tests/org/lamsfoundation/lams/learner/util/LearnerConstants.java (revision 628d0cc215b0e5530c583495db38ae4ae799d45b) @@ -0,0 +1,49 @@ +/**************************************************************** + * 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.learner.util; + +public class LearnerConstants { + + // Constants + + public static final String LEARNER_TITLE = "LAMS Learner"; + + + // SVG details + + /* + * In order to determine which activities we have completed/attempted/current/etc, + * we use the fill color of the icons. + */ + + public static final String LEARNER_SVG_COMPLETED_PATH_FILLCOLOR = "#000099"; + public static final String LEARNER_SVG_CURRENT_PATH_FILLCOLOR = "#bb0000"; + public static final String LEARNER_SVG_TODO_PATH_FILLCOLOR = "#bb0000"; + public static final String LEARNER_SVG_ATTEMPTED_PATH_FILLCOLOR = "#bb0000"; + + public static final String LEARNER_DEFAULT_TOPIC_SUBJECT = "Topic Heading"; + + + public static final String LEARNER_NEXT_ACTIVITY_ID = "finishButton"; + +} Index: lams_tests/tests/org/lamsfoundation/lams/pages/IndexPage.java =================================================================== diff -u -r5578f89837dd6596af003b0cb692a33fff0dedf2 -r628d0cc215b0e5530c583495db38ae4ae799d45b --- lams_tests/tests/org/lamsfoundation/lams/pages/IndexPage.java (.../IndexPage.java) (revision 5578f89837dd6596af003b0cb692a33fff0dedf2) +++ lams_tests/tests/org/lamsfoundation/lams/pages/IndexPage.java (.../IndexPage.java) (revision 628d0cc215b0e5530c583495db38ae4ae799d45b) @@ -28,6 +28,7 @@ import org.lamsfoundation.lams.pages.admin.CourseManagementPage; import org.lamsfoundation.lams.pages.author.FLAPage; +import org.lamsfoundation.lams.pages.learner.LearnerPage; import org.lamsfoundation.lams.pages.monitor.MonitorPage; import org.lamsfoundation.lams.pages.monitor.addlesson.AddLessonPage; import org.openqa.selenium.By; @@ -255,8 +256,18 @@ } - public void openLessonAsLearner() { + public LearnerPage openLessonAsLearner(String lessonName) { + WebElement lesson = getLessonRowByName(lessonName); + + WebElement lessonLink = lesson.findElement(By.tagName("a")); + + lessonLink.click(); + + driver.switchTo().window("lWindow"); + return PageFactory.initElements(driver, LearnerPage.class); + + } /** Index: lams_tests/tests/org/lamsfoundation/lams/pages/author/FLAPage.java =================================================================== diff -u -rc95566c68b524e29690da6cce1e5a0a72a4c2c6d -r628d0cc215b0e5530c583495db38ae4ae799d45b --- lams_tests/tests/org/lamsfoundation/lams/pages/author/FLAPage.java (.../FLAPage.java) (revision c95566c68b524e29690da6cce1e5a0a72a4c2c6d) +++ lams_tests/tests/org/lamsfoundation/lams/pages/author/FLAPage.java (.../FLAPage.java) (revision 628d0cc215b0e5530c583495db38ae4ae799d45b) @@ -30,7 +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.lamsfoundation.lams.pages.tool.forum.author.AuthorPage; import org.openqa.selenium.Alert; import org.openqa.selenium.By; import org.openqa.selenium.Point; @@ -1026,6 +1026,24 @@ } + /** + * Close FLA window + * + * Eventually we need to have a button to exit and then just press it from here + * + * Now we just switchTo + * + * @param indexHandler + */ + + public void close(String indexHandler) { + driver.switchTo().window(indexHandler); + + } + + + + /* Open specific tool authoring windows*/ @@ -1053,6 +1071,8 @@ } + + @@ -1076,7 +1096,6 @@ - /** * Returns the correct popup id * @@ -1322,5 +1341,4 @@ } - } Index: lams_tests/tests/org/lamsfoundation/lams/pages/monitor/addlesson/AddLessonPage.java =================================================================== diff -u -rdd6a6fcd79ef385c6d0eb01a15f5f6b24712c25a -r628d0cc215b0e5530c583495db38ae4ae799d45b --- lams_tests/tests/org/lamsfoundation/lams/pages/monitor/addlesson/AddLessonPage.java (.../AddLessonPage.java) (revision dd6a6fcd79ef385c6d0eb01a15f5f6b24712c25a) +++ lams_tests/tests/org/lamsfoundation/lams/pages/monitor/addlesson/AddLessonPage.java (.../AddLessonPage.java) (revision 628d0cc215b0e5530c583495db38ae4ae799d45b) @@ -22,6 +22,8 @@ package org.lamsfoundation.lams.pages.monitor.addlesson; +import java.util.List; + import org.lamsfoundation.lams.pages.AbstractPage; import org.lamsfoundation.lams.pages.IndexPage; import org.openqa.selenium.WebDriver; @@ -108,4 +110,34 @@ return PageFactory.initElements(driver, AdvancedTab.class); } + + public void createLessonByDesignName(String designName) { + + List designs = openLessontab().getFolderNodes("user"); + + WebElement selectedDesign = null; + + // now find the learning design for the forum + + for (WebElement design : designs) { + + //System.out.println(design.getTagName()); + if (design.getText().equals(designName)) { + selectedDesign = design; + + } + + } + + // Select design + openLessontab() + .clickDesign(selectedDesign) + .setLessonName(designName); + + // create the lesson + + addLessonNow(); + + } + } Index: lams_tests/tests/org/lamsfoundation/lams/pages/tool/forum/author/AdvancedTab.java =================================================================== diff -u --- lams_tests/tests/org/lamsfoundation/lams/pages/tool/forum/author/AdvancedTab.java (revision 0) +++ lams_tests/tests/org/lamsfoundation/lams/pages/tool/forum/author/AdvancedTab.java (revision 628d0cc215b0e5530c583495db38ae4ae799d45b) @@ -0,0 +1,423 @@ +/**************************************************************** + * 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.author; + +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.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.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 void setRelectOnActivity(Boolean value) { + + if(value && !reflectOnActivity.isSelected()) { + + reflectOnActivity.click(); + + } else if(reflectOnActivity.isSelected() && !value) { + + reflectOnActivity.click(); + + } + + } + + public boolean isReflectOnActivity() { + + return reflectOnActivity.isSelected(); + } + + public void setRelectionInstructions(String instructions) { + + reflectInstructions.clear(); + reflectInstructions.sendKeys(instructions); + + } + + public String getReflectionInstructions() { + + return reflectInstructions.getAttribute("value").trim(); + + } + + public boolean isLimitReplies() { + + List options = driver.findElements(By.name("forum.allowNewTopic")); + + if(options.get(1).isSelected()) { + return true; + } else { + return false; + } + + } + + public void setLimitReplies(String min, String max) { + + List options = driver.findElements(By.name("forum.allowNewTopic")); + + options.get(1).click(); + minimumReply.sendKeys(min); + maximumReply.sendKeys(max); + + } + + public String getMinReply() { + + return minimumReply.getAttribute("value").trim(); + } + + public String getMaxReply() { + + return maximumReply.getAttribute("value").trim(); + } + +} Index: lams_tests/tests/org/lamsfoundation/lams/pages/tool/forum/author/AuthorPage.java =================================================================== diff -u --- lams_tests/tests/org/lamsfoundation/lams/pages/tool/forum/author/AuthorPage.java (revision 0) +++ lams_tests/tests/org/lamsfoundation/lams/pages/tool/forum/author/AuthorPage.java (revision 628d0cc215b0e5530c583495db38ae4ae799d45b) @@ -0,0 +1,162 @@ +/**************************************************************** + * 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.author; + +import java.util.Iterator; +import java.util.Set; + +import org.lamsfoundation.lams.pages.AbstractPage; +import org.openqa.selenium.Alert; +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; + + @FindBy(className="warning") + private WebElement warning; + + 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; + } + + public String getWarningMsg(){ + + return warning.getText(); + } + + +} Index: lams_tests/tests/org/lamsfoundation/lams/pages/tool/forum/author/BasicTab.java =================================================================== diff -u --- lams_tests/tests/org/lamsfoundation/lams/pages/tool/forum/author/BasicTab.java (revision 0) +++ lams_tests/tests/org/lamsfoundation/lams/pages/tool/forum/author/BasicTab.java (revision 628d0cc215b0e5530c583495db38ae4ae799d45b) @@ -0,0 +1,164 @@ +/**************************************************************** + * 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.author; + +import org.lamsfoundation.lams.pages.AbstractPage; +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 setTitle(String title) { + + forumTitle.click(); + forumTitle.clear(); + forumTitle.sendKeys(title); + + } + + public void setInstructions(String instructions) { + + // Insert text to CKEditor via javascript + ((JavascriptExecutor) + driver).executeScript("CKEDITOR.instances['forum.instructions'].setData('" + instructions +"');"); + + } + + 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/learner/MessageForm.java =================================================================== diff -u --- lams_tests/tests/org/lamsfoundation/lams/pages/tool/forum/learner/MessageForm.java (revision 0) +++ lams_tests/tests/org/lamsfoundation/lams/pages/tool/forum/learner/MessageForm.java (revision 628d0cc215b0e5530c583495db38ae4ae799d45b) @@ -0,0 +1,186 @@ +/**************************************************************** + * 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.learner; + +import org.lamsfoundation.lams.LamsConstants; +import org.lamsfoundation.lams.pages.AbstractPage; +import org.lamsfoundation.lams.pages.tool.forum.util.ForumConstants; +import org.lamsfoundation.lams.pages.util.LamsPageUtil; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; + +public class MessageForm extends AbstractPage { + + @FindBy(name = "message.subject") + private WebElement messageSubject; + + @FindBy(id = "message.body__lamstextarea") + private WebElement messageBody; + + @FindBy(id = "cancelButton") + private WebElement cancelButton; + + @FindBy(id = "submitButton") + private WebElement submitButton; + + @FindBy(id = "char-left-div") + private WebElement charLeft; + + @FindBy(name = "attachmentFile") + private WebElement attachmentFile; + + @FindBy(id = "removeAttachmentButton") + private WebElement removeAttachmentButton; + + @FindBy(className = "info") + private WebElement infoWarning; + + @FindBy(id = "char-left-div") + private WebElement charactersLeft; + + @FindBy(id = "char-required-div") + private WebElement charactersRequired; + + public MessageForm(WebDriver driver) { + super(driver); + + } + + public void createTopicMessage(String subject, String body) { + + addSubject(subject); + + messageBody.click(); + messageBody.sendKeys(body); + + submitNewTopicMessage(); + + } + + public void submitNewTopicMessage() { + + submitButton.click(); + + } + + public void createTopicMessage(String body) { + + addBody(body); + + submitNewTopicMessage(); + } + + public void createTopicMessageCkEditor(String subject, String content) { + + if (subject != "") { + addSubject(subject); + } + + messageSubject.click(); + + LamsPageUtil.setCkEditorContent(driver, ForumConstants.FORUM_LEARNER_CKEDITOR_ID, content); + + submitButton.click(); + } + + + public void editTopicMessage(String subject, String body) { + + addSubject(subject); + addBody(body); + submitButton.click(); + + } + + private void addSubject(String subject) { + + messageSubject.click(); + messageSubject.clear(); + messageSubject.sendKeys(subject); + + } + + private void addBody(String body) { + + messageBody.click(); + messageBody.clear(); + messageBody.sendKeys(body); + + } + + + public void removeAttachment() { + + removeAttachmentButton.getAttribute("innerHTML"); + removeAttachmentButton.click(); + submitButton.click(); + + } + + + public String getTopicSubject() { + + return messageSubject.getAttribute("value").trim(); + } + + public String getTopicBody() { + + return messageBody.getAttribute("value").trim(); + } + + public String getCharLeft() { + + return charLeft.getText().trim(); + + } + + public void createTopicWithAttachment( String body, String attachment) { + + addBody(body); + + attachmentFile.sendKeys(LamsConstants.RESOURCES_PATH + attachment); + + submitNewTopicMessage(); + } + + public String getInfo() { + + return infoWarning.getText(); + + } + + public String getCharactersLeft() { + + return charactersLeft.getText(); + + } + + public String getCharacterRequired() { + + return charactersRequired.getText(); + + } + + +} Index: lams_tests/tests/org/lamsfoundation/lams/pages/tool/forum/learner/ReflectionPage.java =================================================================== diff -u --- lams_tests/tests/org/lamsfoundation/lams/pages/tool/forum/learner/ReflectionPage.java (revision 0) +++ lams_tests/tests/org/lamsfoundation/lams/pages/tool/forum/learner/ReflectionPage.java (revision 628d0cc215b0e5530c583495db38ae4ae799d45b) @@ -0,0 +1,58 @@ +/**************************************************************** + * 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.learner; + +import org.lamsfoundation.lams.pages.AbstractPage; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; + +public class ReflectionPage extends AbstractPage { + + @FindBy(name = "entryText") + private WebElement entryText; + + @FindBy(className = "nextActivity") + private WebElement nextActivity; + + public ReflectionPage(WebDriver driver) { + super(driver); + + } + + public void postReflection(String reflectionTxt) { + + entryText.click(); + entryText.clear(); + entryText.sendKeys(reflectionTxt); + + } + + public void nextActivity(String learnerHandler) { + + nextActivity.click(); + driver.switchTo().window(learnerHandler); + + } + +} Index: lams_tests/tests/org/lamsfoundation/lams/pages/tool/forum/learner/TopicIndexPage.java =================================================================== diff -u --- lams_tests/tests/org/lamsfoundation/lams/pages/tool/forum/learner/TopicIndexPage.java (revision 0) +++ lams_tests/tests/org/lamsfoundation/lams/pages/tool/forum/learner/TopicIndexPage.java (revision 628d0cc215b0e5530c583495db38ae4ae799d45b) @@ -0,0 +1,282 @@ +/**************************************************************** + * 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.learner; + +import java.util.List; + +import org.lamsfoundation.lams.learner.util.LearnerConstants; +import org.lamsfoundation.lams.pages.AbstractPage; +import org.lamsfoundation.lams.pages.learner.LearnerPage; +import org.lamsfoundation.lams.pages.util.LamsPageUtil; +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.FindBys; +import org.openqa.selenium.support.PageFactory; + +public class TopicIndexPage extends AbstractPage { + + /** + * Forum learner page attributes attributes + */ + + @FindBy(name = "newtopic") + private WebElement addTopicButton; + + @FindBy(id = "forumTitle") + private WebElement forumTitle; + + @FindBy(id = "forumInstructions") + private WebElement forumInstructions; + + @FindBy(className = "info") + private WebElement info; + + @FindBy(name = "refresh") + private WebElement refreshButton; + + @FindBy(id = "topicTable") + private WebElement topicTable; + + @FindBys({ + @FindBy(id = "topicTable"), + @FindBy(id = "topicTitle") + }) + private List allTopicTitles; + + @FindBy(id = "finishButton") + private WebElement finishButton; + + @FindBy(name = "continue") + private WebElement continueButton; + + // This is the div that contains the + // finish button + @FindBy(id = "rightButtons") + private WebElement rightButtons; + + @FindBy(id = "reflection") + private WebElement reflection; + + @FindBy(id = "editReflection") + private WebElement editReflectionButton; + + @FindBy(className = "warning") + private WebElement warningMessage; + + + public TopicIndexPage(WebDriver driver) { + super(driver); + + } + + public void refresh() { + refreshButton.click(); + } + + public MessageForm createTopic() { + + addTopicButton.click(); + + return PageFactory.initElements(driver, MessageForm.class); + + } + + public TopicViewPage openTopicBySubject(String subject) { + + List topics = getTopics(); + + WebElement topicLink = null; + + for (WebElement topic : topics) { + String title = topic.getText().trim(); + + if(title.equals(subject.trim())) { + topicLink = topic; + } + + } + + topicLink.click(); + + return PageFactory.initElements(driver, TopicViewPage.class); + } + + public List getTopics() { + + return allTopicTitles; + + } + + public boolean topicExistBySubject(String subject) { + + boolean exists = false; + + for (WebElement title : allTopicTitles) { + + String isTitle = title.getText(); + + if (isTitle.equals(subject)) { + exists = true; + break; + } + + } + + + return exists; + } + + public String getNumberOfRepliesBySubject(String title) { + + int row = getRowForSubject(title); + row++; + String replies = topicTable.findElement(By.xpath("//tbody/tr[" + row + "]/td[3]")).getText(); + + return replies; + } + + public String getNumberOfNewMsgsBySubject(String title) { + + int row = getRowForSubject(title); + row++; + String newMsgs = topicTable.findElement(By.xpath("//tbody/tr[" + row + "]/td[4]")).getText(); + + return newMsgs; + + } + + /** + * Continues to the next activity in the lesson + * + * Use this to continue to the next activity + */ + public void nextActivity() { + + finishButton.click(); + + } + + /** + * Continues to the next activity or closes pop-up window + * + * Use this for when you have opened a previous activity in a popup + * + * @param windowHandler + */ + public void nextActivity(String windowHandler) { + + finishButton.click(); + driver.switchTo().window(windowHandler); + + } + + public String getForumTitle() { + + return forumTitle.getText(); + + } + + + public String getForumInstructions() { + + return forumInstructions.getText(); + + } + + + + + public LearnerPage returnLearnerHandler(String learnerHandler) { + + driver.switchTo().window(learnerHandler); + + return PageFactory.initElements(driver, LearnerPage.class); + } + + public boolean isNewTopicEnabled() { + + return addTopicButton.isEnabled(); + + } + + public String getInfoWarning() { + + return info.getText(); + + } + + public boolean isNextActivityButtonPresent() { + + rightButtons.getAttribute("innerHTML"); + return LamsPageUtil.isElementPresentById(driver, rightButtons, LearnerConstants.LEARNER_NEXT_ACTIVITY_ID); + + } + + + private int getRowForSubject(String subject) { + + int counter = 0; + for (WebElement title : allTopicTitles) { + + counter++; + String isTitle = title.getText().trim(); + + if (isTitle.equals(subject)) { + + break; + } + } + + return counter; + + } + + public ReflectionPage clickContinue() { + + continueButton.click(); + + return PageFactory.initElements(driver, ReflectionPage.class); + } + + public String getReflection() { + + return reflection.getText(); + + } + + public ReflectionPage editReflection() { + + editReflectionButton.click(); + + return PageFactory.initElements(driver, ReflectionPage.class); + + } + + public String getRepliesLimitWarning() { + + return warningMessage.getText(); + } + +} Index: lams_tests/tests/org/lamsfoundation/lams/pages/tool/forum/learner/TopicViewPage.java =================================================================== diff -u --- lams_tests/tests/org/lamsfoundation/lams/pages/tool/forum/learner/TopicViewPage.java (revision 0) +++ lams_tests/tests/org/lamsfoundation/lams/pages/tool/forum/learner/TopicViewPage.java (revision 628d0cc215b0e5530c583495db38ae4ae799d45b) @@ -0,0 +1,261 @@ +/**************************************************************** + * 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.learner; + +import java.util.ArrayList; +import java.util.List; + +import org.lamsfoundation.lams.pages.tool.forum.util.ForumConstants; +import org.lamsfoundation.lams.pages.util.LamsPageUtil; +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.interactions.Actions; +import org.openqa.selenium.support.FindAll; +import org.openqa.selenium.support.FindBy; +import org.openqa.selenium.support.FindBys; +import org.openqa.selenium.support.PageFactory; + +public class TopicViewPage extends AbstractPage { + + @FindBy(name = "backToForum") + private WebElement backToForumButton; + + @FindBys({ + @FindBy(id = "message") + }) + private List allMessages; + + @FindBys({ + @FindBy(id = "message"), + @FindBy(id = "msgSubject") + }) + private List allMessageSubjects; + + @FindBys({ + @FindBy(id = "message"), + @FindBy(id = "person") + }) + private List allMessagePersons; + + @FindBys({ + @FindBy(id = "message"), + @FindBy(id = "msgDate") + }) + private List allMessageDate; + + @FindBys({ + @FindBy(id = "message"), + @FindBy(className = "rating-starts-caption") + }) + private List allRatingCaptions; + + @FindAll({ + @FindBy(id = "replyButton") + }) + private List allRepliableMessages; + + + public TopicViewPage(WebDriver driver) { + super(driver); + + } + + + public TopicIndexPage goBackToTopics() { + + backToForumButton.click(); + + return PageFactory.initElements(driver, TopicIndexPage.class); + } + + + public List getAllMessages() { + + return allMessages; + + } + + public String getMsgBody(WebElement message) { + + return message.findElement(By.id("msgBody")).getText(); + + } + + public String getMsgBodyCkEditor(WebElement message) { + + return LamsPageUtil.getCkEditorContent(driver, ForumConstants.FORUM_LEARNER_CKEDITOR_ID); + + } + + public String getMsgAuthor(WebElement message) { + + return message.findElement(By.id("author")).getText().trim(); + + } + + public String getMsgDate(WebElement message) { + + return message.findElement(By.id("date")).getText().trim(); + } + + public String getMsgSubject(WebElement message) { + + return message.findElement(By.id("subject")).getText().trim(); + } + + public String getMsgAttachmentFilename(WebElement message) { + + return message.findElement(By.id("attachments")).getText().trim(); + } + + + public MessageForm clickReply(WebElement message) { + + message.findElement(By.id("replyButton")).click(); + + return PageFactory.initElements(driver, MessageForm.class); + } + + public void replyFirstMessage(String body) { + + List messages = getAllMessages(); + + clickReply(messages.get(0)).createTopicMessage(body); + + } + + public void replyToMessage(WebElement message, String body) { + + clickReply(message).createTopicMessage(body); + + } + + public void replyToMessageWithAttachment(WebElement message, String body, String attachment) { + + clickReply(message).createTopicWithAttachment(body, attachment); + //clickReply(message).submitNewTopicMessage(); + + } + + public MessageForm clickEdit(WebElement message) { + + message.findElement(By.id("editButton")).click(); + + return PageFactory.initElements(driver, MessageForm.class); + } + + + public boolean isReplyEnabled(WebElement message) { + + return LamsPageUtil.isElementPresentById(driver, message, "replyButton"); + + } + + public boolean isEditEnabled(WebElement message) { + + return LamsPageUtil.isElementPresentById(driver, message, "editButton"); + + } + + public boolean isRateable(WebElement message) { + + // if the message is rateable, then give it a rate + + return LamsPageUtil.isElementPresentByClassname(driver, message, "rating-stars-div"); + + } + + + + public void rateMessage(WebElement message, int rating) { + + if (isRateable(message)) { + + WebElement hoverItem = message.findElement(By.className("jStar")); + Actions clicker = new Actions(driver); + + int xOffset = 0; + switch(rating) { + case 0: xOffset = -57; + break; + case 1: xOffset = -28; + break; + case 2: xOffset = 0; + break; + case 3: xOffset = 28; + break; + case 4: xOffset = 57; + break; + } + + clicker.moveToElement(hoverItem).moveByOffset(xOffset, 0).click().perform(); + + + } + + } + + public List getRatedMessages() { + + String ratingText; + + List allRated = new ArrayList(); + for (WebElement webElement: allRatingCaptions) { + + ratingText = webElement.getText(); + + if (ratingText.contains("1 vote")){ + + allRated.add(webElement.getText()); + } + + } + + return allRated; + + } + + + public boolean isAttachementPresent(WebElement message) { + + return LamsPageUtil.isElementPresentById(driver, message, "attachments"); + + } + + + public void replyToMessageCkEditor(WebElement message, String content) { + + clickReply(message).createTopicMessageCkEditor("", content); + + } + + + public int getNumberOfRepliableMessages() { + + return allRepliableMessages.size(); + + } + +} Index: lams_tests/tests/org/lamsfoundation/lams/pages/tool/forum/util/ForumConstants.java =================================================================== diff -u -rf94b785243d076566d19f245c9ad906a92fd4dd3 -r628d0cc215b0e5530c583495db38ae4ae799d45b --- lams_tests/tests/org/lamsfoundation/lams/pages/tool/forum/util/ForumConstants.java (.../ForumConstants.java) (revision f94b785243d076566d19f245c9ad906a92fd4dd3) +++ lams_tests/tests/org/lamsfoundation/lams/pages/tool/forum/util/ForumConstants.java (.../ForumConstants.java) (revision 628d0cc215b0e5530c583495db38ae4ae799d45b) @@ -31,11 +31,15 @@ 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"; // Warning messages public static final String FORUM_WARNING_REPLY_LIMITS_TXT = "Please add at least 1 topic when"; // When no topic and reply limits are set + // Learner's textarea id for CkEditor + public static final String FORUM_LEARNER_CKEDITOR_ID = "message.body"; + public static final CharSequence FORUM_FORM_INFO_MIN_CHAR = "The minimum number of characters for your response is"; + public static final String FORUM_LEARNER_MIN_CHAR_WARNING = "characters more to proceed";; + } Index: lams_tests/tests/org/lamsfoundation/lams/pages/util/LamsPageUtil.java =================================================================== diff -u --- lams_tests/tests/org/lamsfoundation/lams/pages/util/LamsPageUtil.java (revision 0) +++ lams_tests/tests/org/lamsfoundation/lams/pages/util/LamsPageUtil.java (revision 628d0cc215b0e5530c583495db38ae4ae799d45b) @@ -0,0 +1,101 @@ +/**************************************************************** + * 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.util; + +import java.util.List; +import java.util.concurrent.TimeUnit; + +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.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; + +public class LamsPageUtil { + + + + public static boolean isElementPresentById(WebDriver driver,WebElement webElement, String elementId) { + + driver.manage().timeouts().implicitlyWait(0, TimeUnit.MILLISECONDS); + List isEnabled = webElement.findElements(By.id(elementId)); + driver.manage().timeouts().implicitlyWait(10000, TimeUnit.MILLISECONDS); + + return ((isEnabled.size() > 0) ? true : false); + + } + + public static boolean isElementPresentByClassname(WebDriver driver, WebElement webElement, String classname) { + + driver.manage().timeouts().implicitlyWait(0, TimeUnit.MILLISECONDS); + List isEnabled = webElement.findElements(By.className(classname)); + driver.manage().timeouts().implicitlyWait(10000, TimeUnit.MILLISECONDS); + + return ((isEnabled.size() > 0) ? true : false); + + } + + public static String getCkEditorContent(WebDriver driver, String ckEditorId) { + + String getText = (String) ((JavascriptExecutor) + driver).executeScript("return (CKEDITOR.instances['"+ ckEditorId + "'].getData());"); + + getText = getText.replaceAll("[\n\r]", ""); + return getText; + + } + + public static void setCkEditorContent(WebDriver driver, String ckEditorId, String content) { + + content = content.replace("'", "\\'"); + + // Insert text to CKEditor via javascript + ((JavascriptExecutor)driver).executeScript("CKEDITOR.instances['" + ckEditorId + "'].setData('" + content +"');"); + + + } + + /** + * Clicks OK on the alert javascript popup and returns text + * + * @return text from popup + */ + public static String getAlertText(WebDriver driver) { + + 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) { + //exception handling + } + return txt; + } + +} Index: lams_tests/tests/org/lamsfoundation/lams/tool/forum/AuthorTests.java =================================================================== diff -u -r1fa1b86dfba232b005e5f73814b30a5ee2548f9d -r628d0cc215b0e5530c583495db38ae4ae799d45b --- lams_tests/tests/org/lamsfoundation/lams/tool/forum/AuthorTests.java (.../AuthorTests.java) (revision 1fa1b86dfba232b005e5f73814b30a5ee2548f9d) +++ lams_tests/tests/org/lamsfoundation/lams/tool/forum/AuthorTests.java (.../AuthorTests.java) (revision 628d0cc215b0e5530c583495db38ae4ae799d45b) @@ -25,27 +25,36 @@ import java.util.List; import java.util.concurrent.TimeUnit; +import org.apache.commons.lang3.StringUtils; import org.lamsfoundation.lams.author.util.AuthorConstants; +import org.lamsfoundation.lams.learner.util.LearnerConstants; 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.learner.LearnerPage; +import org.lamsfoundation.lams.pages.monitor.addlesson.AddLessonPage; +import org.lamsfoundation.lams.pages.tool.forum.author.AdvancedTab; +import org.lamsfoundation.lams.pages.tool.forum.author.AuthorPage; +import org.lamsfoundation.lams.pages.tool.forum.author.BasicTab; +import org.lamsfoundation.lams.pages.tool.forum.learner.MessageForm; +import org.lamsfoundation.lams.pages.tool.forum.learner.ReflectionPage; +import org.lamsfoundation.lams.pages.tool.forum.learner.TopicIndexPage; +import org.lamsfoundation.lams.pages.tool.forum.learner.TopicViewPage; import org.lamsfoundation.lams.pages.tool.forum.util.ForumConstants; +import org.lamsfoundation.lams.pages.util.LamsPageUtil; 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; - /** * - * Authoring Forum tests + * Forum Authoring tests * * @author Ernie Ghiglione (ernieg@lamsfoundation.org) * @@ -60,11 +69,23 @@ private IndexPage index; private FLAPage fla; private AuthorPage forumAuthorPage; + + private AddLessonPage addLesson; + private LearnerPage learnerPage; + private TopicIndexPage topicsPage; + private TopicViewPage topicView; + public String indexHandler; public String flaHandler; + public String learnerHandler; WebDriver driver; + // Tests specifics + + private static final String lessonName = ForumConstants.FORUM_TITLE + " tests " + RANDOM_INT; + + @BeforeClass public void beforeClass() { driver = new FirefoxDriver(); @@ -74,6 +95,7 @@ index = PageFactory.initElements(driver, IndexPage.class); fla = PageFactory.initElements(driver, FLAPage.class); forumAuthorPage = PageFactory.initElements(driver, AuthorPage.class); + addLesson = PageFactory.initElements(driver, AddLessonPage.class); onLogin.navigateToLamsLogin().loginAs("test3", "test3"); } @@ -86,6 +108,7 @@ public void openFLA() { FLAPage fla = new FLAPage(driver); + indexHandler = driver.getWindowHandle(); fla = index.openFla(); flaHandler = driver.getWindowHandle(); fla.maximizeWindows(); @@ -204,7 +227,6 @@ String warningMsg = forumAuthorPage.getWarningMsg(); - System.out.println("Warning: " + warningMsg); Assert.assertTrue(warningMsg.contains(ForumConstants.FORUM_WARNING_REPLY_LIMITS_TXT)); // Cancel the changes so we don't need to rebuild the original content @@ -222,7 +244,7 @@ public void addTopic() { String msgTitle = "Topic# " + RANDOM_INT; - String msgBody = "" + RANDOM_INT + "" + "

" + ForumConstants.FORUM_BODY_TXT + "

" + ForumConstants.FORUM_BODY_TXT + "

"; + String msgBody = LamsUtil.randomParagraphCharLimit(1000) + RANDOM_INT;; BasicTab basicTab = forumAuthorPage.openBasicTab(); @@ -294,6 +316,15 @@ forumAuthorPage.save(); + + } + + /** + * Add forum with Locked when finished + */ + @Test(description="Add forum with Locked when finished", dependsOnMethods={"deleteTopic"}) + public void verifyForumLockedWhenFinished() { + // Assert locked when finished was saved forumAuthorPage.reEdit(); @@ -303,15 +334,17 @@ Assert.assertTrue(isLockedWhenFinshed, "Option locked when finished is not set"); forumAuthorPage.cancel(flaHandler); + } /** * Add forum with no re-edits allowed */ - @Test(description="Add forum with no re-edits allowed", dependsOnMethods={"addForumLockedWhenFinished"}) + @Test(description="Add forum with no re-edits allowed", dependsOnMethods={"verifyForumLockedWhenFinished"}) public void addForumEditNotAllowed() { String forumTitle = "NoEdit " + RANDOM_INT; + String instructionsHTML = "No Edit instructions"; // Drop activities in canvas fla.dragActivityToCanvasPosition(AuthorConstants.FORUM_TITLE, 500, 100) @@ -327,26 +360,58 @@ "The title " + forumTitle + " was not found as an activity in the design"); forumAuthorPage = fla.openForumAuthoring(forumTitle); + + forumAuthorPage.openBasicTab().setTitle(forumTitle); + forumAuthorPage.openBasicTab().setInstructions(instructionsHTML); + forumAuthorPage.openAdvancedTab().setAllowEdit(false); forumAuthorPage.save(); - // Assert edits are not allowed + + } + + /** + * Verify forum with no re-edits allowed. + */ + @Test(description="Verify forum with no re-edits allowed", dependsOnMethods={"addForumEditNotAllowed"}) + public void verifyForumEditNotAllowed() { + // testing data + String forumTitle = "NoEdit " + RANDOM_INT; + String instructionsHTML = "No Edit instructions"; + + // Open author again + forumAuthorPage.reEdit(); - + + + // Assert title and instructions + + String title = forumAuthorPage.openBasicTab().getTitle(); + // We use boolean to compare as CkEditor includes some
tags. + boolean isInstructions = forumAuthorPage.openBasicTab().getIntructions().contains(instructionsHTML); + + Assert.assertEquals(title, forumTitle, "Title isn't the same!"); + Assert.assertTrue(isInstructions, "Instructions don't match!"); + + + // Assert edits are not allowed + boolean isAllowEdit = forumAuthorPage.openAdvancedTab().isAllowEdit(); Assert.assertFalse(isAllowEdit, "Option Allow Edit is still set"); + forumAuthorPage.cancel(flaHandler); + } /** * Add forum with ratings */ - @Test(description="Add forum with ratings", dependsOnMethods={"addForumEditNotAllowed"}) + @Test(description="Add forum with ratings", dependsOnMethods={"verifyForumEditNotAllowed"}) public void addForumRatings() { String forumTitle = "Ratings " + RANDOM_INT; @@ -373,10 +438,20 @@ forumAuthorPage.openAdvancedTab().setMaximumRate(maximumRate); forumAuthorPage.save(); + forumAuthorPage.reEdit(); - // Assert rating is on and the min and max are set + + } + + /** + * Verify forum with ratings + */ + @Test(description="Verify forum with ratings", dependsOnMethods={"addForumRatings"}) + public void verifyForumRatings() { - forumAuthorPage.reEdit(); + // testing data + String minimumRate = "1"; + String maximumRate = "5"; boolean isAllowEdit = forumAuthorPage.openAdvancedTab().isAllowRateMessages(); String minRate = forumAuthorPage.openAdvancedTab().getMinimumRate(); @@ -392,14 +467,15 @@ /** * Add forum with allow uploads on */ - @Test(description="Add forum with allow uploads on", dependsOnMethods={"addForumRatings"}) + @Test(description="Add forum with allow uploads on", dependsOnMethods={"verifyForumRatings"}) public void addForumUploads() { String forumTitle = "Upload " + RANDOM_INT; // Drop activities in canvas + driver.switchTo().window(flaHandler); fla.dragActivityToCanvasPosition(AuthorConstants.FORUM_TITLE,900, 100) - .changeActivityTitle("Forum", forumTitle); + .changeActivityTitle("Forum", forumTitle); // Assert new forum activity title // Now get all the activity titles @@ -415,10 +491,17 @@ forumAuthorPage.openAdvancedTab().setAllowUpload(true); forumAuthorPage.save(); + forumAuthorPage.reEdit(); + + } + + /** + * Verify forum with allow uploads on + */ + @Test(description="Verify forum with allow uploads on", dependsOnMethods={"addForumUploads"}) + public void verifyForumUploads() { // Assert that uploads was set properly - - forumAuthorPage.reEdit(); boolean isAllowUpload = forumAuthorPage.openAdvancedTab().isAllowUpload(); @@ -432,7 +515,7 @@ /** * Add forum with Rich Text editor */ - @Test(description="Add forum with Rich Text editor", dependsOnMethods={"addForumUploads"}) + @Test(description="Add forum with Rich Text editor", dependsOnMethods={"verifyForumUploads"}) public void addForumRichText() { String forumTitle = "RichText " + RANDOM_INT; @@ -456,6 +539,13 @@ forumAuthorPage.save(); + } + + /** + * Verify forum with Rich Text editor + */ + @Test(description="Verify forum with Rich Text editor", dependsOnMethods={"addForumRichText"}) + public void verifyForumRichText() { // Assert rich text editor is set @@ -466,12 +556,14 @@ Assert.assertTrue(isAllowRichText, "Option Allow rich text editor is not set"); forumAuthorPage.cancel(flaHandler); + } + /** * Add forum with limited character restrictions */ - @Test(description="Add forum with limited character restrictions", dependsOnMethods={"addForumRichText"}) + @Test(description="Add forum with limited character restrictions", dependsOnMethods={"verifyForumRichText"}) public void addForumMinMaxCharacters() { String forumTitle = "MinMax " + RANDOM_INT; @@ -502,7 +594,18 @@ forumAuthorPage.openAdvancedTab().setMaxCharacters(maxChar); forumAuthorPage.save(); + } + + /** + * Verify forum with limited character restrictions + */ + @Test(description="Verify forum with limited character restrictions", dependsOnMethods={"addForumMinMaxCharacters"}) + public void verifyForumMinMaxCharacters() { + // testing data + String minChar = "10"; + String maxChar = "100"; + // Assert Min and max characters are set forumAuthorPage.reEdit(); @@ -523,14 +626,15 @@ 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(description="Add forum with notifications on postings for learners and teachers and on mark release", - dependsOnMethods={"addForumMinMaxCharacters"}) + dependsOnMethods={"verifyForumMinMaxCharacters"}) public void addForumNotifications() { String forumTitle = "Notifications " + RANDOM_INT; @@ -557,6 +661,16 @@ forumAuthorPage.save(); + } + + /** + * Verify forum with notifications on postings for learners and teachers and on mark release + */ + @Test(description="Verify forum with notifications on postings for learners and teachers and on mark release", + dependsOnMethods={"addForumNotifications"}) + public void verifyForumNotifications() { + + // Assert Notifications forumAuthorPage.reEdit(); @@ -571,14 +685,13 @@ Assert.assertTrue(learneronMark, "Option for learners notification on mark release is not set"); forumAuthorPage.cancel(flaHandler); - } + } - /** * Add forum with reflection */ - @Test(description="Add forum with reflection", dependsOnMethods={"addForumNotifications"}) + @Test(description="Add forum with reflection", dependsOnMethods={"verifyForumNotifications"}) public void addForumReflection() { String forumTitle = "Reflection " + RANDOM_INT; @@ -605,6 +718,19 @@ forumAuthorPage.save(); + + } + + + /** + * Verify forum with reflection + */ + @Test(description="Verify forum with reflection", dependsOnMethods={"verifyForumNotifications"}) + public void verifyForumReflection() { + + // test data + String reflectionTxt = "Reflect on..."; + // Assert Reflection forumAuthorPage.reEdit(); @@ -618,14 +744,13 @@ forumAuthorPage.cancel(flaHandler); - } + } - /** * Add forum with replies limitation */ @Test(description="Add forum with replies limitation", - dependsOnMethods={"addForumReflection"}) + dependsOnMethods={"verifyForumReflection"}) public void addForumLimitReplies() { String forumTitle = "LimReply " + RANDOM_INT; @@ -652,6 +777,22 @@ forumAuthorPage.save(); + + + + } + + /** + * Verify forum with replies limitation + */ + @Test(description="Verify forum with replies limitation", + dependsOnMethods={"verifyForumReflection"}) + public void verifyForumLimitReplies() { + + // test data + String minReply = "2"; + String maxReply = "5"; + // Assert limit replies forumAuthorPage.reEdit(); @@ -666,16 +807,15 @@ Assert.assertEquals(maximumReplies, maxReply, "Maximum replies don't match"); forumAuthorPage.cancel(flaHandler); - - - } + } + /** * Save design */ @Test(description="saves forum design", - dependsOnMethods={"addForumLimitReplies"}) + dependsOnMethods={"verifyForumLimitReplies"}) public void saveForumTestsDesigns() { String designName = ForumConstants.FORUM_TITLE + " tests " + RANDOM_INT; @@ -687,13 +827,1120 @@ boolean saveResult = result.contains(AuthorConstants.SAVE_SEQUENCE_SUCCESS_MSG); Assert.assertTrue(saveResult, "The designed was not saved or is incomplete"); + fla.closeWindow(); + fla.close(indexHandler); + } + /** + * Create lesson based on forum design + */ + @Test(description="Create lesson based on forum design", + dependsOnMethods={"saveForumTestsDesigns"}) + public void createForumLesson() { + + String designName = ForumConstants.FORUM_TITLE + " tests " + RANDOM_INT; + + final String addButton= "Add now"; + + AddLessonPage addLesson = new AddLessonPage(driver); + addLesson.maximizeWindows(); + addLesson = openDialog(index); + + String assertFrameOpen = addLesson.checkAddLessonButton(); + + Assert.assertEquals(assertFrameOpen, addButton, + "It doesn't seem that the add lesson UI has loaded properly"); + + // Get user's learning designs + + addLesson.createLessonByDesignName(designName); + // Assert that lesson was created + boolean wasLessonCreated = index.isLessonPresent(designName); + + Assert.assertTrue(wasLessonCreated, "Lesson " + designName + " was not found!"); + + } + + /** + * Jump into lesson as learner and verify number of activities + */ + @Test(description="Jump into lesson as learner and verify number of activities", + dependsOnMethods={"createForumLesson"}) + public void jumpAsLearner() { + + int numberOfActivities = 10; + + learnerPage = index.openLessonAsLearner(lessonName); + + learnerHandler = driver.getWindowHandle(); + + List svg = learnerPage.openControlFrame().getActivitiesNamesFromSVG(); + + // Assert activities in lesson (there should be ten) + Assert.assertEquals(svg.size(), numberOfActivities, "There number of activities in lesson is incorrect!"); + + } + + /** + * Jump into lesson as learner and verify basics + */ + @Test(description="Jump into lesson as learner", + dependsOnMethods={"jumpAsLearner"}) + public void verifyLearnerUI() { + + // Assert learner window name + + String windowName = index.getWindowTitle(); + + Assert.assertEquals(windowName, LearnerConstants.LEARNER_TITLE, "It doesn't seem that this UI is the LAMS learner interface"); + + + } + + /** + * Jump into lesson as learner and verify basics + */ + @Test(description="Jump into lesson as learner", + dependsOnMethods={"verifyLearnerUI"}) + public void verifyLessonName() { + + // Assert lesson name + //TODO Ensure that we add this when this is fixed. + // String actualLessonName = learnerPage.openControlFrame().getLessonName(); + //System.out.println(actualLessonName); + // Assert.assertEquals(actualLessonName, lessonName, "Lesson name is not as expected"); + + learnerPage.openControlFrame().closeLearnerPage(indexHandler); + + } + + /** + * Tests basic forum: Verify number of replies and new message on default subject + */ + @Test(description="Verify number of replies and new message on default subject", + dependsOnMethods={"verifyLessonName"}) + public void verifyNumberOfReplies() { + + String title = "Topic# " + RANDOM_INT; + + learnerPage = index.openLessonAsLearner(lessonName); + + learnerHandler = driver.getWindowHandle(); + + topicsPage = learnerPage.openContentFrame().openLearnerForum(); + + // Assert replies + String numberOfReplies = topicsPage.getNumberOfRepliesBySubject(title); + + Assert.assertEquals(numberOfReplies, "0", "There should be only zero replies yet"); + + // Assert new messages + String numberOfNewMsgs = topicsPage.getNumberOfNewMsgsBySubject(title); + + Assert.assertEquals(numberOfNewMsgs, "1", "There should be only 1 message!"); + + + } + + + /** + * Tests basic forum: Verify subject name and number of topics + */ + @Test(description="Verify subject name and number of topics", + dependsOnMethods={"verifyNumberOfReplies"}) + public void verifyNumberOfTopicsAndSubjectName() { + + int numberOfTopics = 1; + String title = "Topic# " + RANDOM_INT; + + // get the topic list + List topics = topicsPage.getTopics(); + + // get the text for the first topic subject + String topicSubject =topics.get(0).getText(); + + + // Assert number of topics + Assert.assertEquals(topics.size(), numberOfTopics, "We were expecting only 1 topic!"); + + // Assert subject name + Assert.assertEquals(topicSubject, title, "The message subjets don't match!"); + + + } + + /** + * Tests basic forum: Verify number of messages + */ + @Test(description="Verify number of messages", + dependsOnMethods={"verifyNumberOfTopicsAndSubjectName"}) + public void verifyNumberOfMessages() { + + int numberOfMessages = 1; + String title = "Topic# " + RANDOM_INT; + + // Now open topic and verify text + + topicView = topicsPage.openTopicBySubject(title); + + List messages = topicView.getAllMessages(); + + int messagesSize = messages.size(); + + // Assert messages size + Assert.assertEquals(messagesSize, numberOfMessages, "The number of messages don't match!"); + + + } + + /** + * Tests basic forum: Verify number of messages + */ + @Test(description="Verify number of messages", + dependsOnMethods={"verifyNumberOfMessages"}) + public void verifyDefaultMessageDetails() { + + String topicSubject = "Topic# " + RANDOM_INT; + String author = "Three Test"; + + List messages = topicView.getAllMessages(); + + // Get msg subject + + String msgSubject = topicView.getMsgSubject(messages.get(0)); + + // Assert subject + + Assert.assertEquals(msgSubject, topicSubject, "Message subjects don't match!"); + + + // Get msg author + + String msgAuthor = topicView.getMsgAuthor(messages.get(0)); + + // Assert author + + Assert.assertEquals(msgAuthor, author, "Author is not the same!"); + + + // Get msg body + + String msgBody = topicView.getMsgBody(messages.get(0)); + + // Assert that msg body contains random int + + boolean containsRandomInt = msgBody.contains(RANDOM_INT); + + Assert.assertTrue(containsRandomInt, "Message doesn't match!"); + + } + + + /** + * Create new topic and verify that it shows accordingly + */ + @Test(description="Create new topic", + dependsOnMethods={"verifyDefaultMessageDetails"}) + public void createNewTopic() { + + String newTopic = "Shijo topic# " + RANDOM_INT; + String newBody = LamsUtil.randomParagraphCharLimit(1500); + topicView.goBackToTopics(); + + topicsPage.createTopic() + .createTopicMessage(newTopic, newBody); + + int topicCount = topicsPage.getTopics().size(); + + boolean topicExists = topicsPage.topicExistBySubject(newTopic); + + // Assert topic count + Assert.assertEquals(topicCount, 2, "Expected two topics!"); + + // Assert if topic exists + Assert.assertTrue(topicExists, "The new topic was not created!"); + + } + + /** + * Reply to the topic we just created and verify it. + */ + @Test(description="Reply to the topic we just created and verify it", + dependsOnMethods={"createNewTopic"}) + public void replyToMessage() { + + String title = "Shijo topic# " + RANDOM_INT; + String newSubject = "Reply# " + RANDOM_INT; + String newBody = LamsUtil.randomParagraphCharLimit(2000); + + topicView = topicsPage.openTopicBySubject(title); + + List messages = topicView.getAllMessages(); + topicView.clickReply(messages.get(0)) + .createTopicMessage(newSubject, newBody); + + // Assert that the reply has worked + + messages = topicView.getAllMessages(); + + // Assert that there's two messages now + + int numberOfMessages = messages.size(); + + Assert.assertEquals(numberOfMessages, 2, "We expected two messages now!"); + + // Assert that message 2 has the correct title and body + + String newMsgTitle = topicView.getMsgSubject(messages.get(1)); + String newMsgBody = topicView.getMsgBody(messages.get(1)); + + Assert.assertEquals(newMsgTitle, newSubject, "Message subjects don't match!"); + Assert.assertEquals(newMsgBody, newBody, "Body messages don't match"); + + topicsPage = topicView.goBackToTopics(); + + String numberOfReplies = topicsPage.getNumberOfRepliesBySubject(title); + + // Assert number of Replies + Assert.assertEquals(numberOfReplies, "1", "It should have 1 reply!"); + + } + + /** + * Reply with 5000 max char. + */ + @Test(description="Reply to a message", + dependsOnMethods={"replyToMessage"}) + public void maxCharPost() { + + String title = "Topic# " + RANDOM_INT; + + String txt = LamsUtil.randomText(25); + txt = txt.substring(0, 4999) + "."; + + topicsPage.openTopicBySubject(title); + + List messages = topicView.getAllMessages(); + topicView.clickReply(messages.get(0)).createTopicMessage(txt); + + // Assert that the reply has worked + + messages = topicView.getAllMessages(); + + // Assert that there's two messages now + + int numberOfMessages = messages.size(); + + Assert.assertEquals(numberOfMessages, 2, "We expected two messages now!"); + + // Assert that message 2 has the correct title and body + + String newMsgBody = topicView.getMsgBody(messages.get(1)); + + int txtLength = txt.length(); + int newMsgBodyLength = newMsgBody.length(); + + Assert.assertEquals(newMsgBodyLength, txtLength, "Number of chars don't match"); + + + } + + + /** + * Edit existing message + */ + @Test(description="Edit existing message", + dependsOnMethods={"maxCharPost"}) + public void editMessage() { + + String msgTitle = "New edit reply..."; + String msgBody = LamsUtil.randomText(6); + + + List messages = topicView.getAllMessages(); + + topicView.clickEdit(messages.get(1)).editTopicMessage(msgTitle, msgBody); + + messages = topicView.getAllMessages(); + + // Assert that there's two messages now + + int numberOfMessages = messages.size(); + + Assert.assertEquals(numberOfMessages, 2, "We expected two messages now!"); + + // Assert that message 2 has the correct title and body + + String newMsgBody = topicView.getMsgBody(messages.get(1)); + + Assert.assertEquals(newMsgBody, newMsgBody, "Number of chars don't match"); + + topicsPage = topicView.goBackToTopics(); + + topicsPage.nextActivity(); + } + + /** + * Verify Locked when finished (LWF): verify initial info message + * + */ + @Test(description="Locked when finished (LWF): verify initial info message", + dependsOnMethods={"editMessage"}) + public void verifyLwfInfoMessage() { + + String initialInfoWarning = "you won't be able to continue posting"; + + String warning = topicsPage.getInfoWarning(); + + // Assert that when entering a locked when finished forum + // the warning is displayed + + boolean isLockedWarning = warning.contains(initialInfoWarning); + + Assert.assertTrue(isLockedWarning, "No warning is displayed"); + + } + + /** + * Verify Locked when finished (LWF): create a topic and verify it was added + * + */ + @Test(description="LWF: create a topic and verify it was added", + dependsOnMethods={"verifyLwfInfoMessage"}) + public void verifyLwfCreateTopic() { + + String subject = "LWF " + RANDOM_INT; + String body = LamsUtil.randomText(6); + + topicsPage.createTopic().createTopicMessage(subject, body); + + // Assert that the topic was added + boolean topicExists = topicsPage.topicExistBySubject(subject); + Assert.assertTrue(topicExists, "The topic was not added!"); + + topicsPage.nextActivity(); + + } + + /** + * Verify Locked when finished (LWF): verify activity is completed + * + */ + @Test(description="LWF: verify activity is completed", + dependsOnMethods={"verifyLwfCreateTopic"}) + public void verifyLwfCompletion() { + + // this is just to wait for the next activity to load properly + topicsPage.getForumTitle(); + + // Close learner page + learnerPage = topicsPage.returnLearnerHandler(learnerHandler); + learnerPage.openControlFrame().closeLearnerPage(indexHandler); + + // Reopen learner + learnerPage = index.openLessonAsLearner(lessonName); + learnerHandler = driver.getWindowHandle(); + + // Assert now two completed activities + int completedActivities = 2; + int numberOfCompletedActivities = learnerPage.openControlFrame().getCompletedActivities().size(); + + Assert.assertEquals(numberOfCompletedActivities, completedActivities, "The number of completed activities isn't correct"); + + + } + + /** + * Verify Locked when finished (LWF): verify that a learners cannot post when + * revisiting the activity + * + */ + @Test(description="LWF: verify that a learners cannot post when revisiting the activity", + dependsOnMethods={"verifyLwfCompletion"}) + public void verifyLwfReEntry() { + + String subject = "LWF " + RANDOM_INT; + String onComeBackInfoWarning = "As you are returning to this Forum again"; + + topicsPage = learnerPage.openControlFrame().openPreviouslyCompletedActivity(); + + // Assert if the warning message is display when returning to the activity + String warning = topicsPage.getInfoWarning(); + + boolean isLockedWarning = warning.contains(onComeBackInfoWarning); + + Assert.assertTrue(isLockedWarning, "The warning message is not being displayed"); + + // Assert whether if new topics can be added + boolean isNewTopicEnabled = topicsPage.isNewTopicEnabled(); + + Assert.assertFalse(isNewTopicEnabled, "New topics should not be allowed!"); + + topicView = topicsPage.openTopicBySubject(subject); + + List allMessages = topicView.getAllMessages(); + + // Assert if the reply and edit button exist + boolean isReplyEnabled = topicView.isReplyEnabled(allMessages.get(0)); + boolean isEditEnabled = topicView.isEditEnabled(allMessages.get(0)); + + Assert.assertFalse(isReplyEnabled, "The reply button is showing!"); + Assert.assertFalse(isEditEnabled, "The edit button is showing!"); + + // Go back to topics + topicView.goBackToTopics(); + + // Close the pop-up window + topicsPage.nextActivity(learnerHandler); + + } + + + /** + * Checks that no edits activity has exact authored values. + * + */ + @Test(description="Checked that after submit a postings cannot be re-edited", + dependsOnMethods={"verifyLwfReEntry"}) + public void verifyNoEditsDefaults() { + + String forumTitle = "NoEdit " + RANDOM_INT; + String instructionsHTML = "No Edit instructions"; + + + topicsPage = learnerPage.openContentFrame().openLearnerForum(); + + // Assert title and instructions + String title = topicsPage.getForumTitle(); + String instructions = topicsPage.getForumInstructions(); + + boolean isInstructions = instructionsHTML.contains(instructions); + + Assert.assertEquals(title, forumTitle, "Titles don't match!"); + Assert.assertTrue(isInstructions, "Instructions don't match"); + + + } + + + /** + * Checks that after submit a postings cannot be re-edited + * + */ + @Test(description="Checks that after submit a postings cannot be re-edited", + dependsOnMethods={"verifyNoEditsDefaults"}) + public void verifyNoEdits() { + + String replyBody = LamsUtil.randomText(2); + + topicView = topicsPage.openTopicBySubject(LearnerConstants.LEARNER_DEFAULT_TOPIC_SUBJECT); + + topicView.replyFirstMessage(replyBody); + + List allMessages = topicView.getAllMessages(); + + boolean isEditEnabled = topicView.isEditEnabled(allMessages.get(1)); + + Assert.assertFalse(isEditEnabled, "Edit is enabled when it shouldn't!"); + + topicsPage = topicView.goBackToTopics();; + topicsPage.nextActivity(learnerHandler); + + } + + + /** + * Ratings: + * + * Checks that specific info warnings are displayed to tell learners of the ratings + * requirements + * + */ + + @Test(description="Checks that specific info warnings are displayed to tell learners of the ratings", + dependsOnMethods={"verifyNoEdits"}) + public void verifyRatingsInfoWarnings() { + + + String warningLimitTxt = "Rating limitation: minimum 1 and maximum 5"; + + topicsPage = learnerPage.openContentFrame().openLearnerForum(); + + String warning = topicsPage.getInfoWarning(); + + // Assert rating limitation warning + boolean isWarningCorrect = warning.contains(warningLimitTxt); + Assert.assertTrue(isWarningCorrect, "No rating limitation warning is displayed!"); + + // Assert that nextActivity button is not present + boolean isNextActivityButtonPresent = topicsPage.isNextActivityButtonPresent(); + Assert.assertFalse(isNextActivityButtonPresent, "The next activity button should not be present!"); + + } + + /** + * Ratings: + * + * Posts 5 messages as original user so they can be rated by next user. + * + */ + + @Test(description="Posts 5 messages as original user so they can be rated by next user.", + dependsOnMethods={"verifyRatingsInfoWarnings"}) + public void verifyRatingsPostMessages1() { + + topicsPage.openTopicBySubject(LearnerConstants.LEARNER_DEFAULT_TOPIC_SUBJECT); + + for (int i = 0; i < 5; i++) { + topicView.replyFirstMessage(LamsUtil.randomText(i + 1)); + } + + // Now assert number of messages + List allMessages = topicView.getAllMessages(); + + Assert.assertEquals(allMessages.size(), 6, "There should be 6 messages at this stage!"); + + topicView.goBackToTopics(); + + // Assert number of replies in the forum page + String replies = topicsPage.getNumberOfRepliesBySubject(LearnerConstants.LEARNER_DEFAULT_TOPIC_SUBJECT); + + Assert.assertEquals(replies, "5", "There should be 5 replies!"); + + } + + /** + * Ratings: + * + * Posts 5 messages as the other user + * + */ + + @Test(description="Posts 5 messages as the other user", + dependsOnMethods={"verifyRatingsPostMessages1"}) + public void verifyRatingsPostMessages2() { + + String warningLimitTxt = "Rating limitation: minimum 1 and maximum 5"; + + // Now logout and login as a new user + topicsPage.closeWindow(); + driver.switchTo().window(indexHandler); + index.logOut(); + onLogin.navigateToLamsLogin().loginAs("test2", "test2"); + + learnerPage = index.openLessonAsLearner(lessonName); + learnerHandler = driver.getWindowHandle(); + + topicsPage = learnerPage.openContentFrame().openLearnerForum(); + + // Skip to the rating activity + topicsPage.nextActivity(); + topicsPage.nextActivity(); + topicsPage.nextActivity(); + + String warning = topicsPage.getInfoWarning(); + + // Assert rating limitation warning + boolean isWarningCorrect = warning.contains(warningLimitTxt); + Assert.assertTrue(isWarningCorrect, "No rating limitation warning is displayed!"); + + topicView = topicsPage.openTopicBySubject(LearnerConstants.LEARNER_DEFAULT_TOPIC_SUBJECT); + + // Post 5 messages + for (int i = 0; i < 5; i++) { + topicView.replyFirstMessage(LamsUtil.randomText(i+1)); + } + + List allMessages = topicView.getAllMessages(); + + // Now rate all the messages we can rate + for (WebElement message : allMessages) { + int random = Integer.parseInt(LamsUtil.randInt(0, 5)); + topicView.rateMessage(message, random); + + } + + topicView.goBackToTopics(); + + // Assert that nextActivity button is present + boolean isNextActivityButtonPresent = topicsPage.isNextActivityButtonPresent(); + Assert.assertTrue(isNextActivityButtonPresent, "The next activity button should be present!"); + + + // Assert number of rated messages + warning = topicsPage.getInfoWarning(); + boolean isWarning = warning.contains("You have rated 5"); + Assert.assertTrue(isWarning, "It doesn't seem that we have rated 5 messages!"); + + + } + + /** + * Ratings: + * + * Rate posting from other user as original user. + * + */ + + @Test(description="Rate posting from other user as original user.", + dependsOnMethods={"verifyRatingsPostMessages1"}) + public void verifyRatingsRateAsOriginalUser() { + + String warningLimitTxt = "Rating limitation: minimum 1 and maximum 5"; + + topicsPage.closeWindow(); + + // Switch to our original user + driver.switchTo().window(indexHandler); + index.logOut(); + onLogin.navigateToLamsLogin().loginAs("test3", "test3"); + + learnerPage = index.openLessonAsLearner(lessonName); + learnerHandler = driver.getWindowHandle(); + + topicsPage = learnerPage.openContentFrame().openLearnerForum(); + + String warning = topicsPage.getInfoWarning(); + + // Assert rating limitation warning + boolean isWarningCorrect = warning.contains(warningLimitTxt); + Assert.assertTrue(isWarningCorrect, "No rating limitation warning is displayed!"); + + // Assert that nextActivity button is not present + boolean isNextActivityButtonPresent = topicsPage.isNextActivityButtonPresent(); + Assert.assertFalse(isNextActivityButtonPresent, "The next activity button should not be present!"); + + topicView = topicsPage.openTopicBySubject(LearnerConstants.LEARNER_DEFAULT_TOPIC_SUBJECT); + + List allMessages = topicView.getAllMessages(); + + for (WebElement message : allMessages) { + + int random = Integer.parseInt(LamsUtil.randInt(0, 5)); + topicView.rateMessage(message, random); + + } + + topicView.goBackToTopics(); + + + // Assert that nextActivity button is present + isNextActivityButtonPresent = topicsPage.isNextActivityButtonPresent(); + Assert.assertTrue(isNextActivityButtonPresent, "The next activity button should be present!"); + + // Assert number of rated messages + warning = topicsPage.getInfoWarning(); + boolean isWarning = warning.contains("You have rated 5"); + Assert.assertTrue(isWarning, "It doesn't seem that we have rated 5 messages!"); + + topicsPage.nextActivity(); + + } + + /** + * Verify attachments + * + * Verifies that attachments can be added + * + */ + + @Test(description="Verifies that attachments can be added to postings", + dependsOnMethods={"verifyRatingsRateAsOriginalUser"}) + public void verifyUploads() { + + String filename = "Example1.zip"; + + String replyBody = LamsUtil.randomText(8); + + + topicView = topicsPage.openTopicBySubject(LearnerConstants.LEARNER_DEFAULT_TOPIC_SUBJECT); + + List allMessages = topicView.getAllMessages(); + + topicView.replyToMessageWithAttachment(allMessages.get(0), replyBody, filename); + + allMessages = topicView.getAllMessages(); + + // Assert that there are two messages now + + int messagesSize = allMessages.size(); + Assert.assertEquals(messagesSize, 2, "There should be two messages!"); + + // Verify that the attachment file was uploaded properly + + String uploadedFilename = topicView.getMsgAttachmentFilename(allMessages.get(1)); + + //Assert file name + Assert.assertEquals(uploadedFilename, filename, "The file name is different"); + + + } + + /** + * Delete attached file + * + * We add a new posting with an attachment and then delete the attachment + * + */ + + @Test(description="Test delete attachement feature", + dependsOnMethods={"verifyUploads"}) + public void verifyAttachmentDeletion() { + + String replyBody = LamsUtil.randomText(2); + String filename = "Example1.zip"; + + List allMessages = topicView.getAllMessages(); + + // This is for our previous addition + WebElement message = allMessages.get(1); + + topicView.replyToMessageWithAttachment(message, replyBody, filename); + + // refresh + allMessages = topicView.getAllMessages(); + + // Now we should have three messages + Assert.assertEquals(allMessages.size(), 3, "We should have three messages now!"); + + // Get the latest posting we've just did + message = allMessages.get(2); + + // Remove its attachment + topicView.clickEdit(message).removeAttachment(); + + // Now get it again: + allMessages = topicView.getAllMessages(); + + // Assert that there's three messages + + Assert.assertEquals(allMessages.size(), 3, "We should have three messages now!"); + + // Now get only the latest message + message = allMessages.get(2); + // get the innerHTML for this node + message.getAttribute("innerHTML"); + + boolean isAttachementPresent = topicView.isAttachementPresent(message); + + // Assert that the file has been removed + Assert.assertFalse(isAttachementPresent, "Attachment is still showing!"); + + topicView.goBackToTopics(); + topicsPage.nextActivity(learnerHandler); + } + + /** + * Verify CKEditor option for learners + * + * We test that we can reply to an existing message and create a new topic using + * the CkEditor + * + */ + + @Test(description="Test CkEditor in learner", + dependsOnMethods={"verifyAttachmentDeletion"}) + public void verifyRichTextEditor() { + + // Prepare testing data + String replyBody1 = LamsUtil.randomText(1); + String subject2 = StringUtils.capitalize(LamsUtil.randomString(15).toLowerCase()); + String replyBody2 = LamsUtil.randomParagraph(500); + + // Open topic + topicsPage = learnerPage.openContentFrame().openLearnerForum(); + topicView = topicsPage.openTopicBySubject(LearnerConstants.LEARNER_DEFAULT_TOPIC_SUBJECT); + + // Get all messages + List allMessages = topicView.getAllMessages(); + + // reply to the first message + WebElement message = allMessages.get(0); + topicView.replyToMessageCkEditor(message, replyBody1); + + // Assert text return + allMessages = topicView.getAllMessages(); + message = allMessages.get(1); + String returnedTxt = topicView.getMsgBody(message); + Assert.assertEquals(replyBody1, returnedTxt, "Body text is not the same!"); + + topicView.goBackToTopics(); + + // Create a topic using CkEditor for body + topicsPage.createTopic().createTopicMessageCkEditor(subject2, replyBody2); + + // Now open the new topic + topicView = topicsPage.openTopicBySubject(subject2); + allMessages = topicView.getAllMessages(); + + //Assert that the body text matches + String bodyMsg = topicView.getMsgBody(allMessages.get(0)); + Assert.assertEquals(replyBody2, bodyMsg); + + topicView.goBackToTopics(); + topicsPage.nextActivity(learnerHandler); + + + } + + /** + * Verify minimum and max on reply + * + * Verify that min and max are enforced on reply topic + * + */ + + @Test(description="Test CkEditor in learner", + dependsOnMethods={"verifyRichTextEditor"}) + public void verifyReplyMinMaxChars() { + + // Prepare testing data + String replyFiveCharacters = LamsUtil.randomString(5); + String replyFinal = LamsUtil.randomParagraphCharLimit(100); + String minChar = "10"; + String maxChar = "100"; + + // Open topic + topicsPage = learnerPage.openContentFrame().openLearnerForum(); + topicView = topicsPage.openTopicBySubject(LearnerConstants.LEARNER_DEFAULT_TOPIC_SUBJECT); + + // Get all messages + List allMessages = topicView.getAllMessages(); + MessageForm replyForm = topicView.clickReply(allMessages.get(0)); + + String infoWarning = replyForm.getInfo(); + + // Assert info warning + boolean isInWarning = infoWarning.contains(ForumConstants.FORUM_FORM_INFO_MIN_CHAR); + Assert.assertTrue(isInWarning, "Warning message for min char posting is incorrect!"); + + String charLeft = replyForm.getCharactersLeft(); + String charRequired = replyForm.getCharacterRequired(); + + // Assert character limitations + Assert.assertEquals(charLeft, maxChar, "Minimum characters is incorrect!"); + Assert.assertEquals(charRequired, minChar, "Maximum characters is incorrect!"); + replyForm.createTopicMessage(replyFiveCharacters); + String result = LamsPageUtil.getAlertText(driver); + + // Assert result popup + boolean isError = result.contains(ForumConstants.FORUM_LEARNER_MIN_CHAR_WARNING); + Assert.assertTrue(isError, "No error message displayed"); + + // Reply proper posting + replyForm.createTopicMessage(replyFinal); + + // Assert that message is only 100 characters + allMessages = topicView.getAllMessages(); + + int msgBody = topicView.getMsgBody(allMessages.get(1)).length(); + + Assert.assertEquals(Integer.toString(msgBody), maxChar, "The message body length is not correct"); + + topicView.goBackToTopics(); + + } + + + /** + * Verify minimum and max on create new topic + * + * Verify that min and max are enforced on new create topic + * + */ + + @Test(description="Verify that min and max are enforced on new create topic", + dependsOnMethods={"verifyReplyMinMaxChars"}) + public void verifyCreateMinMaxChars() { + + String subject = StringUtils.capitalize(LamsUtil.randomString(15).toLowerCase()); + String replyFiveCharacters = LamsUtil.randomString(5); + String replyFinal = LamsUtil.randomParagraphCharLimit(100); + String maxChar = "100"; + + MessageForm newForm = topicsPage.createTopic(); + + newForm.createTopicMessage(subject, replyFiveCharacters); + String result = LamsPageUtil.getAlertText(driver); + + // Assert result popup + boolean isError = result.contains(ForumConstants.FORUM_LEARNER_MIN_CHAR_WARNING); + Assert.assertTrue(isError, "No error message displayed"); + + newForm.createTopicMessage(replyFinal); + + topicView = topicsPage.openTopicBySubject(subject); + + // Assert that message is only 100 characters + List allMessages = topicView.getAllMessages(); + + int msgBody = topicView.getMsgBody(allMessages.get(0)).length(); + + Assert.assertEquals(Integer.toString(msgBody), maxChar, "The message body length is not correct"); + + topicView.goBackToTopics(); + topicsPage.nextActivity(learnerHandler); + + } + + + /** + * Verify notifications + * + * As we have no way to test email notifications we'll skip this test + * + */ + + @Test(description="Verify email notifications on learner events", + dependsOnMethods={"verifyCreateMinMaxChars"}) + public void verifyNotificationsOnLearnerEvents() { + + topicsPage = learnerPage.openContentFrame().openLearnerForum(); + topicsPage.nextActivity(learnerHandler); + } + + /** + * Verify reflections + * + * On activity completion, verify that reflection is presented + * + */ + + @Test(description="On activity completion, verify that reflection is presented", + dependsOnMethods={"verifyNotificationsOnLearnerEvents"}) + public void verifyReflection() { + + // Prepare testing data + String replyBody = LamsUtil.randomParagraph(15); + String reflectionTxt = LamsUtil.randomText(3); + String reflectionTxt2 = LamsUtil.randomText(2); + + // Open topic + topicsPage = learnerPage.openContentFrame().openLearnerForum(); + topicView = topicsPage.openTopicBySubject(LearnerConstants.LEARNER_DEFAULT_TOPIC_SUBJECT); + + // Add a reply + topicView.replyFirstMessage(replyBody); + + // Go back and continue to enter reflection + topicView.goBackToTopics(); + ReflectionPage reflection = topicsPage.clickContinue(); + + // Post reflection and go to next activity + reflection.postReflection(reflectionTxt); + reflection.nextActivity(learnerHandler); + + // Heads to the next activity and gets the Forum instructions + // this gives us just time as for some reason selenium is too fast + // for Firefox :-) + topicsPage = learnerPage.openContentFrame().openLearnerForum(); + topicsPage.getForumInstructions(); + + // Close learner page + learnerPage = topicsPage.returnLearnerHandler(learnerHandler); + learnerPage.openControlFrame().closeLearnerPage(indexHandler); + + // Reopen learner + learnerPage = index.openLessonAsLearner(lessonName); + learnerHandler = driver.getWindowHandle(); + + + topicsPage = learnerPage.openControlFrame().openPreviouslyCompletedActivity(); + + String verifyReflectionTxt = topicsPage.getReflection(); + + // Assert submitted reflection + + Assert.assertEquals(verifyReflectionTxt, reflectionTxt, "Reflections don't match!"); + + reflection = topicsPage.editReflection(); + + reflection.postReflection(reflectionTxt2); + reflection.nextActivity(learnerHandler); + + } + + /** + * Verify replies limits + * + * Verify that we need a minimal of two replies to continue + * + */ + + @Test(description="Verify that we need a minimal of two replies to continue", + dependsOnMethods={"verifyNotificationsOnLearnerEvents"}) + public void verifyRepliesLimits() { + + String infoMessage = "Posting limitations for this forum"; + String warningMinMessages = "You must contribute at least 2 posts in each topic before finish."; + + String body1 = LamsUtil.randomText(5); + + learnerPage = topicsPage.returnLearnerHandler(learnerHandler); + topicsPage = learnerPage.openContentFrame().openLearnerForum(); + + // Assert info message + String infoMsg = topicsPage.getInfoWarning(); + boolean isInfoCorrect = infoMsg.contains(infoMessage); + Assert.assertTrue(isInfoCorrect, "No info message displayed"); + + topicView = topicsPage.openTopicBySubject(LearnerConstants.LEARNER_DEFAULT_TOPIC_SUBJECT); + topicView.replyFirstMessage(body1); + topicView.goBackToTopics(); + topicsPage.refresh(); + + String newReplies = topicsPage.getNumberOfRepliesBySubject(LearnerConstants.LEARNER_DEFAULT_TOPIC_SUBJECT); + Assert.assertEquals(newReplies.toString(), "1", "No new reply exist!"); + + // Now try to submit + + topicsPage.nextActivity(); + + String warningMsg = topicsPage.getRepliesLimitWarning(); + // Assert warning message + Assert.assertEquals(warningMsg, warningMinMessages, "The warning message is not being shown!"); + + topicView = topicsPage.openTopicBySubject(LearnerConstants.LEARNER_DEFAULT_TOPIC_SUBJECT); + + // Post 4 more messages + for (int i = 1; i < 5; i++) { + topicView.replyFirstMessage(LamsUtil.randomText(i)); + } + + // Now check that all reply buttons are gone + //System.out.println("starts"); + int isRepliesOn = topicView.getNumberOfRepliableMessages(); + + + // Assert that you can't reply to messages anymore + Assert.assertEquals(isRepliesOn, 0, "There are reply options still available!"); + + topicView.goBackToTopics(); + topicsPage.nextActivity(); + + // Close learner page + learnerPage = topicsPage.returnLearnerHandler(learnerHandler); + learnerPage.openControlFrame().closeLearnerPage(indexHandler); + + + } + + + @AfterClass public void afterClass() { //driver.quit(); } + + private AddLessonPage openDialog(IndexPage index) { + addLesson = index.addLesson(); + + return addLesson; + } + + } Index: lams_tests/tests/org/lamsfoundation/lams/util/LamsUtil.java =================================================================== diff -u -rd92555293b36d01d50e1f83961e515a5b65aa18f -r628d0cc215b0e5530c583495db38ae4ae799d45b --- lams_tests/tests/org/lamsfoundation/lams/util/LamsUtil.java (.../LamsUtil.java) (revision d92555293b36d01d50e1f83961e515a5b65aa18f) +++ lams_tests/tests/org/lamsfoundation/lams/util/LamsUtil.java (.../LamsUtil.java) (revision 628d0cc215b0e5530c583495db38ae4ae799d45b) @@ -2,12 +2,15 @@ import java.util.Random; +import org.apache.commons.lang3.RandomStringUtils; +import org.apache.commons.lang3.StringUtils; import org.lamsfoundation.lams.LamsConstants; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; public class LamsUtil { - + + public static void loginAs(WebDriver driver, String username, String password) { // Get to login page @@ -39,4 +42,69 @@ return randomNumString; } + public static String randomString(int length) { + + return RandomStringUtils.randomAlphabetic(length); + + } + + public static String randomParagraph(int words) { + + String paragraph = ""; + + for (int i = 0; i < words; i++) { + + int wordLength = Integer.parseInt(randInt(1, 15)); + + String txtTmp = randomString(wordLength); + + paragraph += txtTmp.toLowerCase() + " "; + + } + + paragraph = StringUtils.capitalize(paragraph); + paragraph = paragraph.trim() + "."; + + return paragraph; + } + + public static String randomParagraphCharLimit(int charLimit) { + + String paragraph = ""; + int wordLength; + String txtTmp; + + for (int i = 0; i < (charLimit); i =+ paragraph.length()) { + wordLength = Integer.parseInt(randInt(1, 15)); + + txtTmp = randomString(wordLength); + + paragraph += txtTmp.toLowerCase() + " "; + } + + int minusOne = charLimit - 1; + paragraph = paragraph.substring(0, minusOne); + paragraph += "."; + + return paragraph; + + } + + public static String randomText(int paragraphs) { + + String text = ""; + + for (int i = 0; i < paragraphs; i++) { + + int wordsInParagraphs = Integer.parseInt(randInt(5, 80)); + + String paragraph = randomParagraph(wordsInParagraphs); + + text += paragraph + "\n\n"; + + } + + return text.trim(); + } + } \ No newline at end of file