Example usage for org.openqa.selenium.interactions Actions keyDown

List of usage examples for org.openqa.selenium.interactions Actions keyDown

Introduction

In this page you can find the example usage for org.openqa.selenium.interactions Actions keyDown.

Prototype

public Actions keyDown(CharSequence key) 

Source Link

Document

Performs a modifier key press.

Usage

From source file:com.liferay.faces.test.alloy.showcase.datatable.DataTableTesterBase.java

License:Open Source License

/**
 * Must build this action using keyDown(key) and keyUp(key) since Action sendKeys behaves differently than
 * WebElement sendKeys (unless the browser is phantomjs, then it would need the following script).
 * https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/interactions/Actions.html#sendKeys-java.lang.CharSequence...-
 *//*from   w  w  w .  j av  a 2s.  c o m*/
protected void metaOrCommandClick(BrowserDriver browserDriver, String xpath) {
    Keys metaOrCommandKey = Keys.META;

    if (System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("mac")) {
        metaOrCommandKey = Keys.COMMAND;
    }

    if ("phantomjs".equals(browserDriver.getBrowserName())) {
        browserDriver.executeScriptInCurrentWindow(
                "var element = arguments[0]; YUI().use('node-event-simulate', function(Y) { Y.one(element).simulate('click', { metaKey: true }); });",
                browserDriver.findElementByXpath(xpath));
    } else {
        Actions metaOrCommandClickBuilder = browserDriver.createActions();
        metaOrCommandClickBuilder.keyDown(metaOrCommandKey).click(browserDriver.findElementByXpath(xpath))
                .keyUp(metaOrCommandKey);

        Action metaOrCommandClick = metaOrCommandClickBuilder.build();
        metaOrCommandClick.perform();
    }
}

From source file:com.me.jvmi.SelectElement.java

public void selectAll(Set<String> optionsText) {
    Actions shiftClick = new Actions(driver);
    shiftClick = shiftClick.keyDown(Keys.SHIFT);
    List<WebElement> options = select.findElements(By.tagName("option"));
    for (WebElement option : options) {
        if (optionsText.contains(option.getText())) {
            shiftClick = shiftClick.click(option);
        }/*from   ww w .j av  a 2s .  co  m*/
    }
    shiftClick.keyUp(Keys.SHIFT).perform();
}

From source file:com.pentaho.ctools.issues.cde.CDE286.java

License:Apache License

/**
 * ############################### Test Case 1 ###############################
 *
 * Test Case Name://from  w  ww. j  a  v a 2s.  c o m
 *    Asserting CGG Dial Chart can be exported and viewed via URL
 *
 * Description:
 *    The test pretends validate the CDE-286 issue, so when user exports a CGG Dial Component it can
 *    be viewed via the URL given.
 *
 * Steps:
 *    1. Wait for new Dashboard to be created, assert elements on page and click "Components Panel"
 *    2. Add CGG Dial Component and fill it's properties
 *    3. Click "Shift+G" to create export file and choose URL
 *    4. Add "&param=25" to URL and assert Dial Component is properly shown
 * @throws InterruptedException 
 *
 */
