Example usage for org.openqa.selenium Keys SHIFT

List of usage examples for org.openqa.selenium Keys SHIFT

Introduction

In this page you can find the example usage for org.openqa.selenium Keys SHIFT.

Prototype

Keys SHIFT

To view the source code for org.openqa.selenium Keys SHIFT.

Click Source Link

Usage

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 a 2 s.c  o m
 *    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.screenslicer.core.util.BrowserUtil.java

License:Open Source License

public static boolean click(Browser browser, WebElement toClick, boolean shift) {
    try {/*from  w ww.  j ava2s.  c o m*/
        Actions action = new Actions(browser);
        action.moveToElement(toClick).perform();
        if (shift) {
            browser.getKeyboard().pressKey(Keys.SHIFT);
        }
        toClick.click();
        if (shift) {
            browser.getKeyboard().releaseKey(Keys.SHIFT);
        }
    } catch (Browser.Retry r) {
        throw r;
    } catch (Browser.Fatal f) {
        throw f;
    } catch (Throwable t) {
        return false;
    }
    return true;
}

From source file:com.screenslicer.core.util.Util.java

License:Open Source License

private static boolean click(RemoteWebDriver driver, WebElement toClick, boolean shift) {
    try {//from  ww w. ja  va  2 s .c  o  m
        Actions action = new Actions(driver);
        driverSleepVeryShort();
        action.moveToElement(toClick).perform();
        if (shift) {
            driver.getKeyboard().pressKey(Keys.SHIFT);
        }
        toClick.click();
        if (shift) {
            driver.getKeyboard().releaseKey(Keys.SHIFT);
        }
        Util.driverSleepVeryShort();
    } catch (Throwable t) {
        return false;
    }
    return true;
}

From source file:com.thoughtworks.selenium.webdriven.commands.SendKeys.java

License:Apache License

