Index: lams_tests/tests/org/lamsfoundation/lams/author/Author-tests.xml
===================================================================
diff -u
--- lams_tests/tests/org/lamsfoundation/lams/author/Author-tests.xml (revision 0)
+++ lams_tests/tests/org/lamsfoundation/lams/author/Author-tests.xml (revision 563e1a1b8dba97f3a3a172f6a85c7eb86363a721)
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
Index: lams_tests/tests/org/lamsfoundation/lams/author/AuthorErrorsTests.java
===================================================================
diff -u
--- lams_tests/tests/org/lamsfoundation/lams/author/AuthorErrorsTests.java (revision 0)
+++ lams_tests/tests/org/lamsfoundation/lams/author/AuthorErrorsTests.java (revision 563e1a1b8dba97f3a3a172f6a85c7eb86363a721)
@@ -0,0 +1,577 @@
+/****************************************************************
+ * 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.author;
+
+import java.util.concurrent.TimeUnit;
+
+import org.lamsfoundation.lams.author.util.AuthorConstants;
+import org.lamsfoundation.lams.pages.IndexPage;
+import org.lamsfoundation.lams.pages.LoginPage;
+import org.lamsfoundation.lams.pages.author.ConditionsPropertiesPage;
+import org.lamsfoundation.lams.pages.author.FLAPage;
+import org.lamsfoundation.lams.util.LamsUtil;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.firefox.FirefoxDriver;
+import org.openqa.selenium.support.PageFactory;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.AfterClass;
+
+/**
+ * LAMS Authoring common errors
+ *
+ * - attempt clear when unsaved design
+ * - Two transition going to the same activity
+ * - recursive transition act1 --> act2 --> act1 (LDEV-3354)
+ * - circular designs (LDEV-3355)
+ * - Overwrite warning
+ * - don't allow system activities in support and optional activities (LDEV-3356)
+ * - saving invalid designs:
+ * - no transition
+ * - no grouping assigned
+ * - no branches set
+ * - no set grouping branches
+ * - no set branching conditions
+ * - optional activities must have at least one act inside
+ * - support activities must have at least on act inside
+ * - no activity in design
+ *
+ *
+ * @author Ernie Ghiglione (ernieg@lamsfoundation.org)
+ *
+ */
+
+public class AuthorErrorsTests {
+
+
+ private static final String RANDOM_INT = LamsUtil.randInt(0, 9999);
+
+
+ private String randomDesignName = "Design-" + RANDOM_INT;
+
+ private LoginPage onLogin;
+ private IndexPage index;
+ private FLAPage fla;
+
+ WebDriver driver;
+
+ @BeforeClass
+ public void beforeClass() {
+ driver = new FirefoxDriver();
+ driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
+
+ onLogin = PageFactory.initElements(driver, LoginPage.class);
+ index = PageFactory.initElements(driver, IndexPage.class);
+ fla = PageFactory.initElements(driver, FLAPage.class);
+ onLogin.navigateToLamsLogin().loginAs("test3", "test3");
+
+ }
+
+ @AfterClass
+ public void afterClass() {
+ driver.quit();
+ }
+
+
+ /**
+ * Opens FLA interface
+ */
+ @Test
+ public void openFLA() {
+
+ FLAPage fla = new FLAPage(driver);
+ fla = index.openFla();
+ fla.maximizeWindows();
+ Assert.assertEquals(AuthorConstants.FLA_TITLE, fla.getTitle(),
+ "The expected title is not present");
+
+
+
+ }
+
+ /**
+ * Clears the canvas
+ */
+ @Test(dependsOnMethods={"openFLA"})
+ public void cleanCanvas() {
+ fla.newDesign().getAlertText();
+
+ // Check that the design titled is back to untitled
+ String newTitle = fla.getDesignName();
+ Assert.assertTrue(newTitle.equals("Untitled"),
+ "The canvas wasn't clean. Still shows: " + newTitle);
+
+ }
+
+ /**
+ * Attempt to clear the canvas when there's unsaved design.
+ */
+ @Test(dependsOnMethods={"cleanCanvas"})
+ public void attemptClearWhenUnsavedDesign() {
+
+ fla.dragActivityToCanvasPosition(AuthorConstants.ASSESSMENT_TITLE, 200, 250);
+ fla.dragActivityToCanvas(AuthorConstants.WIKI_TITLE);
+
+ String assertOutput = fla.newDesign().getAlertText();
+
+ // Assert error message
+ Assert.assertTrue(assertOutput.contains(AuthorConstants.CLEAR_ON_UNSAVED_DESIGN),
+ "No alert message before clearing the design without saving was displayed");
+
+ // Assert
+ String newTitle = fla.getDesignName();
+ Assert.assertTrue(newTitle.equals("Untitled"),
+ "There's an unexpected design title");
+
+ }
+
+ /**
+ * Attempt to clear the canvas when there's unsaved design.
+ */
+ @Test(dependsOnMethods={"attemptClearWhenUnsavedDesign"})
+ public void attemptActivitiesTransitionToEachOther() {
+
+ cleanCanvas();
+
+ fla.dragActivityToCanvasPosition(AuthorConstants.MINDMAP_TITLE, 200, 450);
+ fla.dragActivityToCanvas(AuthorConstants.MULTIPLE_CHOICE_TITLE);
+
+ fla.drawTransitionBtwActivities();
+
+ String alertTxt = fla.drawTransitionFromTo(AuthorConstants.MINDMAP_TITLE,
+ AuthorConstants.MULTIPLE_CHOICE_TITLE)
+ .getAlertText();
+
+ // Assert error message
+ Assert.assertTrue(alertTxt.contains(AuthorConstants.RECURSIVE_TRANSITION_MSG),
+ "Unexpected message when attempting to bow transitions");
+
+ }
+
+
+ /**
+ * Attempt to clear the canvas when there's unsaved design.
+ */
+ @Test(dependsOnMethods={"attemptActivitiesTransitionToEachOther"})
+ public void attemptCircularDesign() {
+
+
+ fla.dragActivityToCanvasPosition(AuthorConstants.ASSESSMENT_TITLE, 400, 450);
+
+ fla.drawTransitionFromTo(AuthorConstants.MULTIPLE_CHOICE_TITLE, AuthorConstants.ASSESSMENT_TITLE);
+
+ String alertTxt = fla.drawTransitionFromTo(AuthorConstants.ASSESSMENT_TITLE,
+ AuthorConstants.MINDMAP_TITLE)
+ .getAlertText();
+
+ // Assert error message
+ Assert.assertTrue(alertTxt.contains(AuthorConstants.CIRCULAR_DESIGN_MSG),
+ "Unexpected message when attempting to create a circular design");
+
+ }
+
+ /**
+ * Attempt to clear the canvas when there's unsaved design.
+ */
+ @Test(dependsOnMethods={"attemptCircularDesign"})
+ public void attemptOverwriteDesign() {
+
+ String alertTxt = fla.saveAsDesign(randomDesignName + "-overwrite");
+
+ // Assert initial save
+ Assert.assertTrue(alertTxt.contains(AuthorConstants.SAVE_SEQUENCE_SUCCESS_MSG),
+ "The saving result should have been valid. We've got: " + alertTxt);
+
+ alertTxt = fla.overWriteDesign(randomDesignName + "-overwrite");
+
+ // Assert error message
+ Assert.assertTrue(alertTxt.contains(AuthorConstants.SAVE_OVERWRITE_MSG),
+ "Unexpected message when attempting to overwrite a design");
+
+ }
+
+ /**
+ * Attempts to put a system gate into a support activity
+ *
+ * @see LDEV-3356
+ */
+ @Test(dependsOnMethods={"attemptOverwriteDesign"})
+ public void attemptSystemActivityInSupportActivities() {
+
+
+ cleanCanvas();
+ fla.dragOptionalActivityToCanvas();
+
+ // Try with Gate
+ fla.dragGateToCanvas();
+
+ String alertTxt = fla.dragActivityIntoOptionalActivity(AuthorConstants.OPTIONAL_ACTIVITY_TITLE,
+ AuthorConstants.GATE_TITLE).getAlertText();
+
+ Assert.assertTrue(alertTxt.contains(AuthorConstants.ADD_SYSTEM_ACT_TO_OPTIONAL_MSG),
+ "No error message thrown!");
+
+ // Try with Group
+ fla.dragGroupToCanvas();
+
+ alertTxt = fla.dragActivityIntoOptionalActivity(AuthorConstants.OPTIONAL_ACTIVITY_TITLE,
+ AuthorConstants.GROUP_TITLE).getAlertText();
+
+ Assert.assertTrue(alertTxt.contains(AuthorConstants.ADD_SYSTEM_ACT_TO_OPTIONAL_MSG),
+ "No error message thrown!");
+
+ // Try with branching
+ fla.dragBranchToCanvas();
+
+ alertTxt = fla.dragActivityIntoOptionalActivity(AuthorConstants.OPTIONAL_ACTIVITY_TITLE,
+ AuthorConstants.BRANCHING_START_TITLE).getAlertText();
+
+ Assert.assertTrue(alertTxt.contains(AuthorConstants.ADD_SYSTEM_ACT_TO_OPTIONAL_MSG),
+ "No error message thrown!");
+
+
+ }
+
+ /**
+ * Save invalid design: no transitions
+ *
+ * Attempts to save an design that has no transitions.
+ *
+ */
+ @Test(dependsOnMethods={"attemptSystemActivityInSupportActivities"})
+ public void attemptSaveNoTransitionsDesign() {
+
+ cleanCanvas();
+
+ fla.dragActivityToCanvasPosition(AuthorConstants.FORUM_TITLE, 200, 300);
+ fla.dragActivityToCanvas(AuthorConstants.IMAGE_GALLERY_TITLE);
+
+ String saveResult = fla.saveAsDesign(randomDesignName + RANDOM_INT + "-incompleteSave");
+
+ // Assert invalid design
+ Assert.assertTrue(saveResult.contains(AuthorConstants.SAVE_SEQUENCE_INVALID_MSG),
+ "The design should not be valid as it's missing transitions");
+
+ // Make the design valid and save
+ fla.arrangeDesign();
+ fla.drawTransitionBtwActivities();
+
+ // save
+ String saveOutput = saveDesign();
+
+ // Assert design is valid
+ Assert.assertTrue(saveOutput.contains(AuthorConstants.SAVE_SEQUENCE_SUCCESS_MSG),
+ "The design still shows as no valid");
+
+ }
+
+ /**
+ * Save invalid design: no assigned groups
+ *
+ * Attempts to save a design that has no groups assigned.
+ *
+ */
+ @Test(dependsOnMethods={"attemptSaveNoTransitionsDesign"})
+ public void attemptSaveNoGroupingAssigned() {
+
+ fla.dragGroupToCanvas();
+
+ fla.drawTransitionFromTo(AuthorConstants.GROUP_TITLE, AuthorConstants.FORUM_TITLE);
+
+ String saveResult = fla.saveDesign();
+
+ // Assert invalid design
+ Assert.assertTrue(saveResult.contains(AuthorConstants.SAVE_SEQUENCE_NO_GROUPS_ASSIGNED),
+ "The design should not be valid as it has unassigned groups");
+
+ // fix design
+ fla.setGroupForActivity(AuthorConstants.GROUP_TITLE, AuthorConstants.FORUM_TITLE);
+
+ // save
+ String saveOutput = saveDesign();
+
+ // Assert design is valid
+ Assert.assertTrue(saveOutput.contains(AuthorConstants.SAVE_SEQUENCE_SUCCESS_MSG),
+ "The design still shows as no valid");
+
+ }
+
+ /**
+ * Save invalid design: no branches set
+ *
+ * Attempts to save a design that has no branches created.
+ *
+ */
+ @Test(dependsOnMethods={"attemptSaveNoGroupingAssigned"})
+ public void attemptSaveNoBranchesSet() {
+
+ cleanCanvas();
+
+ fla.dragActivityToCanvasPosition(AuthorConstants.COMMON_CARTRIDGE_TITLE, 300, 150);
+ fla.dragBranchToCanvas();
+
+ fla.drawTransitionFromTo(AuthorConstants.COMMON_CARTRIDGE_TITLE, AuthorConstants.BRANCHING_START_TITLE);
+
+ String saveResult = fla.saveAsDesign(randomDesignName + "-noBranches" );
+
+ // Assert invalid design
+ Assert.assertTrue(saveResult.contains(AuthorConstants.BRANCHING_MUST_HAVE_AT_LEAST_MSG),
+ "The error message recieved was not what we expected." + saveResult);
+
+ // fix design
+ fla.drawTransitionFromTo(AuthorConstants.BRANCHING_START_TITLE, AuthorConstants.BRANCH_END_TITLE);
+
+ // save
+ String saveOutput = saveDesign();
+
+ // Assert design is valid
+ Assert.assertTrue(saveOutput.contains(AuthorConstants.SAVE_SEQUENCE_SUCCESS_MSG),
+ "The design still shows as no valid");
+
+ }
+
+ /**
+ * Save invalid design: no branches set
+ *
+ * Attempts to save a design that has no branches created.
+ *
+ */
+ @Test(dependsOnMethods={"attemptSaveNoBranchesSet"})
+ public void attemptSaveNoGroupBranchesSet() {
+
+ cleanCanvas();
+
+ fla.dragGroupToCanvas();
+ fla.dragBranchToCanvas();
+
+ fla.drawTransitionFromTo(AuthorConstants.GROUP_TITLE, AuthorConstants.BRANCHING_START_TITLE);
+ fla.drawTransitionFromTo(AuthorConstants.BRANCHING_START_TITLE, AuthorConstants.BRANCH_END_TITLE);
+
+ fla.branchingProperties(AuthorConstants.BRANCHING_TITLE)
+ .setBranchingType(BranchingTests.BRANCHING_TYPE_GROUP)
+ .setGroupInGroupBranchingType(AuthorConstants.GROUP_TITLE);
+
+ String saveResult = fla.saveAsDesign(randomDesignName + "-noGroupBranches" );
+
+ // Assert invalid design
+ Assert.assertTrue(saveResult.contains(AuthorConstants.BRANCHING_MUST_HAVE_GROUPS_TO_BRANCHES_MSG),
+ "The error message recieved was not what we expected." + saveResult);
+
+ // fix design.
+ fla.branchingProperties(AuthorConstants.BRANCHING_TITLE)
+ .clickMatchGroupsToBranches();
+
+ fla.branchingProperties(AuthorConstants.BRANCHING_TITLE)
+ .matchGroupToBranch("1", "1")
+ .matchGroupToBranch("1", "1");
+
+ fla.branchingProperties(AuthorConstants.BRANCHING_TITLE).clickOkGroupButton();
+
+ // save
+ String saveOutput = saveDesign();
+
+ // Assert design is valid
+ Assert.assertTrue(saveOutput.contains(AuthorConstants.SAVE_SEQUENCE_SUCCESS_MSG),
+ "The design still shows as no valid");
+
+ }
+
+
+ /**
+ * Save invalid design: no conditions set
+ *
+ * Attempts to save a design that has no conditions created.
+ *
+ */
+ @Test(dependsOnMethods={"attemptSaveNoGroupBranchesSet"})
+ public void attemptSaveNoConditionsBranchesSet() {
+
+ // Test data
+ String rangeValueZero = "0";
+ String rangeValueOne = "1";
+
+ String conditionZeroRange = "Zero condition";
+ String conditionOneRange = "One condition";
+
+ String branchOne = "Branch 1";
+ String branchTwo = "Branch 2";
+
+ cleanCanvas();
+
+ fla.dragActivityToCanvasPosition(AuthorConstants.MULTIPLE_CHOICE_TITLE, 250, -10);
+ fla.dragBranchToCanvas();
+
+ fla.drawTransitionFromTo(AuthorConstants.MULTIPLE_CHOICE_TITLE, AuthorConstants.BRANCHING_START_TITLE);
+ fla.drawTransitionFromTo(AuthorConstants.BRANCHING_START_TITLE, AuthorConstants.BRANCH_END_TITLE);
+
+ fla.branchingProperties(AuthorConstants.BRANCHING_TITLE)
+ .setBranchingType(BranchingTests.BRANCHING_TYPE_LEARNER_OUTPUT)
+ .setInputTool(AuthorConstants.MULTIPLE_CHOICE_TITLE);;
+
+ String saveResult = fla.saveAsDesign(randomDesignName + "-noConditionsBranches" );
+
+
+ // Assert invalid design
+ Assert.assertTrue(saveResult.contains(AuthorConstants.BRANCHING_MUST_HAVE_ONE_CONDITION_MSG),
+ "The error message recieved was not what we expected." + saveResult);
+
+ // fix design
+ fla.branchingProperties(AuthorConstants.BRANCHING_TITLE)
+ .clickCreateConditions()
+ .setConditionOutput(ConditionsPropertiesPage.OUTPUT_MCQ_TOTAL_MARK)
+ .setOptionType(ConditionsPropertiesPage.OPTION_RANGE)
+ .setFromRangeValue(rangeValueZero)
+ .setToRangeValue(rangeValueZero)
+ .clickAddOptionRange()
+ .setConditionName(conditionZeroRange, "2")
+ .setFromRangeValue(rangeValueOne)
+ .setToRangeValue(rangeValueOne)
+ .clickAddOptionRange()
+ .setConditionName(conditionOneRange, "3")
+ .clickOkConditionsButton()
+ .matchConditionToBranch(conditionOneRange, branchOne)
+ .matchConditionToBranch(conditionZeroRange, branchTwo)
+ .clickOkMatchingConditionsToBranchesButton();
+
+ saveResult = saveDesign();
+
+ // Assert design is valid
+ Assert.assertTrue(saveResult.contains(AuthorConstants.SAVE_SEQUENCE_SUCCESS_MSG),
+ "The error message recieved was not what we expected." + saveResult);
+
+
+ }
+
+
+ /**
+ * Save invalid design: no activities inside the optional
+ *
+ * Attempts to save a design that has no activities within the optional activity.
+ *
+ */
+ @Test(dependsOnMethods={"attemptSaveNoConditionsBranchesSet"})
+ public void attemptSaveNoActivitiesInsideOptional() {
+
+ cleanCanvas();
+
+ fla.dragOptionalActivityToCanvas();
+ fla.dragActivityToCanvas(AuthorConstants.MINDMAP_TITLE);
+ fla.drawTransitionBtwActivities();
+
+ String saveResult = fla.saveAsDesign(randomDesignName + "-nothingInsideOptional" );
+
+
+ // Assert invalid design
+ Assert.assertTrue(saveResult.contains(AuthorConstants.OPTIONAL_MUST_HAVE_ONE_ACTIVITY_MSG),
+ "The error message recieved was not what we expected." + saveResult);
+
+ // fix design
+ fla.dragActivityToCanvasPosition(AuthorConstants.FORUM_TITLE, 300, 185);
+ fla.dragActivityIntoOptionalActivity(AuthorConstants.OPTIONAL_ACTIVITY_TITLE,
+ AuthorConstants.FORUM_TITLE);
+
+ saveResult = saveDesign();
+
+ // Assert design is valid
+ Assert.assertTrue(saveResult.contains(AuthorConstants.SAVE_SEQUENCE_SUCCESS_MSG),
+ "The error message recieved was not what we expected." + saveResult);
+
+ }
+
+
+ /**
+ * Save invalid design: no activities inside a support container
+ *
+ * Attempts to save a design that has no activities within the support activity.
+ *
+ */
+ @Test(dependsOnMethods={"attemptSaveNoActivitiesInsideOptional"})
+ public void attemptSaveNoActivitiesInsideSupport() {
+
+ cleanCanvas();
+
+ fla.dragSupportActivityToCanvas();
+ fla.dragActivityToCanvas(AuthorConstants.WIKI_TITLE);
+ fla.drawTransitionBtwActivities();
+
+ String saveResult = fla.saveAsDesign(randomDesignName + "-nothingInsideSupport" );
+
+
+ // Assert invalid design
+ Assert.assertTrue(saveResult.contains(AuthorConstants.SUPPORT_MUST_HAVE_ONE_ACTIVITY_MSG),
+ "The error message recieved was not what we expected." + saveResult);
+
+ // fix design
+ fla.dragActivityToCanvasPosition(AuthorConstants.FORUM_TITLE, 300, 185);
+ fla.dragActivityIntoSupportActivity(AuthorConstants.SUPPORT_ACTIVITY_TITLE,
+ AuthorConstants.FORUM_TITLE);
+
+ saveResult = saveDesign();
+
+ // Assert design is valid
+ Assert.assertTrue(saveResult.contains(AuthorConstants.SAVE_SEQUENCE_SUCCESS_MSG),
+ "The error message recieved was not what we expected." + saveResult);
+
+ }
+
+ /**
+ * Save invalid design: no activities inside a support container
+ *
+ * Attempts to save a design that has no activities within the support activity.
+ *
+ */
+ @Test(dependsOnMethods={"attemptSaveNoActivitiesInsideSupport"})
+ public void attemptSaveNoActivities() {
+
+ cleanCanvas();
+
+ String saveResult = fla.saveAsDesign(randomDesignName + "-blankDesign" );
+
+
+ // Assert invalid design
+ Assert.assertTrue(saveResult.contains(AuthorConstants.SAVE_MUST_HAVE_ONE_ACTIVITY_MSG),
+ "The error message recieved was not what we expected." + saveResult);
+
+ // fix design
+ fla.dragActivityToCanvasPosition(AuthorConstants.FORUM_TITLE, 300, 185);
+
+ saveResult = saveDesign();
+
+ // Assert design is valid
+ Assert.assertTrue(saveResult.contains(AuthorConstants.SAVE_SEQUENCE_SUCCESS_MSG),
+ "The error message recieved was not what we expected." + saveResult);
+
+ }
+
+
+ private String saveDesign() {
+
+ return fla.saveDesign();
+ }
+
+
+
+
+
+}
Index: lams_tests/tests/org/lamsfoundation/lams/pages/author/FLAPage.java
===================================================================
diff -u -r3f7fbe1307799d1c650ad3e0f83399f3c1a8f9e9 -r563e1a1b8dba97f3a3a172f6a85c7eb86363a721
--- lams_tests/tests/org/lamsfoundation/lams/pages/author/FLAPage.java (.../FLAPage.java) (revision 3f7fbe1307799d1c650ad3e0f83399f3c1a8f9e9)
+++ lams_tests/tests/org/lamsfoundation/lams/pages/author/FLAPage.java (.../FLAPage.java) (revision 563e1a1b8dba97f3a3a172f6a85c7eb86363a721)
@@ -59,6 +59,7 @@
@FindBy(id = "newButton")
private WebElement newButton;
+
@FindBy(id = "openButton")
private WebElement openButton;
@@ -72,6 +73,7 @@
@FindBy(id = "importPartSequenceButton")
private WebElement importPartDesignButton;
+
@FindBy(id = "saveButton")
private WebElement saveButton;
@@ -91,9 +93,24 @@
@FindBy(id = "pasteButton")
private WebElement pasteButton;
+
@FindBy(id = "transitionButton")
private WebElement transitionButton;
-
+
+
+ @FindBy(id = "optionalButton")
+ private WebElement optionalButton;
+
+ @FindBy(id = "optionalDropButton")
+ private WebElement optionalDropButton;
+
+ @FindBy(id = "optionalActivityButton")
+ private WebElement optionalActivityButton;
+
+ @FindBy(id = "floatingActivityButton")
+ private WebElement supportActivityButton;
+
+
@FindBy(id = "flowButton")
private WebElement flowButton;
@@ -106,8 +123,10 @@
@FindBy(id = "branchingButton")
private WebElement branchingButton;
+
@FindBy(id = "groupButton")
private WebElement groupButton;
+
@FindBy(id = "annotateButton")
private WebElement annotateButton;
@@ -124,6 +143,7 @@
@FindBy(id = "arrangeButton")
private WebElement arrangeButton;
+
@FindBy(id = "previewButton")
private WebElement previewButton;
@@ -215,11 +235,11 @@
public FLAPage newDesign() {
newButton.click();
- checkAlert();
return PageFactory.initElements(driver, FLAPage.class);
}
+
/**
* Drops a group activity into the canvas.
*
@@ -424,10 +444,8 @@
*/
public FLAPage changeActivityTitle(String activityTitle, String newActivityTitle) {
- WebElement svg = driver.findElement(By.tagName("svg"));
+ WebElement activity = getActivityElement(activityTitle);
- WebElement activity = getActivityElement(svg, activityTitle);
-
// select the activity
activity.click();
@@ -457,10 +475,8 @@
*/
public AbstractPage openSpecificActivity(String activityName) {
- WebElement svg = driver.findElement(By.tagName("svg"));
+ WebElement act = getActivityElement(activityName);
- WebElement act = getActivityElement(svg, activityName);
-
Actions openAct = new Actions(driver);
openAct.doubleClick(act).build().perform();;
@@ -497,6 +513,36 @@
}
/**
+ * Given a design on canvas, it overwrites the existing one
+ *
+ * This method is different from saveAsDesign, as this one has to
+ * deal with two consecutive popups. One that prompts if you are
+ * sure to overwrite and the second one that gives the "Congratulations!
+ * your design is saved".
+ *
+ * We concatenate both alert txts and send them back
+ *
+ * @param designName design name to reuse. It must exist in folder.
+ * @return msg from alert
+ */
+ public String overWriteDesign(String designName) {
+
+ String saveAsResult = null;
+ saveDropButton.click();
+ saveAsButton.click();
+ ldStoreDialogNameField.click();
+ ldStoreDialogNameField.clear();
+ ldStoreDialogNameField.sendKeys(designName);
+ saveLdStoreButton.click();
+ saveAsResult = getAlertText();
+ saveAsResult = saveAsResult + getAlertText();
+
+ return saveAsResult;
+
+ }
+
+
+ /**
* Gets the activity names into a list.
*
*
@@ -535,10 +581,8 @@
*/
public FLAPage setGroupForActivity(String groupName, String activityName) {
- WebElement svg = driver.findElement(By.tagName("svg"));
+ WebElement activity = getActivityElement(activityName);
- WebElement activity = getActivityElement(svg, activityName);
-
activity.click();
Select groupDropDown = new Select(
@@ -560,17 +604,13 @@
*/
public FLAPage drawTransitionFromTo(String fromActivity, String toActivity) {
- WebElement svg = driver.findElement(By.tagName("svg"));
+ WebElement fromActivityElement = getActivityElement(fromActivity);
+ WebElement toActivityElement = getActivityElement(toActivity);
- WebElement fromActivityElement = getActivityElement(svg, fromActivity);
- WebElement toActivityElement = getActivityElement(svg, toActivity);
-
transitionButton.click();
fromActivityElement.click();
toActivityElement.click();
- canvas.click();
-
return PageFactory.initElements(driver, FLAPage.class);
}
@@ -585,14 +625,11 @@
*/
public FLAPage drawBranchingFromActivity(String fromActivity, List toActivities) {
- WebElement svg = driver.findElement(By.tagName("svg"));
-
- WebElement fromActivityElement = getActivityElement(svg, fromActivity);
+ WebElement fromActivityElement = getActivityElement(fromActivity);
-
for (String toActivity : toActivities) {
- WebElement toActivityElement = getActivityElement(svg, toActivity);
+ WebElement toActivityElement = getActivityElement(toActivity);
transitionButton.click();
fromActivityElement.click();
@@ -611,9 +648,8 @@
*/
public FLAPage copyPasteActivity(String activity) {
- WebElement svg = driver.findElement(By.tagName("svg"));
// Select activity
- getActivityElement(svg, activity).click();
+ getActivityElement(activity).click();
copyButton.click();
@@ -648,7 +684,7 @@
WebElement svg = driver.findElement(By.tagName("svg"));
// Select activity
- WebElement activityToDelete = getActivityElement(svg, activity);
+ WebElement activityToDelete = getActivityElement(activity);
//activityToDelete.click();
@@ -685,9 +721,8 @@
public void setGroups(String groupActivityName, String groupType, boolean isGroupsOrLearners,
int numberOfGroups, String groupNames, String groupOptions) {
- WebElement svg = driver.findElement(By.tagName("svg"));
// Select activity
- WebElement groupActivity = getActivityElement(svg, groupActivityName);
+ WebElement groupActivity = getActivityElement(groupActivityName);
groupActivity.click();
@@ -787,9 +822,9 @@
public BranchingPropertiesPage branchingProperties(String branchingName) {
branchingName = branchingName + " start";
- WebElement svg = driver.findElement(By.tagName("svg"));
- WebElement branchingActivity = getActivityElement(svg, branchingName);
+ WebElement branchingActivity = getActivityElement(branchingName);
+
branchingActivity.click();
return PageFactory.initElements(driver, BranchingPropertiesPage.class);
@@ -803,9 +838,7 @@
*/
public GatePropertyPage gateProperties() {
-
- WebElement svg = driver.findElement(By.tagName("svg"));
- WebElement gateActivity = getActivityElement(svg, AuthorConstants.GATE_TITLE);
+ WebElement gateActivity = getActivityElement(AuthorConstants.GATE_TITLE);
gateActivity.click();
return PageFactory.initElements(driver, GatePropertyPage.class);
@@ -816,9 +849,8 @@
final String selectGroupDropDownXpath =
"/html/body/div[14]/div[2]/div/table/tbody/tr[2]/td[2]/select";
- WebElement svg = driver.findElement(By.tagName("svg"));
// Select activity
- WebElement groupActivity = getActivityElement(svg, groupActivityName);
+ WebElement groupActivity = getActivityElement(groupActivityName);
groupActivity.click();
@@ -840,13 +872,18 @@
* @return Point location for the activity
*/
public Point getActivityLocation(String activityTitle) {
- WebElement svg = driver.findElement(By.tagName("svg"));
+
// Select activity
- WebElement activity = getActivityElement(svg, activityTitle);
+ WebElement activity = getActivityElement(activityTitle);
return activity.getLocation();
}
+ /**
+ * Inserts a gate activity into the canvas.
+ *
+ * @return
+ */
public FLAPage dragGateToCanvas() {
flowDropButton.click();
@@ -889,7 +926,55 @@
return PageFactory.initElements(driver, FLAPage.class);
}
+ /**
+ * Drags a optional activity into the canvas
+ *
+ */
+ public FLAPage dragOptionalActivityToCanvas() {
+
+ dragContainerActivityToCanvas("optional", 200, 180);
+
+ return PageFactory.initElements(driver, FLAPage.class);
+ }
+
+ /**
+ * Drags an support activity into the canvas
+ *
+ */
+ public FLAPage dragSupportActivityToCanvas() {
+
+ dragContainerActivityToCanvas("support", 200, 250);
+
+ return PageFactory.initElements(driver, FLAPage.class);
+ }
+
+
+ /**
+ * Drags an activity into the optional activity
+ */
+ public FLAPage dragActivityIntoOptionalActivity(String containerActivity, String activityName) {
+
+ dragActivityInToContainerActivity(containerActivity, activityName);
+
+ return PageFactory.initElements(driver, FLAPage.class);
+ }
+
+ /**
+ * Drags an activity into support activity
+ */
+ public FLAPage dragActivityIntoSupportActivity(String containerActivity, String activityName) {
+
+ dragActivityInToContainerActivity(containerActivity, activityName);
+
+ return PageFactory.initElements(driver, FLAPage.class);
+ }
+
+ /**
+ * Opens the Import design UI
+ *
+ * @return {@link ImportDesignPage}
+ */
public ImportDesignPage importDesign() {
openDropButton.click();
@@ -899,6 +984,27 @@
return PageFactory.initElements(driver, ImportDesignPage.class);
}
+ /**
+ * 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();
+ //driver.switchTo().defaultContent();
+ alert.accept();
+ } catch (Exception e) {
+ //exception handling
+ }
+ return txt;
+ }
/**
* Returns the correct popup id
@@ -933,36 +1039,18 @@
}
}
- /**
- * 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();
- //driver.switchTo().defaultContent();
- alert.accept();
- } catch (Exception e) {
- //exception handling
- }
- return txt;
- }
-
/**
* Parses thru the SVG design to find the WebElement for the activity name.
*
* @param svg The SVG for the current canvas
* @param activityName the name of the activity
* @return
*/
- private WebElement getActivityElement(WebElement svg, String activityName) {
+ private WebElement getActivityElement(String activityName) {
+
+ WebElement svg = driver.findElement(By.tagName("svg"));
WebElement activityElement = null;
@@ -1103,6 +1191,65 @@
inputNumGroups.clear();
inputNumGroups.sendKeys(Integer.toString(numberOfGroups));
}
+
+ /**
+ * Drags a container activity into the canvas.
+ *
+ * @param containerType ie: "optional" or "support"
+ * @param x
+ * @param y
+ */
+ private void dragContainerActivityToCanvas(String containerType, int x, int y) {
+
+ optionalDropButton.click();
+
+ if (containerType.equals("support")) {
+ supportActivityButton.click();
+ } else {
+ optionalActivityButton.click();
+ }
+
+ // Prepare the dragAndDrop action
+ Actions builder = new Actions(driver); // Configure the Action
+ Action dropBranch = builder
+ .moveToElement(canvas, x, y)
+ .click()
+ .moveByOffset(600, 0)
+ .click()
+ .build();
+
+ // Execute the Action
+ dropBranch.perform();
+
+ }
+
+ /**
+ * Drags an activity into a container (support/optional) activity.
+ *
+ * @param containerActivity name container activity
+ * @param activityName
+ */
+ private void dragActivityInToContainerActivity(String containerActivity, String activityName) {
+
+ WebElement optional = getActivityElement(containerActivity);
+ WebElement activityToDrop = getActivityElement(activityName);
+
+ Actions builder = new Actions(driver); // Configure the Action
+ @SuppressWarnings("deprecation")
+ Action dropActivityInsideOptional = builder
+ .moveToElement(activityToDrop)
+ .clickAndHold()
+ .pause(500) // for some reason we need this pause otherwise it doesn't work
+ .moveToElement(optional)
+ .release()
+ .build(); // Get the action
+
+ // Execute the Action
+ dropActivityInsideOptional.perform();
+
+ }
+
+
}