@Test
public void tc01_NewCdeDashboard_CggDialComponentExport() {
    this.log.info("tc01_NewCdeDashboard_CggDialComponentExport");

    /*
     * ## Step 1
     */
    //Go to New CDE Dashboard
    driver.get(PageUrl.CDE_DASHBOARD);
    this.elemHelper.WaitForElementInvisibility(driver, By.cssSelector("div.blockUI.blockOverlay"));
    //assert buttons
    WebElement buttonSaveTemplate = this.elemHelper.WaitForElementPresence(driver,
            By.xpath("//a[@title='Save as Template']"));
    WebElement buttonApplyTemplate = this.elemHelper.WaitForElementPresence(driver,
            By.xpath("//a[@title='Apply Template']"));
    WebElement buttonAddResource = this.elemHelper.WaitForElementPresence(driver,
            By.xpath("//a[@title='Add Resource']"));
    WebElement buttonAddBoostrap = this.elemHelper.WaitForElementPresence(driver,
            By.xpath("//a[@title='Add Bootstrap Panel']"));
    WebElement buttonAddFreeForm = this.elemHelper.WaitForElementPresence(driver,
            By.xpath("//a[@title='Add FreeForm']"));
    WebElement buttonAddRow = this.elemHelper.WaitForElementPresence(driver, By.xpath("//a[@title='Add Row']"));
    WebElement buttonLayout = this.elemHelper.WaitForElementPresenceAndVisible(driver,
            By.xpath("//div[@class='layoutPanelButton']"));
    WebElement buttonComponents = this.elemHelper.WaitForElementPresenceAndVisible(driver,
            By.xpath("//div[@class='componentsPanelButton']"));
    WebElement buttonDatasources = this.elemHelper.WaitForElementPresenceAndVisible(driver,
            By.xpath("//div[@class='datasourcesPanelButton']"));
    assertNotNull(buttonSaveTemplate);
    assertNotNull(buttonApplyTemplate);
    assertNotNull(buttonAddResource);
    assertNotNull(buttonAddBoostrap);
    assertNotNull(buttonAddFreeForm);
    assertNotNull(buttonAddRow);
    assertNotNull(buttonLayout);
    assertNotNull(buttonComponents);
    assertNotNull(buttonDatasources);
    this.elemHelper.Click(driver, By.cssSelector("div.componentsPanelButton"));

    /*
     * ## Step 2
     */
    this.elemHelper.Click(driver, By.xpath("//div[@id='cdfdd-components-palletePallete']/div/h3/span"));
    this.elemHelper.Click(driver, By.xpath(
            "//div[@id='cdfdd-components-palletePallete']/div/div/ul/li[24]/a[@title='CGG Dial Chart']"));
    String componentName = this.elemHelper.WaitForElementPresentGetText(driver,
            By.xpath("//table[@id='table-cdfdd-components-components']/tbody/tr[2]/td"));
    assertEquals(componentName, "CGG Dial Component");

    //Add Name
    String expectedChartName = "dial";
    this.elemHelper
            .FindElement(driver, By.xpath(
                    "//div[@id='cdfdd-components-properties']/div/div[2]/table/tbody/tr/td[2]/form/input"))
            .sendKeys("dial");
    this.elemHelper
            .FindElement(driver, By.xpath(
                    "//div[@id='cdfdd-components-properties']/div/div[2]/table/tbody/tr/td[2]/form/input"))
            .submit();
    this.elemHelper.WaitForTextPresence(driver,
            By.xpath("//div[@id='cdfdd-components-properties']/div/div[2]/table/tbody/tr/td[2]"), "dial");
    String actualChartName = this.elemHelper.WaitForElementPresentGetText(driver,
            By.xpath("//div[@id='cdfdd-components-properties']/div/div[2]/table/tbody/tr/td[2]"));
    assertEquals(expectedChartName, actualChartName);

    //Add Color Range
    String strColor1 = "blue";
    String strColor2 = "green";
    String strColor3 = "brown";
    this.elemHelper.Click(driver,
            By.xpath("//table[@id='table-cdfdd-components-properties']/tbody/tr[2]/td[2]"));
    //We need to wait for the animation finish for the display popup
    this.elemHelper.FindElement(driver, By.id("popup"));
    //Add Colors
    //this.elemHelper.Click( driver, By.cssSelector( "button.popup-add-row-button" ) );
    WebElement elemArg0 = this.elemHelper.FindElement(driver, By.id("arg_0"));
    this.elemHelper.Click(driver, By.cssSelector("button.popup-add-row-button"));
    WebElement elemArg1 = this.elemHelper.FindElement(driver, By.id("arg_1"));
    this.elemHelper.Click(driver, By.cssSelector("button.popup-add-row-button"));
    WebElement elemArg2 = this.elemHelper.FindElement(driver, By.id("arg_2"));
    assertNotNull(elemArg0);
    assertNotNull(elemArg1);
    assertNotNull(elemArg2);
    //Add the first color
    this.elemHelper.ClickAndSendKeys(driver, By.id("arg_0"), strColor3);
    //Add the second color
    this.elemHelper.ClickAndSendKeys(driver, By.id("arg_1"), strColor2);
    //Add the third color
    this.elemHelper.ClickAndSendKeys(driver, By.id("arg_2"), strColor1);

    //Submit
    this.elemHelper.Click(driver, By.id("popup_state0_buttonOk"));
    //Wait For Popup Disappear
    this.elemHelper.WaitForElementNotPresent(driver, By.id("popupbox"));
    //Check the colors array
    this.elemHelper.WaitForTextPresence(driver,
            By.xpath("//table[@id='table-cdfdd-components-properties']/tbody/tr[2]/td[2]"),
            "[\"" + strColor3 + "\",\"" + strColor2 + "\",\"" + strColor1 + "\"]");
    String rangeColorArray = this.elemHelper.WaitForElementPresentGetText(driver,
            By.xpath("//table[@id='table-cdfdd-components-properties']/tbody/tr[2]/td[2]"));
    assertEquals("[\"brown\",\"green\",\"blue\"]", rangeColorArray);

    //Add Intervals Array
    String strInterval0 = "100";
    String strInterval1 = "50";
    String strInterval2 = "25";
    String strInterval3 = "0";
    this.elemHelper.Click(driver,
            By.xpath("//table[@id='table-cdfdd-components-properties']/tbody/tr[3]/td[2]"));
    //We need to wait for the animation finish for the display popup
    this.elemHelper.FindElement(driver, By.id("popup"));
    //Add intervals
    //this.elemHelper.Click( driver, By.cssSelector( "button.popup-add-row-button" ) );
    WebElement elemInterArg0 = this.elemHelper.FindElement(driver, By.id("arg_0"));
    this.elemHelper.Click(driver, By.cssSelector("button.popup-add-row-button")); // Add arg1
    WebElement elemInterArg1 = this.elemHelper.FindElement(driver, By.id("arg_1"));
    this.elemHelper.Click(driver, By.cssSelector("button.popup-add-row-button")); // Add arg2
    WebElement elemInterArg2 = this.elemHelper.FindElement(driver, By.id("arg_2"));
    this.elemHelper.Click(driver, By.cssSelector("button.popup-add-row-button")); // Add arg3
    WebElement elemInterArg3 = this.elemHelper.FindElement(driver, By.id("arg_3"));
    assertNotNull(elemInterArg0);
    assertNotNull(elemInterArg1);
    assertNotNull(elemInterArg2);
    assertNotNull(elemInterArg3);
    //Add interval 0
    this.elemHelper.ClickAndSendKeys(driver, By.id("arg_0"), strInterval3);
    //Add interval 1
    this.elemHelper.ClickAndSendKeys(driver, By.id("arg_1"), strInterval2);
    //Add interval 2
    this.elemHelper.ClickAndSendKeys(driver, By.id("arg_2"), strInterval1);
    //Add interval 3
    this.elemHelper.ClickAndSendKeys(driver, By.id("arg_3"), strInterval0);

    // Submit
    this.elemHelper.ClickJS(driver, By.id("popup_state0_buttonOk"));
    //Wait For Popup Disappear
    this.elemHelper.WaitForElementNotPresent(driver, By.id("popupbox"));
    //Check if was saved
    String expectedIntervalArray = "[\"" + strInterval3 + "\",\"" + strInterval2 + "\",\"" + strInterval1
            + "\",\"" + strInterval0 + "\"]";
    this.elemHelper.WaitForTextPresence(driver,
            By.xpath("//table[@id='table-cdfdd-components-properties']/tbody/tr[3]/td[2]"),
            expectedIntervalArray);
    String actualIntervalsArray = this.elemHelper.WaitForElementPresentGetText(driver,
            By.xpath("//table[@id='table-cdfdd-components-properties']/tbody/tr[3]/td[2]"));
    assertEquals(expectedIntervalArray, actualIntervalsArray);

    //Add Parameter
    String expectedParameter = "27";
    this.elemHelper.Click(driver,
            By.xpath("//table[@id='table-cdfdd-components-properties']/tbody/tr[4]/td[2]"));
    this.elemHelper
            .FindElement(driver,
                    By.xpath("//table[@id='table-cdfdd-components-properties']/tbody/tr[4]/td[2]/form/input"))
            .sendKeys(expectedParameter);
    this.elemHelper
            .FindElement(driver,
                    By.xpath("//table[@id='table-cdfdd-components-properties']/tbody/tr[4]/td[2]/form/input"))
            .submit();
    String actualParameter = this.elemHelper.WaitForElementPresentGetText(driver,
            By.xpath("//table[@id='table-cdfdd-components-properties']/tbody/tr[4]/td[2]"));
    assertEquals(expectedParameter, actualParameter);

    //Add Height
    String expectedHeight = "321";
    this.elemHelper.Click(driver,
            By.xpath("//table[@id='table-cdfdd-components-properties']/tbody/tr[6]/td[2]"));
    this.elemHelper
            .FindElement(driver,
                    By.xpath("//table[@id='table-cdfdd-components-properties']/tbody/tr[6]/td[2]/form/input"))
            .sendKeys(expectedHeight);
    this.elemHelper
            .FindElement(driver,
                    By.xpath("//table[@id='table-cdfdd-components-properties']/tbody/tr[6]/td[2]/form/input"))
            .submit();
    String actualHeight = this.elemHelper.WaitForElementPresentGetText(driver,
            By.xpath("//table[@id='table-cdfdd-components-properties']/tbody/tr[6]/td[2]"));
    assertEquals(expectedHeight, actualHeight);

    //Add Width
    String expectedWidth = "215";
    this.elemHelper.Click(driver,
            By.xpath("//table[@id='table-cdfdd-components-properties']/tbody/tr[7]/td[2]"));
    this.elemHelper
            .FindElement(driver,
                    By.xpath("//table[@id='table-cdfdd-components-properties']/tbody/tr[7]/td[2]/form/input"))
            .sendKeys(expectedWidth);
    this.elemHelper
            .FindElement(driver,
                    By.xpath("//table[@id='table-cdfdd-components-properties']/tbody/tr[7]/td[2]/form/input"))
            .submit();
    String actualWidth = this.elemHelper.WaitForElementPresentGetText(driver,
            By.xpath("//table[@id='table-cdfdd-components-properties']/tbody/tr[7]/td[2]"));
    assertEquals(expectedWidth, actualWidth);

    /*
     * ## Step 3
     */
    Actions a = new Actions(driver);
    a.keyDown(Keys.SHIFT).sendKeys("g").keyUp(Keys.SHIFT).build().perform();
    WebElement cggDialog = this.elemHelper.WaitForElementPresence(driver, By.id("cggDialog"));
    assertNotNull(cggDialog);
    String actualCggDialogTitle = this.elemHelper.WaitForElementPresentGetText(driver,
            By.xpath("//div[@id='cggDialog']/h3"));
    assertEquals("Choose what charts to render as CGG", actualCggDialogTitle);
    String actualChartNameTorender = this.elemHelper.WaitForElementPresentGetText(driver,
            By.xpath("//div[@id='cggDialog']/div/span"));
    assertEquals(expectedChartName, actualChartNameTorender);
    this.elemHelper.Click(driver, By.xpath("//div[@id='cggDialog']/div/input"));
    this.elemHelper.Click(driver, By.xpath("//div[@id='cggDialog']/div/button"));
    String actualUrl = this.elemHelper.GetAttribute(driver, By.xpath("//div[@id='cggDialog']/div/div/input"),
            "value");
    String expectedURL = baseUrl
            + "plugin/cgg/api/services/draw?script=/system/pentaho-cdf-dd/resources/custom/components/cgg/charts/dial.js&paramcolors="
            + strColor3 + "&paramcolors=" + strColor2 + "&paramcolors=" + strColor1 + "&paramscale="
            + strInterval3 + "&paramscale=" + strInterval2 + "&paramscale=" + strInterval1 + "&paramscale="
            + strInterval0 + "&height=" + expectedHeight + "&width=" + expectedWidth + "&outputType=png";
    assertEquals(expectedURL, actualUrl);

    /*
     * ## Step 4
     */
    driver.get(expectedURL + "&paramvalue=25");
    WebElement elemImg = this.elemHelper.FindElement(driver, By.cssSelector("img"));
    assertNotNull(elemImg);
    String actualImgUrl = this.elemHelper.GetAttribute(driver, By.cssSelector("img"), "src");
    assertEquals(actualImgUrl, expectedURL + "&paramvalue=25");

}