@Override
protected Void handleSeleneseCommand(WebDriver driver, String locator, String value) {
    alertOverride.replaceAlertMethod(driver);

    value = value.replace("${KEY_ALT}", Keys.ALT);
    value = value.replace("${KEY_CONTROL}", Keys.CONTROL);
    value = value.replace("${KEY_CTRL}", Keys.CONTROL);
    value = value.replace("${KEY_META}", Keys.META);
    value = value.replace("${KEY_COMMAND}", Keys.COMMAND);
    value = value.replace("${KEY_SHIFT}", Keys.SHIFT);

    value = value.replace("${KEY_BACKSPACE}", Keys.BACK_SPACE);
    value = value.replace("${KEY_BKSP}", Keys.BACK_SPACE);
    value = value.replace("${KEY_DELETE}", Keys.DELETE);
    value = value.replace("${KEY_DEL}", Keys.DELETE);
    value = value.replace("${KEY_ENTER}", Keys.ENTER);
    value = value.replace("${KEY_EQUALS}", Keys.EQUALS);
    value = value.replace("${KEY_ESCAPE}", Keys.ESCAPE);
    value = value.replace("${KEY_ESC}", Keys.ESCAPE);
    value = value.replace("${KEY_INSERT}", Keys.INSERT);
    value = value.replace("${KEY_INS}", Keys.INSERT);
    value = value.replace("${KEY_PAUSE}", Keys.PAUSE);
    value = value.replace("${KEY_SEMICOLON}", Keys.SEMICOLON);
    value = value.replace("${KEY_SPACE}", Keys.SPACE);
    value = value.replace("${KEY_TAB}", Keys.TAB);

    value = value.replace("${KEY_LEFT}", Keys.LEFT);
    value = value.replace("${KEY_UP}", Keys.UP);
    value = value.replace("${KEY_RIGHT}", Keys.RIGHT);
    value = value.replace("${KEY_DOWN}", Keys.DOWN);
    value = value.replace("${KEY_PAGE_UP}", Keys.PAGE_UP);
    value = value.replace("${KEY_PGUP}", Keys.PAGE_UP);
    value = value.replace("${KEY_PAGE_DOWN}", Keys.PAGE_DOWN);
    value = value.replace("${KEY_PGDN}", Keys.PAGE_DOWN);
    value = value.replace("${KEY_END}", Keys.END);
    value = value.replace("${KEY_HOME}", Keys.HOME);

    value = value.replace("${KEY_NUMPAD0}", Keys.NUMPAD0);
    value = value.replace("${KEY_N0}", Keys.NUMPAD0);
    value = value.replace("${KEY_NUMPAD1}", Keys.NUMPAD1);
    value = value.replace("${KEY_N1}", Keys.NUMPAD1);
    value = value.replace("${KEY_NUMPAD2}", Keys.NUMPAD2);
    value = value.replace("${KEY_N2}", Keys.NUMPAD2);
    value = value.replace("${KEY_NUMPAD3}", Keys.NUMPAD3);
    value = value.replace("${KEY_N3}", Keys.NUMPAD3);
    value = value.replace("${KEY_NUMPAD4}", Keys.NUMPAD4);
    value = value.replace("${KEY_N4}", Keys.NUMPAD4);
    value = value.replace("${KEY_NUMPAD5}", Keys.NUMPAD5);
    value = value.replace("${KEY_N5}", Keys.NUMPAD5);
    value = value.replace("${KEY_NUMPAD6}", Keys.NUMPAD6);
    value = value.replace("${KEY_N6}", Keys.NUMPAD6);
    value = value.replace("${KEY_NUMPAD7}", Keys.NUMPAD7);
    value = value.replace("${KEY_N7}", Keys.NUMPAD7);
    value = value.replace("${KEY_NUMPAD8}", Keys.NUMPAD8);
    value = value.replace("${KEY_N8}", Keys.NUMPAD8);
    value = value.replace("${KEY_NUMPAD9}", Keys.NUMPAD9);
    value = value.replace("${KEY_N9}", Keys.NUMPAD9);
    value = value.replace("${KEY_ADD}", Keys.ADD);
    value = value.replace("${KEY_NUM_PLUS}", Keys.ADD);
    value = value.replace("${KEY_DECIMAL}", Keys.DECIMAL);
    value = value.replace("${KEY_NUM_PERIOD}", Keys.DECIMAL);
    value = value.replace("${KEY_DIVIDE}", Keys.DIVIDE);
    value = value.replace("${KEY_NUM_DIVISION}", Keys.DIVIDE);
    value = value.replace("${KEY_MULTIPLY}", Keys.MULTIPLY);
    value = value.replace("${KEY_NUM_MULTIPLY}", Keys.MULTIPLY);
    value = value.replace("${KEY_SEPARATOR}", Keys.SEPARATOR);
    value = value.replace("${KEY_SEP}", Keys.SEPARATOR);
    value = value.replace("${KEY_SUBTRACT}", Keys.SUBTRACT);
    value = value.replace("${KEY_NUM_MINUS}", Keys.SUBTRACT);

    value = value.replace("${KEY_F1}", Keys.F1);
    value = value.replace("${KEY_F2}", Keys.F2);
    value = value.replace("${KEY_F3}", Keys.F3);
    value = value.replace("${KEY_F4}", Keys.F4);
    value = value.replace("${KEY_F5}", Keys.F5);
    value = value.replace("${KEY_F6}", Keys.F6);
    value = value.replace("${KEY_F7}", Keys.F7);
    value = value.replace("${KEY_F8}", Keys.F8);
    value = value.replace("${KEY_F9}", Keys.F9);
    value = value.replace("${KEY_F10}", Keys.F10);
    value = value.replace("${KEY_F11}", Keys.F11);
    value = value.replace("${KEY_F12}", Keys.F12);

    finder.findElement(driver, locator).sendKeys(value);

    return null;//from  www  .  java  2s.com
}

