Index: lams_tests/tests/org/lamsfoundation/lams/author/AuthorTests.java =================================================================== RCS file: /usr/local/cvsroot/lams_tests/tests/org/lamsfoundation/lams/author/AuthorTests.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_tests/tests/org/lamsfoundation/lams/author/AuthorTests.java 16 Oct 2014 02:02:46 -0000 1.1 @@ -0,0 +1,227 @@ +/**************************************************************** + * 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.List; + +import org.lamsfoundation.lams.pages.author.FLAPage; +import org.lamsfoundation.lams.pages.AbstractPage; +import org.lamsfoundation.lams.pages.IndexPage; +import org.lamsfoundation.lams.pages.LoginPage; +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; + +/** + * Authoring tests for: + * + * - opening FLA + * - create a design with 4 activities + * - name and save design + * - clear canvas + * - reopen design + * - arrange activities + * - re-save design + * - saveAs design + * - change activity titles + * - save (one click) + * - open activity authoring + * + * @author Ernie Ghiglione (ernieg@lamsfoundation.org) + * + */ +public class AuthorTests { + + + // Constants + + private static final String FLA_TITLE = "Flashless Authoring"; + private static final String SAVE_SEQUENCE_SUCCESS_MSG = "Congratulations"; + + private static final String FORUM_TITLE = "Forum"; + private static final String KALTURA_TITLE = "Kaltura"; + private static final String SHARE_RESOURCES_TITLE = "Share Resources"; + private static final String Q_AND_A_TITLE = "Q & A"; + + private static final String randomInt = LamsUtil.randInt(0, 9999); + + private String randomDesignName = "Design-" + randomInt; + private int randomInteger = Integer.parseInt(LamsUtil.randInt(0, 5)); + + private LoginPage onLogin; + private IndexPage index; + private FLAPage fla; + + + WebDriver driver; + + @BeforeClass + public void beforeClass() { + driver = new FirefoxDriver(); + + onLogin = PageFactory.initElements(driver, LoginPage.class); + index = PageFactory.initElements(driver, IndexPage.class); + fla = PageFactory.initElements(driver, FLAPage.class); + onLogin.navigateToLamsLogin().loginAs("test2", "test2"); + + } + + @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(FLA_TITLE, fla.getTitle(), "The expected title is not present"); + + + + } + + /** + * Creates a 4 activity sequence + */ + @Test(dependsOnMethods={"openFLA"}) + public void createDesign() { + + // Drop activites in canvas + fla.dragActivityToCanvas(FORUM_TITLE); + fla.dragActivityToCanvasPosition(SHARE_RESOURCES_TITLE, 250, (20 * randomInteger)); + fla.dragActivityToCanvasPosition(KALTURA_TITLE, (350 * randomInteger), 120); + fla.dragActivityToCanvasPosition(Q_AND_A_TITLE, 600, (14 * randomInteger)); + fla.drawTransitionBtwActivities(); + + // Now get all the activity titles + List allActivityTitles = fla.getAllActivityNames(); + + // Assert that all of them are in the design + + Assert.assertTrue(allActivityTitles.contains(FORUM_TITLE), + "The title " + FORUM_TITLE + " was not found as an activity in the design"); + Assert.assertTrue(allActivityTitles.contains(SHARE_RESOURCES_TITLE), + "The title " + SHARE_RESOURCES_TITLE + " was not found as an activity in the design"); + Assert.assertTrue(allActivityTitles.contains(KALTURA_TITLE), + "The title " + KALTURA_TITLE + " was not found as an activity in the design"); + Assert.assertTrue(allActivityTitles.contains(Q_AND_A_TITLE), + "The title " + Q_AND_A_TITLE + " was not found as an activity in the design"); + } + + @Test(dependsOnMethods={"createDesign"}) + public void nameAndSaveDesign() { + + String saveResult = fla.saveDesign(randomDesignName); + // System.out.println(saveResult); + Assert.assertTrue(saveResult.contains(SAVE_SEQUENCE_SUCCESS_MSG), + "Saving a sequence returned an unexpected message: "+ saveResult); + + } + + @Test(dependsOnMethods={"nameAndSaveDesign"}) + public void cleanCanvas() { + fla.newDesign(); + + // Check that the design titled is back to untitled + String newTitle = fla.getSequenceName(); + Assert.assertTrue(newTitle.equals("Untitled"), "The canvas wasn't clean. Still shows: " + newTitle); + + } + + @Test(dependsOnMethods={"cleanCanvas"}) + public void reOpenDesign() { + + fla.openDesign(randomDesignName); + Assert.assertEquals(fla.getSequenceName(), randomDesignName); + + + } + + + @Test(dependsOnMethods={"reOpenDesign"}) + public void reArrangeDesign() { + + fla.arrangeDesign(); + + } + + @Test(dependsOnMethods={"reOpenDesign"}) + public void saveAsDesign() { + + String newSequenceName = "Re" + randomDesignName; + fla.saveAsDesign(newSequenceName); + Assert.assertEquals(fla.getSequenceName(), newSequenceName); + } + + + /** + * + */ + @Test(dependsOnMethods={"saveAsDesign"}) + public void changeActivityTitle() { + + String forumNewTitle = "New " + FORUM_TITLE; + String kalturaNewTitle = "New " + KALTURA_TITLE; + + fla.changeActivityTitle(FORUM_TITLE, forumNewTitle); + fla.changeActivityTitle(KALTURA_TITLE, kalturaNewTitle); + List allActivityTitles = fla.getAllActivityNames(); + + System.out.println("All Activites: "+ allActivityTitles); + + Assert.assertTrue(allActivityTitles.contains(forumNewTitle), + "The title " + forumNewTitle + " was not found as an activity in the design"); + Assert.assertTrue(allActivityTitles.contains(kalturaNewTitle), + "The title " + kalturaNewTitle + " was not found as an activity in the design"); + + + } + + + @Test(dependsOnMethods={"changeActivityTitle"}) + public void openActivity() { + + AbstractPage forumPage = fla.openSpecificActivity("New " + FORUM_TITLE); + + String forumPageTitle = forumPage.getTitle(); + forumPage.closeWindow(); + + Assert.assertEquals(forumPageTitle, FORUM_TITLE, + "The title seems to be different from what we expected."); + + + } + + +} Index: lams_tests/tests/org/lamsfoundation/lams/pages/AbstractPage.java =================================================================== RCS file: /usr/local/cvsroot/lams_tests/tests/org/lamsfoundation/lams/pages/AbstractPage.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_tests/tests/org/lamsfoundation/lams/pages/AbstractPage.java 16 Oct 2014 02:02:46 -0000 1.1 @@ -0,0 +1,69 @@ +/**************************************************************** + * 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; + +import org.lamsfoundation.lams.LamsConstants; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.support.PageFactory; + +/** + * AbstractPage for PageModel and PageFactory patterns + * All other pages will inherit from this. + * + * @author Ernie Ghiglione (ernieg@lamsfoundation.org) + * + */ +public class AbstractPage { + + protected WebDriver driver; + + public AbstractPage (WebDriver driver) { + this.driver = driver; + } + + public WebDriver getDriver() { + return driver; + } + + public LoginPage navigateToLamsLogin() { + driver.navigate().to(LamsConstants.TEST_SERVER_URL); + return PageFactory.initElements(driver, LoginPage.class); + } + + public String getTitle() { + return driver.getTitle(); + } + + public void maximizeWindows() { + driver.manage().window().maximize(); + } + + public void closeWindow() { + driver.close(); + } + + public String getWindowTitle() { + return driver.getTitle(); + } + +} Index: lams_tests/tests/org/lamsfoundation/lams/pages/IndexPage.java =================================================================== RCS file: /usr/local/cvsroot/lams_tests/tests/org/lamsfoundation/lams/pages/IndexPage.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_tests/tests/org/lamsfoundation/lams/pages/IndexPage.java 16 Oct 2014 02:02:46 -0000 1.1 @@ -0,0 +1,56 @@ +/**************************************************************** + * 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; + +import org.lamsfoundation.lams.pages.author.FLAPage; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; +import org.openqa.selenium.support.PageFactory; + +/** + * IndexPage + * + * @author Ernie Ghiglione (ernieg@lamsfoundation.org) + * + */ +public class IndexPage extends AbstractPage { + + @FindBy(id = "openFla") + private WebElement flaLink; + + @FindBy(id = "My Profile") + private WebElement myProfileTab; + + public IndexPage(WebDriver driver) { + super(driver); + } + + public FLAPage openFla() { + flaLink.click(); + driver.switchTo().window("FlashlessAuthoring"); + return PageFactory.initElements(driver, FLAPage.class); + } + + +} Index: lams_tests/tests/org/lamsfoundation/lams/pages/LoginPage.java =================================================================== RCS file: /usr/local/cvsroot/lams_tests/tests/org/lamsfoundation/lams/pages/LoginPage.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_tests/tests/org/lamsfoundation/lams/pages/LoginPage.java 16 Oct 2014 02:02:46 -0000 1.1 @@ -0,0 +1,47 @@ +package org.lamsfoundation.lams.pages; + + +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; +import org.openqa.selenium.support.PageFactory; + + +public class LoginPage extends AbstractPage { + + @FindBy(name = "j_username") + private WebElement usernameField; + + @FindBy(name = "j_password") + private WebElement passwordField; + + @FindBy(id = "loginButton") + private WebElement loginButton; + + public LoginPage(WebDriver driver) { + super(driver); + } + + public IndexPage loginAs(String username, String password) { + enterUsername(username); + enterPassword(password); + submitLogin(); + return PageFactory.initElements(driver, IndexPage.class); + + } + + public void enterUsername (String username) { + usernameField.clear(); + usernameField.sendKeys(username); + + } + + public void enterPassword (String password) { + passwordField.clear(); + passwordField.sendKeys(password); + } + + public void submitLogin() { + loginButton.click(); + } +} Index: lams_tests/tests/org/lamsfoundation/lams/pages/author/FLAPage.java =================================================================== RCS file: /usr/local/cvsroot/lams_tests/tests/org/lamsfoundation/lams/pages/author/FLAPage.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_tests/tests/org/lamsfoundation/lams/pages/author/FLAPage.java 16 Oct 2014 02:02:46 -0000 1.1 @@ -0,0 +1,578 @@ +/**************************************************************** + * 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.author; + + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +import org.lamsfoundation.lams.pages.AbstractPage; +import org.openqa.selenium.Alert; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Action; +import org.openqa.selenium.interactions.Actions; +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; + +/** + * Flashless Authoring page. + * All interaction with Authoring environment should be done thru this page. + * + * @author Ernie Ghiglione (ernieg@lamsfoundation.org) + * + */ +public class FLAPage extends AbstractPage { + + /** + * Menu buttons + * These are the menu buttons on the interface. + */ + + @FindBy(id = "newButton") + private WebElement newButton; + + @FindBy(id = "openButton") + private WebElement openButton; + + @FindBy(id = "importSequenceButton") + private WebElement importSequenceButton; + + @FindBy(id = "importPartSequenceButton") + private WebElement importPartSequenceButton; + + @FindBy(id = "saveButton") + private WebElement saveButton; + + @FindBy(id = "saveDropButton") + private WebElement saveDropButton; + + @FindBy(id = "saveAsButton") + private WebElement saveAsButton; + + @FindBy(id = "exportButton") + private WebElement exportButton; + + + @FindBy(id = "copyButton") + private WebElement copyButton; + + @FindBy(id = "pasteButton") + private WebElement pasteButton; + + @FindBy(id = "transitionButton") + private WebElement transitionButton; + + @FindBy(id = "flowButton") + private WebElement flowButton; + + @FindBy(id = "gateButton") + private WebElement gateButton; + + @FindBy(id = "branchingButton") + private WebElement branchingButton; + + @FindBy(id = "groupButton") + private WebElement groupButton; + + @FindBy(id = "annotateButton") + private WebElement annotateButton; + + @FindBy(id = "annotateLabelButton") + private WebElement annotateLabelButton; + + @FindBy(id = "annotateRegionButton") + private WebElement annotateRegionButton; + + @FindBy(id = "arrangeButton") + private WebElement arrangeButton; + + @FindBy(id = "previewButton") + private WebElement previewButton; + + /** + * Activities + */ + + + /** + * Page elements + * These are the page elements on FLA + */ + + @FindBy(id = "canvas") + private WebElement canvas; + + @FindBy(id = "ldDescriptionFieldTitle") + private WebElement sequenceTitle; + + @FindBy(id = "svg") + private WebElement svgCanvas; + + + /** + * Dialogs: Save design dialog elements + */ + + @FindBy(id = "ldStoreDialogNameField") + private WebElement ldStoreDialogNameField; + + @FindBy(id = "saveLdStoreButton") + private WebElement saveLdStoreButton; + + + /** + * Dialogs: Open design dialog elements + */ + + @FindBy(id = "openLdStoreButton") + private WebElement openLdStoreButton; + + @FindBy(id = "ldStoreDialogTreeCell") + private WebElement ldTree; + + + @FindBy(id = "propertiesContentTool") + private WebElement propertiesContentTool; + + + + public FLAPage(WebDriver driver) { + super(driver); + + } + + + + /** + * Opens LD Dialog to open a design + * + */ + public void openLdOpenDialog() { + + openButton.click(); + + } + + /** + * Opens LD Dialog to save a design + */ + public void openLdSaveDialog() { + + saveButton.click(); + } + + + /** + * Clears canvas to new + */ + public void newDesign() { + + newButton.click(); + checkAlert(); + } + + /** + * Given the activity name, it drags it into the canvas. By default it puts it in the + * center of the canvas. + * @param name + */ + public void dragActivityToCanvas(String name) { + + String toolName = "tool" + name; + + WebElement tool = driver.findElement(By.id(toolName)); + + Actions builder = new Actions(driver); // Configure the Action + Action dragAndDrop = builder.clickAndHold(tool) + .moveToElement(canvas) + .release(canvas) + .build(); // Get the action + dragAndDrop.perform(); // Execute the Action + + } + + /** + * Given an activity, it drags it into the canvas and moves it in the x,y offset position. + * It uses the randomInteger value to randomize the position of the activities in the + * screen + * + * @param name activity name + * @param x x offset move + * @param y y offset move + */ + public void dragActivityToCanvasPosition(String name, int x, int y) { + + // we include the prefix "tool" as that's what we named the ids + String toolName = "tool" + name; + + // Finds the activity + WebElement tool = driver.findElement(By.id(toolName)); + + // Prepare the dragAndDrop action + Actions builder = new Actions(driver); // Configure the Action + Action dragAndDrop = builder.clickAndHold(tool) + .moveByOffset(x, y) + .release() + .build(); + + // Execute the Action + dragAndDrop.perform(); + + } + + /** + * Saves a design with the given param desigName. + * + * @param designName + * @return the message shown in the save alert popup. + * + */ + public String saveDesign(String designName) { + + String saveResult = null; + + openLdSaveDialog(); + ldStoreDialogNameField.sendKeys(designName); + saveLdStoreButton.click(); + saveResult = getAlertText(); + + return saveResult; + + } + + /** + * Saves a design + * This takes no parameters as it's just a click on the + * save menu button once the sequence/design exists. + * + * @return the message shown in the save alert popup. + * + */ + public String saveDesign() { + + String saveResult = null; + + saveButton.click(); + saveResult = getAlertText(); + + return saveResult; + + } + + /** + * Gets the Sequence title/name for the canvas. + * + * @return + */ + public String getSequenceName () { + return sequenceTitle.getText().trim(); + } + + + /** + * Rearranges the design on the canvas by pressing + * the "Arrange" button. + */ + public void arrangeDesign() { + arrangeButton.click(); + + } + + + /** + * Opens the open sequence dialog to select and open the design on + * canvas. + * + * @param seqName + * + */ + public void openDesign(String seqName) { + + // opens the dialog + openLdOpenDialog(); + + // parses the available sequences + List elements = ldTree.findElements( + By.xpath("//*[contains(text(), '"+ seqName +"')]")); + + // Find the sequence that is in seqName and also is visible + // -- we've got to improve this though! + for (int i = 0; i < elements.size(); i++) { + WebElement el = elements.get(i); + //System.out.println(el.getText()); + if (el.isDisplayed()) { + el.click(); + } + } + + // click on open + openLdStoreButton.click(); + + } + + + /** + * Draws transitions in between the activities. + * It follows the order in which it finds the activities. + * + */ + public void drawTransitionBtwActivities() { + + WebElement svg = driver.findElement(By.tagName("svg")); + + List listActivities = svg.findElements(By.tagName("text")); + + int size = listActivities.size(); + //System.out.println("Activity #: " + size); + for (int i = 0; i < size; i++) { + System.out.println("i: " + i ); + if (i+1 < size) { + transitionButton.click(); + listActivities.get(i).click(); + listActivities.get(i+1).click(); + //System.out.println("i + 1= " + (i+1) ); + + } + //System.out.println("closing"); + } + + } + + /** + * Changes the name in the activity. + * + * @param activityTitle + * @param newActivityTitle + */ + public void changeActivityTitle(String activityTitle, String newActivityTitle) { + + WebElement svg = driver.findElement(By.tagName("svg")); + + WebElement activity = getActivityElement(svg, activityTitle); + + // select the activity + activity.click(); + + // Now change the Title using xpath to the activity Title input + // -- this should change to id in the future. + driver.findElement( + By.xpath("/html/body/div[14]/div[2]/div/table/tbody/tr[1]/td[2]/input")) + .clear(); + driver.findElement( + By.xpath("/html/body/div[14]/div[2]/div/table/tbody/tr[1]/td[2]/input")) + .sendKeys(newActivityTitle); + + // click on canvas so the change takes effect + canvas.click(); + + } + + /** + * Opens an the authoring window for an learning activity + * This should be moved eventually to another test. + * + * + * @param activityName the name of the activity to open + * @return abstractPage factory so it can be manipulated. + * + */ + public AbstractPage openSpecificActivity(String activityName) { + + WebElement svg = driver.findElement(By.tagName("svg")); + + WebElement act = getActivityElement(svg, activityName); + + Actions openAct = new Actions(driver); + openAct.doubleClick(act).build().perform();; + + String popUpWindow = getPopUpWindowId(driver); + + driver.switchTo().window(popUpWindow); + + return PageFactory.initElements(driver, AbstractPage.class); + + + } + + + /** + * Given a design on canvas, it saves it under a new name + * + * + * @param newSequenceName new name to save as + * @return msg from alert + */ + public String saveAsDesign(String newSequenceName) { + + String saveAsResult = null; + saveDropButton.click(); + saveAsButton.click(); + ldStoreDialogNameField.clear(); + ldStoreDialogNameField.sendKeys(newSequenceName); + saveLdStoreButton.click(); + saveAsResult = getAlertText(); + + return saveAsResult; + + } + + /** + * Gets the activity names into a list. + * + * + * @return a string list with the activity names + */ + public List getAllActivityNames() { + + List allActivities = new ArrayList<>(); + + WebElement svg = driver.findElement(By.tagName("svg")); + + List allActivitiesElements = getActivityElements(svg); + + System.out.println("Allactivities size: " + allActivitiesElements.size()); + + for (int i = 0; i < allActivitiesElements.size(); i++) { + + WebElement element = allActivitiesElements.get(i); + System.out.println(element.getText()); + allActivities.add(element.getText()); + + } + + return allActivities; + + } + + + /** + * Returns the correct popup id + * + * @param driver + * @return + */ + private String getPopUpWindowId(WebDriver driver) { + + String authorToolWindow = null; + Set handles = driver.getWindowHandles(); + Iterator iterator = handles.iterator(); + + while (iterator.hasNext()){ + authorToolWindow = iterator.next(); + } + + return authorToolWindow; + } + + /** + * Clicks OK on the alert javascript popup + */ + private void checkAlert() { + try { + WebDriverWait wait = new WebDriverWait(driver, 2); + wait.until(ExpectedConditions.alertIsPresent()); + Alert alert = driver.switchTo().alert(); + alert.accept(); + } catch (Exception e) { + //exception handling + } + } + + /** + * 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) { + + WebElement activityElement = null; + + List listActivities = svg.findElements(By.tagName("text")); + + for (WebElement webElement : listActivities) { + activityElement = webElement.findElement(By.tagName("tspan")); + String name = activityElement.getText(); + + if (activityName.equals(name)) { + break; + + } + + } + + return activityElement; + } + + /** + * Returns all activities in the design as WebElements in a list + * + * @param svg svg node on page. + * @return list of web elements for activities in design + */ + private List getActivityElements(WebElement svg) { + + List activitiesElements = new ArrayList(); + + List activityList = svg.findElements(By.tagName("text")); + + for (WebElement webElement : activityList) { + WebElement activityElement = webElement.findElement(By.tagName("tspan")); + activitiesElements.add(activityElement); + } + + return activitiesElements; + + } + + +}