From source file:com.pentaho.ctools.issues.cde.editor.CDELayoutPanel.java

License:Apache License

/**
 * ############################### Test Case 1 ###############################
 *
 * Test Case Name:/*from w  w  w . j  a v  a2 s  .  c om*/
 *    This test is meant to validate all issues related to CDE's Layout Panel
 *
 * Description:
 *    CDE-270: Layout elements are draggable
 *    CDE-366: Style and Dashboard type changes are kept when saving dashboard
 *    CDE-395: Bootstrap is default renderer
 *    CDE-402: When applying template, user is asked for confirmation before it is applied
 *    CDE-406: Drag and Drop of Freeform elements works
 *    CDE-407: Able to duplicate spacers
 *    CDE-410: Shortcuts work
 *    CDE-425: Shortcuts work
 *    CDE-432: Left is the first option of text alignment
 *    CDE-527: Only Column can be direct child of Rows in a bootstrap dashboard
 *    CDE-528: If a bootstrap Column has no Xs defined a default of 12 is used
 *
 * Steps:
 *    1. Open new CDE dashboard and assert bootstrap is selected as renderer
 *    2. Use shortcuts to add and delete elements
 *    3. Add some elements and Drag them to other positions, asserting new positions
 *    4. Set template and assert it is correctly applied
 *    5. Assert navigation shortcuts work as expected and set clear Xs of an element
 *    6. Edit Settings and save dashboard. Preview dashboard and assert Xs is 12 by default
 */