From source file:com.vaadin.tests.components.grid.basicfeatures.server.GridEditorUnbufferedTest.java

License:Apache License

@Test
public void testEditorMoveWithKeyboard() throws InterruptedException {
    selectMenuPath(EDIT_ITEM_100);//from ww w  .  j av a  2  s .c o m

    assertEditorOpen();

    getEditorWidgets().get(0).click();
    new Actions(getDriver()).sendKeys(Keys.ENTER).perform();

    String firstFieldValue = getEditorWidgets().get(0).getAttribute("value");
    assertEquals("Editor should move to row 101", "(101, 0)", firstFieldValue);

    for (int i = 0; i < 10; i++) {
        new Actions(getDriver()).keyDown(Keys.SHIFT).sendKeys(Keys.ENTER).keyUp(Keys.SHIFT).perform();

        firstFieldValue = getEditorWidgets().get(0).getAttribute("value");
        int row = 100 - i;
        assertEquals("Editor should move to row " + row, "(" + row + ", 0)", firstFieldValue);
    }
}

From source file:com.vaadin.tests.components.grid.basicfeatures.server.GridKeyboardNavigationTest.java

License:Apache License

@Test
public void testNavigateBetweenHeaderAndBodyWithTab() {
    openTestURL();//from w  w w.ja v a 2  s  . c om

    GridElement grid = getGridElement();
    grid.getCell(10, 2).click();

    assertTrue("Body cell 10, 2 does not have focus", grid.getCell(10, 2).isFocused());
    new Actions(getDriver()).keyDown(Keys.SHIFT).sendKeys(Keys.TAB).keyUp(Keys.SHIFT).perform();
    assertTrue("Header cell 0, 2 does not have focus", grid.getHeaderCell(0, 2).isFocused());
    new Actions(getDriver()).sendKeys(Keys.TAB).perform();
    assertTrue("Body cell 10, 2 does not have focus", grid.getCell(10, 2).isFocused());

    // Navigate out of the Grid and try to navigate with arrow keys.
    new Actions(getDriver()).keyDown(Keys.SHIFT).sendKeys(Keys.TAB).sendKeys(Keys.TAB).keyUp(Keys.SHIFT)
            .sendKeys(Keys.ARROW_DOWN).perform();
    assertTrue("Header cell 0, 2 does not have focus", grid.getHeaderCell(0, 2).isFocused());
}

From source file:com.vaadin.tests.components.grid.basicfeatures.server.GridKeyboardNavigationTest.java

License:Apache License

@Test
public void testNavigateBetweenFooterAndBodyWithTab() {
    openTestURL();//from w w w. j  a va 2 s. c  o m

    selectMenuPath("Component", "Footer", "Visible");

    GridElement grid = getGridElement();
    grid.getCell(10, 2).click();

    assertTrue("Body cell 10, 2 does not have focus", grid.getCell(10, 2).isFocused());
    new Actions(getDriver()).sendKeys(Keys.TAB).perform();
    assertTrue("Footer cell 0, 2 does not have focus", grid.getFooterCell(0, 2).isFocused());
    new Actions(getDriver()).keyDown(Keys.SHIFT).sendKeys(Keys.TAB).keyUp(Keys.SHIFT).perform();
    assertTrue("Body cell 10, 2 does not have focus", grid.getCell(10, 2).isFocused());

    // Navigate out of the Grid and try to navigate with arrow keys.
    new Actions(getDriver()).sendKeys(Keys.TAB).sendKeys(Keys.TAB).sendKeys(Keys.ARROW_UP).perform();
    assertTrue("Footer cell 0, 2 does not have focus", grid.getFooterCell(0, 2).isFocused());
}

From source file:com.vaadin.tests.components.grid.basicfeatures.server.GridMultiSortingTest.java

License:Apache License

@Test
public void testUserMultiColumnSorting() {
    openTestURL();/*from   w w w  .j a v  a 2  s . com*/

    selectMenuPath("Component", "Columns", "Column 11", "Column 11 Width", "Auto");

    GridCellElement cell = getGridElement().getHeaderCell(0, 11);
    new Actions(driver).moveToElement(cell, 20, 10).click().perform();
    new Actions(driver).keyDown(Keys.SHIFT).perform();
    new Actions(driver).moveToElement(getGridElement().getHeaderCell(0, 0), 20, 10).click().perform();
    new Actions(driver).keyUp(Keys.SHIFT).perform();

    String prev = getGridElement().getCell(0, 11).getAttribute("innerHTML");
    for (int i = 1; i <= 6; ++i) {
        assertEquals("Column 11 should contain same values.", prev,
                getGridElement().getCell(i, 11).getAttribute("innerHTML"));
    }

    prev = getGridElement().getCell(0, 0).getText();
    for (int i = 1; i <= 6; ++i) {
        assertTrue("Grid is not sorted by column 0.",
                prev.compareTo(getGridElement().getCell(i, 0).getText()) < 0);
    }
}

From source file:com.vaadin.tests.components.grid.basicfeatures.server.GridSortingTest.java

License:Apache License

@Test
public void testKeyboardSorting() {
    openTestURL();/*w  ww . j a va 2  s. co m*/

    /*
     * We can't click on the header directly, since it will sort the header
     * immediately. We need to focus some other column first, and only then
     * navigate there.
     */
    getGridElement().getCell(0, 0).click();
    sendKey(Keys.ARROW_UP);

    // Sort ASCENDING on first column
    sendKey(Keys.ENTER);
    assertLastSortIsUserOriginated(true);
    assertColumnsAreSortedAs(_(1, SortDirection.ASCENDING));

    // Move to next column
    sendKey(Keys.RIGHT);

    // Add this column to the existing sorting group
    holdKey(Keys.SHIFT);
    sendKey(Keys.ENTER);
    releaseKey(Keys.SHIFT);
    assertColumnsAreSortedAs(_(1, SortDirection.ASCENDING), _(2, SortDirection.ASCENDING));

    // Move to next column
    sendKey(Keys.RIGHT);

    // Add a third column to the sorting group
    holdKey(Keys.SHIFT);
    sendKey(Keys.ENTER);
    releaseKey(Keys.SHIFT);
    assertColumnsAreSortedAs(_(1, SortDirection.ASCENDING), _(2, SortDirection.ASCENDING),
            _(3, SortDirection.ASCENDING));

    // Move back to the second column
    sendKey(Keys.LEFT);

    // Change sort direction of the second column to DESCENDING
    holdKey(Keys.SHIFT);
    sendKey(Keys.ENTER);
    releaseKey(Keys.SHIFT);
    assertColumnsAreSortedAs(_(1, SortDirection.ASCENDING), _(2, SortDirection.DESCENDING),
            _(3, SortDirection.ASCENDING));

    // Move back to the third column
    sendKey(Keys.RIGHT);

    // Set sorting to third column, ASCENDING
    sendKey(Keys.ENTER);
    assertColumnsAreSortedAs(_(2, 1, SortDirection.ASCENDING));

    // Move to the fourth column
    sendKey(Keys.RIGHT);

    // Make sure that single-column sorting also works as expected
    sendKey(Keys.ENTER);
    assertColumnsAreSortedAs(_(3, 1, SortDirection.ASCENDING));

}

From source file:com.vaadin.tests.components.window.CloseShortcutTest.java

License:Apache License

private void attemptShiftShortcut() {
    window.focus();//from  w  w  w  . java2 s  .co  m
    new Actions(driver).keyDown(Keys.SHIFT).perform();
    $(TextFieldElement.class).first().sendKeys("H");
    new Actions(driver).keyUp(Keys.SHIFT).perform();
}