@Test
public void tc01_CDEDashboardEdit_LayoutPanel() {
    this.log.info("tc01_CDEDashboardEdit_LayoutPanel");

    /*
     * ## Step 1
     */
    //Go to New CDE Dashboard
    driver.get(PageUrl.CDE_DASHBOARD);
    this.elemHelper.WaitForElementInvisibility(driver, By.cssSelector("div.blockUI.blockOverlay"));

    //Open Dashboard Settings and assert bootstrap is selected as renderer
    WebElement settingsLink = this.elemHelper.WaitForElementPresenceAndVisible(driver,
            By.xpath("//div[@id='headerLinks']//a[@onclick='cdfdd.saveSettings()']"));
    assertNotNull(settingsLink);
    settingsLink.click();
    WebElement settingsPopup = this.elemHelper.WaitForElementPresenceAndVisible(driver,
            By.xpath("//div[@id='popup']//div[@id='popupstates']"));
    assertNotNull(settingsPopup);
    Select dashboardType = new Select(
            this.elemHelper.WaitForElementPresenceAndVisible(driver, By.id("rendererInput")));
    String selectedOption = dashboardType.getFirstSelectedOption().getAttribute("value");
    assertEquals("bootstrap", selectedOption);
    WebElement cancelButton = this.elemHelper.FindElement(driver, By.id("popup_state0_buttonCancel"));
    assertNotNull(cancelButton);
    cancelButton.click();
    this.elemHelper.WaitForElementNotPresent(driver, By.xpath("//div[@id='popup']//div[@id='popupstates']"));

    /*
     * ## Step 2
     */
    //Add Row and verify that columns and html can not be added outside of rows
    this.elemHelper.Click(driver, By.id("table-cdfdd-layout-tree"));
    Actions a = new Actions(driver);
    a.sendKeys("c").sendKeys("h").sendKeys("r").build().perform();
    this.elemHelper.Click(driver, By.id("table-cdfdd-layout-tree"));

    //Add Column
    a.sendKeys("c").build().perform();

    //Add Html
    this.elemHelper.Click(driver, By.id("table-cdfdd-layout-tree"));
    a.sendKeys("h").build().perform();

    //Assert elements were successfully created
    WebElement row = this.elemHelper.WaitForElementPresenceAndVisible(driver,
            By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr/td"));
    assertNotNull(row);
    this.elemHelper.WaitForTextPresence(driver, By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr/td"),
            "Row");
    String rowText = row.getText();
    assertEquals(rowText, "Row");
    WebElement column = this.elemHelper.WaitForElementPresenceAndVisible(driver,
            By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr[2]/td"));
    assertNotNull(column);
    this.elemHelper.WaitForTextPresence(driver,
            By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr[2]/td"), "Column");
    String columnText = column.getText();
    assertEquals(columnText, "Column");
    WebElement html = this.elemHelper.WaitForElementPresenceAndVisible(driver,
            By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr[3]/td"));
    assertNotNull(html);
    this.elemHelper.WaitForTextPresence(driver,
            By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr[3]/td"), "Html");
    String htmlText = html.getText();
    assertEquals(htmlText, "Html");

    //Add spacer and duplicate it
    column.click();
    WebElement spacerButton = this.elemHelper.WaitForElementPresenceAndVisible(driver,
            By.xpath("//a[@title='Add Space']"));
    assertNotNull(spacerButton);
    spacerButton.click();
    WebElement spacer = this.elemHelper.WaitForElementPresenceAndVisible(driver,
            By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr[4]/td"));
    assertNotNull(spacer);
    this.elemHelper.WaitForTextPresence(driver,
            By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr[4]/td"), "Space");
    String spacerText = spacer.getText();
    assertEquals(spacerText, "Space");
    column.click();
    spacer.click();
    a.keyDown(Keys.SHIFT).sendKeys("d").keyUp(Keys.SHIFT).build().perform();
    spacer = this.elemHelper.WaitForElementPresenceAndVisible(driver,
            By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr[4]/td"));
    assertNotNull(spacer);
    WebElement spacer2 = this.elemHelper.WaitForElementPresenceAndVisible(driver,
            By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr[5]/td"));
    assertNotNull(spacer2);
    this.elemHelper.WaitForTextPresence(driver,
            By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr[4]/td"), "Space");
    spacerText = spacer.getText();
    assertEquals(spacerText, "Space");
    this.elemHelper.WaitForTextPresence(driver,
            By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr[5]/td"), "Space");
    String spacerText2 = spacer2.getText();
    assertEquals(spacerText2, "Space");

    //Delete elements and assert they are no longer present
    this.elemHelper.Click(driver, By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr/td"));
    a.keyDown(Keys.SHIFT).sendKeys("x").keyUp(Keys.SHIFT).build().perform();
    assertTrue(this.elemHelper.WaitForElementNotPresent(driver,
            By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr/td")));

    /*
     * ## Step 3
     */
    //Add elements
    WebElement addRow = this.elemHelper.WaitForElementPresenceAndVisible(driver,
            By.xpath("//a[@title='Add Row']"));
    assertNotNull(addRow);
    addRow.click();
    WebElement addColumn = this.elemHelper.WaitForElementPresenceAndVisible(driver,
            By.xpath("//a[@title='Add Columns']"));
    WebElement addFreeForm = this.elemHelper.WaitForElementPresenceAndVisible(driver,
            By.xpath("//a[@title='Add FreeForm']"));
    WebElement addBootstrap = this.elemHelper.WaitForElementPresenceAndVisible(driver,
            By.xpath("//a[@title='Add Bootstrap Panel']"));
    assertNotNull(addFreeForm);
    assertNotNull(addColumn);
    assertNotNull(addBootstrap);
    this.elemHelper.WaitForElementPresenceAndVisible(driver, By.xpath("//a[@title='Add Bootstrap Panel']"))
            .click();
    this.elemHelper.WaitForElementPresenceAndVisible(driver, By.xpath("//a[@title='Add Row']")).click();
    this.elemHelper.WaitForElementPresenceAndVisible(driver, By.xpath("//a[@title='Add FreeForm']")).click();
    this.elemHelper.WaitForElementPresenceAndVisible(driver, By.xpath("//a[@title='Add Row']")).click();
    this.elemHelper.WaitForElementPresenceAndVisible(driver, By.xpath("//a[@title='Add Columns']")).click();
    this.elemHelper.WaitForElementPresenceAndVisible(driver, By.xpath("//a[@title='Add Columns']")).click();
    this.elemHelper.WaitForElementPresenceAndVisible(driver, By.xpath("//a[@title='Add FreeForm']")).click();

    //Assert elements on Layout
    String row1 = this.elemHelper.WaitForTextPresence(driver,
            By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr/td"), "Row");
    assertEquals("Row", row1);
    String bootstrap = this.elemHelper.WaitForTextPresence(driver,
            By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr[2]/td"), "Bootstrap Panel");
    assertEquals("Bootstrap Panel", bootstrap);
    String row2 = this.elemHelper.WaitForTextPresence(driver,
            By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr[6]/td"), "Row");
    assertEquals("Row", row2);
    String freeform1 = this.elemHelper.WaitForTextPresence(driver,
            By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr[7]/td"), "FreeForm");
    assertEquals("FreeForm", freeform1);
    String row3 = this.elemHelper.WaitForTextPresence(driver,
            By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr[8]/td"), "Row");
    assertEquals("Row", row3);
    String column1 = this.elemHelper.WaitForTextPresence(driver,
            By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr[9]/td"), "Column");
    assertEquals("Column", column1);
    String column2 = this.elemHelper.WaitForTextPresence(driver,
            By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr[10]/td"), "Column");
    assertEquals("Column", column2);
    String freeform2 = this.elemHelper.WaitForTextPresence(driver,
            By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr[11]/td"), "FreeForm");
    assertEquals("FreeForm", freeform2);

    //Assert bootstrap and freeform are parent elements
    String bootstrapClass = this.elemHelper.GetAttribute(driver,
            By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr[2]"), "class");
    assertTrue(bootstrapClass.contains("parent"));
    String freeformClass = this.elemHelper.GetAttribute(driver,
            By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr[7]"), "class");
    assertTrue(freeformClass.contains("parent"));

    //Move elements
    this.elemHelper.DragAndDrop(driver, By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr[11]/td"),
            By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr[1]/td"));
    this.elemHelper.DragAndDrop(driver, By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr[8]/td"),
            By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr[2]/td"));

    //Assert new positions
    freeform1 = this.elemHelper.WaitForTextPresence(driver,
            By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr/td"), "FreeForm");
    assertEquals("FreeForm", freeform1);
    freeform2 = this.elemHelper.WaitForTextPresence(driver,
            By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr[2]/td"), "FreeForm");
    assertEquals("FreeForm", freeform2);
    row1 = this.elemHelper.WaitForTextPresence(driver,
            By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr[3]/td"), "Row");
    assertEquals("Row", row1);
    column1 = this.elemHelper.WaitForTextPresence(driver,
            By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr[4]/td"), "Column");
    assertEquals("Column", column1);
    column2 = this.elemHelper.WaitForTextPresence(driver,
            By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr[5]/td"), "Column");
    assertEquals("Column", column2);
    row2 = this.elemHelper.WaitForTextPresence(driver,
            By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr[6]/td"), "Row");
    assertEquals("Row", row2);
    bootstrap = this.elemHelper.WaitForTextPresence(driver,
            By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr[7]/td"), "Bootstrap Panel");
    assertEquals("Bootstrap Panel", bootstrap);
    row3 = this.elemHelper.WaitForTextPresence(driver,
            By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr[11]/td"), "Row");
    assertEquals("Row", row3);

    /*
     * ## Step 4
     */
    //Apply template

    WebElement templateButton = this.elemHelper.WaitForElementPresenceAndVisible(driver,
            By.xpath("//a[@title='Apply Template']"));
    assertNotNull(templateButton);
    templateButton.click();
    this.elemHelper.WaitForFrameReady(driver, By.id("popup"));
    WebElement templatePopup = this.elemHelper.WaitForElementPresenceAndVisible(driver, By.id("popup"));
    assertNotNull(templatePopup);
    String templateText = this.elemHelper
            .FindElement(driver, By.xpath("//div[@class='template-scroll']/div[2]/span")).getText();
    assertEquals("2 Columns Template", templateText);
    this.elemHelper.Click(driver, By.xpath("//div[@class='template-scroll']/div[2]/div/img"));
    WebElement templateOk = this.elemHelper.WaitForElementPresenceAndVisible(driver,
            By.id("popup_state0_buttonOk"));
    assertNotNull(templateOk);
    this.elemHelper.Click(driver, By.id("popup_state0_buttonOk"));
    assertTrue(this.elemHelper.WaitForElementNotPresent(driver, By.id("popup")));
    WebElement confirmationPopup = this.elemHelper.WaitForElementPresenceAndVisible(driver, By.id("popup"));
    assertNotNull(confirmationPopup);
    String warningText = this.elemHelper.WaitForElementPresentGetText(driver,
            By.xpath("//div[@class='popup-body-container layout-popup']"));
    assertEquals("Are you sure you want to load the template?WARNING: Dashboard Layout will be overwritten!",
            warningText);
    WebElement confirmationOk = this.elemHelper.WaitForElementPresenceAndVisible(driver,
            By.id("popup_state0_buttonOk"));
    assertNotNull(confirmationOk);
    this.elemHelper.Click(driver, By.id("popup_state0_buttonOk"));
    this.elemHelper.WaitForElementNotPresent(driver, By.id("popup"));

    //Asset elements were created
    String trtdText = this.elemHelper.WaitForTextPresence(driver,
            By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr/td"), "Row");
    String trtd2Text = this.elemHelper.WaitForTextPresence(driver,
            By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr/td[2]"), "Header");
    String tr4tdText = this.elemHelper.WaitForTextPresence(driver,
            By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr[4]/td"), "Row");
    String tr4td2Text = this.elemHelper.WaitForTextPresence(driver,
            By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr[4]/td[2]"), "Spacer");
    assertEquals("Row", trtdText);
    assertEquals("Header", trtd2Text);
    assertEquals("Row", tr4tdText);
    assertEquals("Spacer", tr4td2Text);

    /*
     * ## Step 5
     */
    //Press down and assert second Row is selected
    this.elemHelper.Click(driver, By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr/td"));
    String firstRowClass = this.elemHelper
            .FindElement(driver, By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr"))
            .getAttribute("class");
    assertEquals(firstRowClass, "ui-draggable ui-droppable initialized parent collapsed ui-state-active");
    a.sendKeys(Keys.DOWN).build().perform();
    this.elemHelper.WaitForAttributeValue(driver,
            By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr[4]"), "class",
            "ui-draggable ui-droppable initialized ui-state-active");
    String secondRowClass = this.elemHelper.WaitForElementPresenceAndVisible(driver,
            By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr[4]")).getAttribute("class");
    assertEquals(secondRowClass, "ui-draggable ui-droppable initialized ui-state-active");

    //Assert columns aren't visible, go to row and expand it and then assert columns are visible
    this.elemHelper.WaitForElementInvisibility(driver,
            By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr[6]"));
    this.elemHelper.WaitForElementInvisibility(driver,
            By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr[7]"));

    a.sendKeys(Keys.DOWN).sendKeys(Keys.RIGHT).build().perform();
    WebElement firstColumn = this.elemHelper.WaitForElementPresenceAndVisible(driver,
            By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr[6]"));
    assertNotNull(firstColumn);
    WebElement secondColumn = this.elemHelper.WaitForElementPresenceAndVisible(driver,
            By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr[7]"));
    assertNotNull(secondColumn);

    //Go to second column and back to first and assert first column is selected
    a.sendKeys(Keys.DOWN).sendKeys(Keys.DOWN).sendKeys("c").sendKeys(Keys.TAB).build().perform();
    this.elemHelper.WaitForAttributeValue(driver,
            By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr[8]"), "class", "ui-state-active");
    String firstColumnClass = this.elemHelper
            .FindElement(driver, By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr[8]"))
            .getAttribute("class");
    assertTrue(firstColumnClass.contains("ui-state-active"));

    //Click tab key and assert focus has changed to properties table
    a.sendKeys(Keys.TAB).build().perform();
    this.elemHelper.WaitForAttributeValue(driver,
            By.xpath("//table[@id='table-cdfdd-layout-properties']/tbody/tr"), "class",
            "initialized ui-state-active");
    String firstPropertyClass = this.elemHelper
            .FindElement(driver, By.xpath("//table[@id='table-cdfdd-layout-properties']/tbody/tr"))
            .getAttribute("class");
    assertEquals(firstPropertyClass, "initialized ui-state-active");

    //Click enter to change following properties "Name", "Span size" and "Right border"
    a.sendKeys(Keys.ENTER).sendKeys("a").sendKeys(Keys.ENTER).sendKeys(Keys.DOWN).build().perform();

    //assert name has changed
    String columnName = this.elemHelper.WaitForElementPresentGetText(driver,
            By.xpath("//table[@id='table-cdfdd-layout-properties']/tbody/tr/td[2]"));
    assertEquals(columnName, "a");

    //Change "Extra Small Devices" and "Text Align"
    this.elemHelper.WaitForAttributeValue(driver,
            By.xpath("//table[@id='table-cdfdd-layout-properties']/tbody/tr[2]"), "class",
            "initialized ui-state-active");
    String xsInput = this.elemHelper
            .FindElement(driver, By.xpath("//table[@id='table-cdfdd-layout-properties']/tbody/tr[2]"))
            .getAttribute("class");
    assertEquals(xsInput, "initialized ui-state-active");
    a.sendKeys(Keys.ENTER).build().perform();
    this.elemHelper
            .FindElement(driver,
                    By.xpath("//table[@id='table-cdfdd-layout-properties']/tbody/tr[2]/td[2]/form/input"))
            .clear();
    a.sendKeys(Keys.ENTER).build().perform();

    //assert values are changed
    String xsValue = this.elemHelper.WaitForElementPresentGetText(driver,
            By.xpath("//table[@id='table-cdfdd-layout-properties']/tbody/tr[2]/td[2]"));
    assertEquals(xsValue, "-");

    a.sendKeys(Keys.DOWN).sendKeys(Keys.DOWN).sendKeys(Keys.DOWN).sendKeys(Keys.DOWN).sendKeys(Keys.DOWN)
            .sendKeys(Keys.DOWN).sendKeys(Keys.DOWN).sendKeys(Keys.DOWN).sendKeys(Keys.ENTER)
            .sendKeys(Keys.DOWN).sendKeys(Keys.DOWN).sendKeys(Keys.ENTER).sendKeys(Keys.ENTER).build()
            .perform();
    String alignValue = this.elemHelper.WaitForElementPresentGetText(driver,
            By.xpath("//table[@id='table-cdfdd-layout-properties']/tbody/tr[10]/td[2]"));
    assertEquals(alignValue, "Left");
    //Click tab and assert focus has gone back to first table
    a.sendKeys(Keys.TAB).build().perform();
    this.elemHelper.WaitForAttributeValue(driver,
            By.xpath("//table[@id='table-cdfdd-layout-properties']/tbody/tr[8]"), "class", "initialized");
    String columnClass = this.elemHelper
            .FindElement(driver, By.xpath("//table[@id='table-cdfdd-layout-properties']/tbody/tr[8]"))
            .getAttribute("class");
    assertEquals(columnClass, "initialized");

    //Collapse Row and assert columns aren't showing
    a.sendKeys(Keys.UP).sendKeys(Keys.UP).sendKeys(Keys.UP).sendKeys(Keys.LEFT).build().perform();
    this.elemHelper.WaitForElementInvisibility(driver,
            By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr[6]"));
    this.elemHelper.WaitForElementInvisibility(driver,
            By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr[7]"));
    this.elemHelper.WaitForElementInvisibility(driver,
            By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr[8]"));

    /*
     * ## Step 6
     */
    //Save Dashboard
    WebElement saveDashboard = this.elemHelper.WaitForElementPresenceAndVisible(driver,
            By.xpath("//div[@id='headerLinks']//a[@id='Save']"));
    assertNotNull(saveDashboard);
    saveDashboard.click();
    WebElement folderSelector = this.elemHelper.WaitForElementPresenceAndVisible(driver,
            By.xpath("//div[@id='saveAsFEContainer']//a[@rel='public/']"));
    assertNotNull(folderSelector);
    folderSelector.click();
    WebElement inputName = this.elemHelper.WaitForElementPresenceAndVisible(driver, By.id("fileInput"));
    assertNotNull(inputName);
    inputName.sendKeys("CDE366");
    WebElement okButton = this.elemHelper.WaitForElementPresenceAndVisible(driver,
            By.xpath("//div[@class='popupbuttons']/button[@id='popup_state0_buttonOk']"));
    okButton.click();
    this.elemHelper.WaitForElementNotPresent(driver, By.xpath("//div[@class='popupbuttons']"));
    WebElement title = this.elemHelper.WaitForElementPresenceAndVisible(driver,
            By.xpath("//div[@title='CDE366']"));
    assertNotNull(title);
    this.failure = 0;

    //Open Dashboard Settings
    settingsLink = this.elemHelper.WaitForElementPresenceAndVisible(driver,
            By.xpath("//div[@id='headerLinks']//a[@onclick='cdfdd.saveSettings()']"));
    assertNotNull(settingsLink);
    settingsLink.click();
    settingsPopup = this.elemHelper.WaitForElementPresenceAndVisible(driver,
            By.xpath("//div[@id='popup']//div[@id='popupstates']"));
    assertNotNull(settingsPopup);

    //Edit Style and Dashboard Type
    Select style = new Select(this.elemHelper.WaitForElementPresenceAndVisible(driver, By.id("styleInput")));
    style.selectByVisibleText("WDDocs");
    Select dashType = new Select(
            this.elemHelper.WaitForElementPresenceAndVisible(driver, By.id("rendererInput")));
    dashType.selectByVisibleText("blueprint");

    //Click save and assert user gets a message of "Saved Successfully"
    okButton = this.elemHelper.WaitForElementPresenceAndVisible(driver, By.id("popup_state0_buttonOk"));
    assertNotNull(okButton);
    okButton.click();
    WebElement notifySuccess = this.elemHelper.WaitForElementPresenceAndVisible(driver,
            By.xpath("//div[@id='notifyBar']"));
    assertNotNull(notifySuccess);
    String successMessage = this.elemHelper.WaitForElementPresentGetText(driver,
            By.xpath("//div[@id='notifyBar']/div[@class='notify-bar-message']"));
    assertEquals("Dashboard Settings saved successfully", successMessage);

    //Open dashboard in preview mode
    this.elemHelper.Get(driver, PageUrl.ISSUES_CDE_366);
    this.elemHelper.WaitForElementInvisibility(driver, By.cssSelector("div.blockUI.blockOverlay"));

    //Assert Xs is set to 12 as default
    WebElement xsColumn = this.elemHelper.FindElement(driver, By.xpath("//div[@id='Body']/div[3]"));
    assertNotNull(xsColumn);
    String xsNumber = xsColumn.getAttribute("class");
    assertEquals("col-xs-12 last", xsNumber);

    //Open dashboard in edit
    this.elemHelper.Get(driver, PageUrl.ISSUES_CDE_366_EDIT);

    //Open Settings and assert Style and Dashboard Type were saved 
    settingsLink = this.elemHelper.WaitForElementPresenceAndVisible(driver,
            By.xpath("//div[@id='headerLinks']//a[@onclick='cdfdd.saveSettings()']"));
    assertNotNull(settingsLink);
    settingsLink.click();
    settingsPopup = this.elemHelper.WaitForElementPresenceAndVisible(driver,
            By.xpath("//div[@id='popup']//div[@id='popupstates']"));
    assertNotNull(settingsPopup);
    WebElement selectedStyle = this.elemHelper.WaitForElementPresenceAndVisible(driver,
            By.xpath("//select[@id='styleInput']/option[@selected='']"));
    String selectedValue = selectedStyle.getAttribute("value");
    assertEquals("WDDocs", selectedValue);
    WebElement selectedDash = this.elemHelper.WaitForElementPresenceAndVisible(driver,
            By.xpath("//select[@id='rendererInput']/option[@selected='']"));
    selectedValue = selectedDash.getAttribute("value");
    assertEquals("blueprint", selectedValue);

    /*
     * ## Step 7
     */
    BrowseFiles browse = new BrowseFiles(driver);
    browse.DeleteMultipleFilesByName("/public", "CDE366");
    browse.EmptyTrash();
    this.failure = 1;
}

From source file:com.pentaho.gui.web.puc.BrowseFiles.java

License:Apache License

/**
 * This method will empty a folder in the repository given the full path to it, including the folder name
 *
 * Ex. "/public/plugin-samples/pentaho-cdf-dd" the SelectFolder method will be called with the path provided, it it
 * returns false an info will be shown on the logs saying the file wasn't deleted for it wasn't found. If it returns
 * true, all files shown on the files table will be selected, Delete button will be clicked on File Actions, it will
 * wait for popup and confirm the delete action.
 *
 * @param path/*from   w ww .  j a  v a2  s  .  c  o  m*/
 */
public void EmptyFolder(String path) {
    if (SelectFolder(path)) {
        WebElement listFiles = this.elemHelper.WaitForElementPresenceAndVisible(this.DRIVER,
                By.xpath("//div[@id='fileBrowserFiles']/div[2]"));
        List<WebElement> AllFolderFiles = listFiles.findElements(By.xpath("//div[@class='title']"));

        // Check if the widget named exist
        if (AllFolderFiles != null) {
            if (AllFolderFiles.size() > 0) {
                WebElement[] arrayAllFolderFiles = new WebElement[AllFolderFiles.size()];
                AllFolderFiles.toArray(arrayAllFolderFiles);

                // Where we want to select three files
                // <the widget>
                // <the widget>.cdfde
                // <the widget>.component.xml
                // To do that we select each file (using the CONTROL key) and delete them.
                Actions action = new Actions(this.DRIVER);
                action.keyDown(Keys.CONTROL);
                for (WebElement arrayAllFolderFile : arrayAllFolderFiles) {
                    action.click(arrayAllFolderFile);
                }
                action.keyUp(Keys.CONTROL);
                action.build().perform();

                // Here we still in the iframe
                assertNotNull(this.elemHelper.WaitForElementVisibility(this.DRIVER, By.id("deleteButton")));
                this.elemHelper.WaitForElementPresenceAndVisible(this.DRIVER, By.id("deleteButton")).click();
                // Go back to root html
                this.DRIVER.switchTo().defaultContent();
                assertEquals(this.elemHelper
                        .WaitForElementPresenceAndVisible(this.DRIVER, By.cssSelector("div.gwt-HTML"))
                        .getText(), "Are you sure you want to move all selected items to the trash?");
                this.elemHelper.WaitForElementPresenceAndVisible(this.DRIVER, By.id("okButton")).click();

                // wait for visibility of waiting pop-up
                this.elemHelper.WaitForElementInvisibility(this.DRIVER,
                        By.xpath("//div[@class='busy-indicator-container waitPopup']"));

                this.elemHelper.WaitForElementInvisibility(this.DRIVER,
                        By.xpath("//div[@class='spinner large-spinner']"));
                this.elemHelper.WaitForElementInvisibility(this.DRIVER,
                        By.xpath("(//div[@class='spinner large-spinner'])[2]"));

            }
        }
    } else {
        LOG.info("folder not emptied for it was not found");
    }
}

From source file:com.pentaho.gui.web.puc.BrowseFiles.java

License:Apache License

/**
 * Given the path to a folder this method will delete all files located in that folder that contain a specific string
 * in the name/*ww  w .j a v a2s.co  m*/
 *
 * Ex. "/public/plugin-samples/pentaho-cdf-dd" the SelectFolder method will be called with the path provided, it it
 * returns false an info will be shown on the logs saying the file wasn't deleted for it wasn't found.
 *
 * If it returns true, all files containing string "name" provided in the name will be selected, Delete button will be
 * clicked on File Actions, it will wait for popup and confirm the delete action.
 *
 * @param path
 * @param name
 */
public void DeleteMultipleFilesByName(String path, String name) {
    LOG.debug("DeleteMultipleFilesByName::Enter");
    if (SelectFolder(path)) {
        LOG.debug("Deleting [" + path + "] with name [" + name + "]");

        WebElement elemWidgetFile = this.elemHelper.WaitForElementPresence(this.DRIVER,
                By.cssSelector("div[title='" + name + ".wcdf']"), 1);
        if (elemWidgetFile != null) {
            WebElement listFiles = this.elemHelper.WaitForElementPresenceAndVisible(this.DRIVER,
                    By.xpath("//div[@id='fileBrowserFiles']/div[2]"));
            List<WebElement> theNamedFiles = listFiles
                    .findElements(By.xpath("//div[@class='title' and contains(text(),'" + name + "')]"));

            // Check if the widget named exist
            if (theNamedFiles != null) {
                if (theNamedFiles.size() > 0) {
                    WebElement[] arraytheNamedFiles = new WebElement[theNamedFiles.size()];
                    theNamedFiles.toArray(arraytheNamedFiles);

                    // Where we want to select three files
                    // <the widget>
                    // <the widget>.cdfde
                    // <the widget>.component.xml
                    // To do that we select each file (using the CONTROL key) and delete them.
                    Actions action = new Actions(this.DRIVER);
                    action.keyDown(Keys.CONTROL);
                    for (WebElement arraytheNamedFile : arraytheNamedFiles) {
                        action.click(arraytheNamedFile);
                    }
                    action.keyUp(Keys.CONTROL);
                    action.build().perform();

                    // Here we still in the iframe
                    assertNotNull(this.elemHelper.WaitForElementVisibility(this.DRIVER, By.id("deleteButton")));
                    this.elemHelper.WaitForElementPresenceAndVisible(this.DRIVER, By.id("deleteButton"))
                            .click();
                    // Go back to root html
                    this.DRIVER.switchTo().defaultContent();
                    assertEquals(
                            this.elemHelper.WaitForElementPresenceAndVisible(this.DRIVER,
                                    By.cssSelector("div.gwt-HTML")).getText(),
                            "Are you sure you want to move all selected items to the trash?");
                    this.elemHelper.WaitForElementPresenceAndVisible(this.DRIVER, By.id("okButton")).click();

                    // wait for visibility of waiting pop-up
                    this.elemHelper.WaitForElementInvisibility(this.DRIVER,
                            By.xpath("//div[@class='busy-indicator-container waitPopup']"));

                    assertNotNull(this.elemHelper.WaitForElementPresenceAndVisible(this.DRIVER,
                            By.id("applicationShell")));
                    assertNotNull(this.elemHelper.WaitForElementPresenceAndVisible(this.DRIVER,
                            By.xpath("//iframe[@id='browser.perspective']")));
                    this.DRIVER.switchTo().frame("browser.perspective");

                    assertNotNull(this.elemHelper.WaitForElementPresenceAndVisible(this.DRIVER,
                            By.id("fileBrowser")));
                    this.elemHelper.WaitForElementInvisibility(this.DRIVER,
                            By.xpath("//div[@class='spinner large-spinner']"));
                    this.elemHelper.WaitForElementInvisibility(this.DRIVER,
                            By.xpath("(//div[@class='spinner large-spinner'])[2]"));

                    this.elemHelper.Click(this.DRIVER, By.id("refreshBrowserIcon"));
                    this.elemHelper.WaitForElementInvisibility(this.DRIVER,
                            By.xpath("//div[@class='spinner large-spinner']"));
                    this.elemHelper.WaitForElementInvisibility(this.DRIVER,
                            By.xpath("(//div[@class='spinner large-spinner'])[2]"));

                    // Assert Panels
                    assertNotNull(this.elemHelper.WaitForElementPresenceAndVisible(this.DRIVER,
                            By.xpath("//div[@id='fileBrowserFolders']")));
                    assertNotNull(this.elemHelper.WaitForElementPresenceAndVisible(this.DRIVER,
                            By.xpath("//div[@id='fileBrowserFiles']")));
                    assertNotNull(this.elemHelper.WaitForElementPresenceAndVisible(this.DRIVER,
                            By.xpath("//div[@id='fileBrowserButtons']")));
                    LOG.info("Exit: Assert browser perspective shown");
                } else {
                    LOG.debug("No file exist!");
                }
            } else {
                LOG.debug("Null - No file exist!");
            }
        } else {
            LOG.warn("The widget does not exist.");
        }
    } else {
        LOG.info("Files were not deleted or folder was not found!");
    }
}

From source file:com.stratio.qa.specs.CommonG.java

License:Apache License

/**
 * Capture a snapshot or an evidence in the driver
 *
 * @param driver driver used for testing
 * @param type type//  w  ww  .j  a  va2  s  . co  m
 * @param suffix suffix
 * @return String
 */
public String captureEvidence(WebDriver driver, String type, String suffix) {
    String testSuffix = System.getProperty("TESTSUFFIX");
    String dir = "./target/executions/";
    if (testSuffix != null) {
        dir = dir + testSuffix + "/";
    }

    String clazz = ThreadProperty.get("class");
    String currentBrowser = ThreadProperty.get("browser");
    String currentData = ThreadProperty.get("dataSet");

    if (!currentData.equals("")) {
        currentData = currentData.replaceAll("[\\\\|\\/|\\|\\s|:|\\*]", "_");
    }

    if (!"".equals(currentData)) {
        currentData = "-" + HashUtils.doHash(currentData);
    }

    Timestamp ts = new Timestamp(new java.util.Date().getTime());
    String outputFile = dir + clazz + "/" + ThreadProperty.get("feature") + "." + ThreadProperty.get("scenario")
            + "/" + currentBrowser + currentData + ts.toString() + suffix;

    outputFile = outputFile.replaceAll(" ", "_");

    if (type.endsWith("htmlSource")) {
        if (type.equals("framehtmlSource")) {
            boolean isFrame = (Boolean) ((JavascriptExecutor) driver)
                    .executeScript("return window.top != window.self");

            if (isFrame) {
                outputFile = outputFile + "frame.html";
            } else {
                outputFile = "";
            }
        } else if (type.equals("htmlSource")) {
            driver.switchTo().defaultContent();
            outputFile = outputFile + ".html";
        }

        if (!outputFile.equals("")) {
            String source = ((RemoteWebDriver) driver).getPageSource();

            File fout = new File(outputFile);
            boolean dirs = fout.getParentFile().mkdirs();

            FileOutputStream fos;
            try {
                fos = new FileOutputStream(fout, true);
                Writer out = new OutputStreamWriter(fos, "UTF8");
                PrintWriter writer = new PrintWriter(out, false);
                writer.append(source);
                writer.close();
                out.close();
            } catch (IOException e) {
                logger.error("Exception on evidence capture", e);
            }
        }

    } else if ("screenCapture".equals(type)) {
        outputFile = outputFile + ".png";
        File file = null;
        driver.switchTo().defaultContent();
        ((Locatable) driver.findElement(By.tagName("body"))).getCoordinates().inViewPort();

        if (currentBrowser.startsWith("chrome") || currentBrowser.startsWith("droidemu")) {
            Actions actions = new Actions(driver);
            actions.keyDown(Keys.CONTROL).sendKeys(Keys.HOME).perform();
            actions.keyUp(Keys.CONTROL).perform();

            file = chromeFullScreenCapture(driver);
        } else {
            file = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
        }
        try {
            FileUtils.copyFile(file, new File(outputFile));
        } catch (IOException e) {
            logger.error("Exception on copying browser screen capture", e);
        }
    }

    return outputFile;

}

From source file:com.vaadin.testbench.TestBenchElement.java

@Override
public void click(int x, int y, Keys... modifiers) {
    waitForVaadin();// ww w . j ava 2  s  . co m
    Actions actions = new Actions(getCommandExecutor().getWrappedDriver());
    actions.moveToElement(actualElement, x, y);
    // Press any modifier keys
    for (Keys modifier : modifiers) {
        actions.keyDown(modifier);
    }
    actions.click();
    // Release any modifier keys
    for (Keys modifier : modifiers) {
        actions.keyUp(modifier);
    }
    actions.build().perform();
}

From source file:io.github.blindio.prospero.core.browserdrivers.WebDriverDriver.java

License:Apache License

public void shiftClick(String locator) {
    WebElement element = getWebDriver().findElement(BySeleneseLocator.seleneseLocator(locator));
    Actions builder = new Actions(getWebDriver());
    builder.keyDown(Keys.SHIFT).click(element).keyUp(Keys.SHIFT).build().perform();
}

From source file:org.auraframework.integration.test.util.WebDriverTestCase.java

License:Apache License

public Action shiftTab() {
    Actions builder = new Actions(getDriver());
    builder.keyDown(Keys.SHIFT).sendKeys(Keys.TAB).keyUp(Keys.SHIFT);
    return builder.build();
}