Example usage for org.openqa.selenium Keys SPACE

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

Introduction

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

Prototype

Keys SPACE

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

Click Source Link

Usage

From source file:org.auraframework.components.ui.menu.MenuUITest.java

License:Apache License

public void testMenuRadio() throws MalformedURLException, URISyntaxException {
    open(MENUTEST_APP);/*  ww  w  .  ja  v  a  2 s  .com*/
    WebDriver driver = this.getDriver();
    String label = "radioMenuLabel";
    String menuName = "radioMenu";
    String menuItem3 = "radioItem3";
    String menuItem4 = "radioItem4";
    String menuItem5 = "radioItem5";
    String disableValueM4Exp = auraUITestingUtil.getValueFromCmpRootExpression(menuItem4, "v.disabled");
    WebElement menuLabel = driver.findElement(By.className(label));
    WebElement menu = driver.findElement(By.className(menuName));
    WebElement item3 = driver.findElement(By.className(menuItem3));
    WebElement item3Element = item3.findElement(By.tagName("a"));
    WebElement item4 = driver.findElement(By.className(menuItem4));
    WebElement item4Element = item4.findElement(By.tagName("a"));
    WebElement item5 = driver.findElement(By.className(menuItem5));
    WebElement item5Element = item5.findElement(By.tagName("a"));
    WebElement button = driver.findElement(By.className("radioButton"));
    WebElement result = driver.findElement(By.className("radioResult"));

    // check for default label present
    assertEquals("label is wrong", "National League West", menuLabel.getText());
    assertFalse("Default: CheckboxMenu list should not be visible",
            menu.getAttribute("class").contains("visible"));
    // open menu list
    menuLabel.click();
    // verify menu list is visible
    assertTrue("CheckboxMenu list should be visible", menu.getAttribute("class").contains("visible"));
    item3.click();
    // verify item3 got selected
    assertTrue("Item3 should be selected after the click",
            item3Element.getAttribute("class").contains("selected"));

    // send key to go to item 4 using 'd'
    item3Element.sendKeys("d");
    // verify focus on item 4
    assertEquals("Focus should be on item4 after the search", item4Element.getText(),
            auraUITestingUtil.getActiveElementText());
    // verify item is disabled
    assertTrue("Item4 aria attribute should be defaulted to disable",
            Boolean.valueOf(item4Element.getAttribute("aria-disabled")));
    assertTrue("Item4 should be defaulted to disable", (Boolean) auraUITestingUtil.getEval(disableValueM4Exp));

    // click on item4
    item4Element.click();
    // verify item4 should not be selectable
    assertFalse("Item4 should not be selectable as its disable item",
            item4Element.getAttribute("class").contains("selected"));
    // goto item 5 using down arrow
    item4Element.sendKeys(Keys.DOWN);
    // verify focus on item 5
    assertEquals("Focus should be on item5 after pressing down key", item5Element.getText(),
            auraUITestingUtil.getActiveElementText());
    // click on item 5 using space
    item5Element.sendKeys(Keys.SPACE);
    assertTrue("Item5 should be checked after pressing Space",
            item5Element.getAttribute("class").contains("selected"));
    assertFalse("Item3 should be unchecked after clicking item 5",
            item3Element.getAttribute("class").contains("selected"));
    // close the menu using esc key
    item5Element.sendKeys(Keys.ESCAPE);
    // check the result
    button.click();
    assertEquals("Checkbox items selected are not correct", "Colorado", result.getText());
}

From source file:org.auraframework.integration.test.components.ui.inputDate.InputDateWithLabelUITest.java

License:Apache License

private String pageUpDownHelper(int iterCondition, String keyString) {
    // Making sure the textBox is empty so we always start at the same date
    WebElement element = findDomElement(By.cssSelector(DATE_INPUT_BOX_SEL));
    element.clear();//from www  .  j a  v  a  2s .c  om
    element.sendKeys(TEST_DATE_TO_USE);

    openDatePicker();

    String classOfActiveElem = "" + getAuraUITestingUtil().getEval(CLASSNAME);
    element = findDomElement(By.cssSelector("td[class*='" + classOfActiveElem + "']"));

    element = loopThroughKeys(element, keyString, iterCondition, ARIA_SELECTED_SEL, "Shift+Page Up/Down");

    // Selecting the date that we are on to get the value and compare it to what it should be
    element.sendKeys(Keys.SPACE);

    // Setting the input box in focus to get its value
    element = findDomElement(By.cssSelector(DATE_INPUT_BOX_SEL));

    // Checking if the values are equal
    return element.getAttribute("value");
}

From source file:org.auraframework.integration.test.components.ui.inputDate.InputDateWithLabelUITest.java

License:Apache License

/**
 * Test Flow:/*from  w  w w. java  2s .  co  m*/
 * 1. Have focus on inputDate
 * 2. Tab onto the calendar icon and press enter
 * 3. After datepicker opens, press a button (ESC, ENTER, SPACE) to close it
 * 4. Check if inputDate has focus
 * @throws Exception
 */
// Testing the focus after closing datePicker
// Disabling for Safari since Safari does not handle tabs normally
@ExcludeBrowsers({ BrowserType.SAFARI, BrowserType.ANDROID_PHONE, BrowserType.ANDROID_TABLET, BrowserType.IPAD,
        BrowserType.IPHONE })

@Test
public void testFocusOnClosingDP() throws Exception {

    // the different keys we will use to close the datePicker
    Keys[] keysToClose = { Keys.ESCAPE, Keys.ENTER, Keys.SPACE };

    open(URL);

    for (int i = 0; i < keysToClose.length; i++) {

        WebElement inputDate = findDomElement(By.cssSelector(DATE_INPUT_BOX_SEL));
        inputDate.sendKeys(Keys.TAB);

        //active element should now be the calendar icon - hit enter to open datePicker
        WebElement activeElement = (WebElement) getAuraUITestingUtil().getEval(ACTIVE_ELEMENT);
        activeElement.sendKeys(Keys.ENTER);

        //datePicker should be open
        getAuraUITestingUtil().waitForElement("datePicker should been present, but its not",
                By.cssSelector(".uiDatePicker.visible"));

        //use key to close the datePicker
        WebElement selectedDate = findDomElement(By.cssSelector(SELECTED_DATE));
        selectedDate.sendKeys(keysToClose[i]);

        //check if datePicker is closed
        getAuraUITestingUtil().waitForElementNotPresent("datePicker should not be present, but it is",
                By.cssSelector(".uiDatePicker.visible"));

        //check if active element is the inputDate
        activeElement = (WebElement) getAuraUITestingUtil().getEval(ACTIVE_ELEMENT);
        assertEquals("Focus not on the right element", activeElement, inputDate);

    }
}

From source file:org.auraframework.integration.test.components.ui.inputDate.InputDateWithLabelUITest.java

License:Apache License

@ExcludeBrowsers({ BrowserType.ANDROID_PHONE, BrowserType.ANDROID_TABLET, BrowserType.IPAD,
        BrowserType.IPHONE })/*from  w w w.  j ava  2  s  . co  m*/
// TODO(W-2701964): Flapping in autobuilds, needs to be revisited
@Flapper
@Test
public void testDateWithOneArrow() throws Exception {
    open(URL);

    WebElement element = findDomElement(By.cssSelector(DATE_INPUT_BOX_SEL));
    element.sendKeys("2013-10-01");
    element.click();

    openDatePicker();

    String classOfActiveElem = "" + getAuraUITestingUtil().getEval(CLASSNAME);

    element = findDomElement(By.cssSelector("td[class*='" + classOfActiveElem + "']"));

    // Loop through 151 days
    element = loopThroughKeys(element, "" + Keys.ARROW_RIGHT, 151, ARIA_SELECTED_SEL, "Arrow-Right ");

    element.sendKeys(Keys.SPACE);

    element = findDomElement(By.cssSelector(DATE_INPUT_BOX_SEL));
    assertEquals("Dates do not match up", "2014-03-01", element.getAttribute("value").trim());
}

From source file:org.auraframework.integration.test.components.ui.inputDate.InputDateWithLabelUITest.java

License:Apache License

@ExcludeBrowsers({ BrowserType.ANDROID_PHONE, BrowserType.ANDROID_TABLET, BrowserType.IPAD,
        BrowserType.IPHONE })/*from   ww w.  j a  v  a 2  s .  c o m*/
@Test
public void testLeftAndRightArrows() throws Exception {
    open(URL);

    WebElement element = findDomElement(By.cssSelector(DATE_INPUT_BOX_SEL));
    element.sendKeys(TEST_DATE_TO_USE);
    element.click();

    openDatePicker();

    // Find todays date, which should be focused
    By activeElmLoc = By.cssSelector("td[class*='" + getAuraUITestingUtil().getEval(CLASSNAME) + "']");
    element = findDomElement(activeElmLoc);

    // Move from todays date, to the todays date +41
    element = loopThroughKeys(element, "" + Keys.ARROW_RIGHT, 41, ARIA_SELECTED_SEL, "Arrow-Right key ");

    // Move from today (date+41), to the todays date+1
    element = loopThroughKeys(element, "" + Keys.ARROW_LEFT, 40, ARIA_SELECTED_SEL, "Arrow-Left key");

    // Select element
    element.sendKeys(Keys.SPACE);

    // Focus on the input box and get its value
    element = findDomElement(By.cssSelector(DATE_INPUT_BOX_SEL));
    assertEquals("Next day was not correctly found", "2013-04-16", element.getAttribute("value").trim());
}

From source file:org.auraframework.integration.test.components.ui.inputDate.InputDateWithLabelUITest.java

License:Apache License

@ExcludeBrowsers({ BrowserType.ANDROID_PHONE, BrowserType.ANDROID_TABLET, BrowserType.IPAD,
        BrowserType.IPHONE })/*from   ww w .  j  a v  a2  s .  c o m*/
@Test
public void testUpAndDownArrows() throws Exception {
    open(URL);

    // Start at specific date
    WebElement element = findDomElement(By.cssSelector(DATE_INPUT_BOX_SEL));
    element.sendKeys(TEST_DATE_TO_USE);
    element.click();

    openDatePicker();

    // Find todays date, which should be focused
    String classOfActiveElem = "" + getAuraUITestingUtil().getEval(CLASSNAME);
    element = findDomElement(By.cssSelector("td[class*='" + classOfActiveElem + "']"));

    // Move 4 months up
    element = loopThroughKeys(element, "" + Keys.ARROW_UP, 4, ARIA_SELECTED_SEL, "Arrow-Up key");

    // Move 4 months down
    element = loopThroughKeys(element, "" + Keys.ARROW_DOWN, 4, ARIA_SELECTED_SEL, "Arrow-Down key");

    // Focus should be back on todays date
    element.sendKeys(Keys.SPACE);

    // Select the input text box and get its value for comparison
    element = findDomElement(By.cssSelector(DATE_INPUT_BOX_SEL));
    assertEquals("Moving dates using arrows has not brought us to todays date", TEST_DATE_TO_USE,
            element.getAttribute("value").trim());
}

From source file:org.auraframework.integration.test.components.ui.menu.MenuUITest.java

License:Apache License

@Test
public void testOpenMenuViaKeyboardSpace() throws Exception {
    openMenuViaKeyboardAndTestActionMenu(MENUTEST_APP, Keys.SPACE, "trigger", "actionItem1");
}

From source file:org.auraframework.integration.test.components.ui.menu.MenuUITest.java

License:Apache License

private void testActionMenuViaKeyboardInteractionForApp(String appName, String appendString,
        boolean verifyLabelUpdate) throws Exception {
    open(appName);/*from   w ww .  j av  a 2 s .c  o  m*/
    WebDriver driver = this.getDriver();
    String label = "trigger" + appendString;
    String menuName = "actionMenu" + appendString;
    String menuItem1 = "actionItem1" + appendString;
    String menuItem3 = "actionItem3" + appendString;
    String menuItem4 = "actionItem4" + appendString;
    WebElement menuLabel = driver.findElement(By.className(label));
    WebElement actionMenu = driver.findElement(By.className(menuName));

    openMenu(menuLabel, actionMenu);

    WebElement actionItem1 = driver.findElement(By.className(menuItem1));
    WebElement actionItem1Element = getAnchor(actionItem1);
    WebElement actionItem3 = driver.findElement(By.className(menuItem3));
    WebElement actionItem3Element = getAnchor(actionItem3);
    WebElement actionItem4 = driver.findElement(By.className(menuItem4));
    WebElement actionItem4Element = getAnchor(actionItem4);

    // default focus on trigger
    assertEquals("Focus should be on the trigger", menuLabel.getText(),
            getAuraUITestingUtil().getActiveElementText());

    // press down key once
    menuLabel.sendKeys(Keys.DOWN);

    // focus should be one the first item
    waitForFocusOnElement(actionItem1Element);

    actionItem1Element.sendKeys(Keys.DOWN, Keys.DOWN);

    // verify focus on action item3
    getAuraUITestingUtil().setHoverOverElement(menuItem3);
    waitForFocusOnElement(actionItem3Element);

    actionItem3Element.click();
    if (verifyLabelUpdate) {
        waitForMenuText(menuLabel, "Inter Milan");
    }

    openMenu(menuLabel, actionMenu);
    getAuraUITestingUtil().setHoverOverElement(menuItem4);
    waitForFocusOnElement(actionItem4Element);

    actionItem4Element.sendKeys(Keys.UP);
    // verify focus on action item3
    waitForFocusOnElement(actionItem3Element);

    // press space key and check if item3 got selected
    actionItem3Element.sendKeys(Keys.SPACE);
    if (verifyLabelUpdate) {
        waitForMenuText(menuLabel, "Inter Milan");
    }

    openMenu(menuLabel, actionMenu);
    getAuraUITestingUtil().setHoverOverElement(menuItem1);
    waitForFocusOnElement(actionItem1Element);
    actionItem1Element.sendKeys(Keys.ESCAPE);
    waitForMenuClose(actionMenu);
}

From source file:org.auraframework.integration.test.components.ui.menu.MenuUITest.java

License:Apache License

private void testMenuCheckboxForApp(String appName) throws Exception {
    open(appName);/*  w w  w.ja v a  2 s.c o  m*/
    WebDriver driver = this.getDriver();
    String label = "checkboxMenuLabel";
    String menuName = "checkboxMenu";
    String menuItem3 = "checkboxItem3";
    String menuItem4 = "checkboxItem4";
    WebElement menuLabel = driver.findElement(By.className(label));
    WebElement menu = driver.findElement(By.className(menuName));
    WebElement button = driver.findElement(By.className("checkboxButton"));
    By resultLocator = By.className("checkboxMenuResult");

    // check for default label present
    assertEquals("label is wrong", "NFC West Teams", menuLabel.getText());
    assertFalse("Default: CheckboxMenu list should not be visible",
            menu.getAttribute("class").contains("visible"));

    openMenu(menuLabel, menu);

    WebElement item3 = driver.findElement(By.className(menuItem3));
    WebElement item3Element = getAnchor(item3);
    WebElement item4 = driver.findElement(By.className(menuItem4));
    WebElement item4Element = getAnchor(item4);

    // verify aria attribute item4 which is used for accessibility is disabled and selected
    assertTrue("Item4 aria attribute should be disabled",
            Boolean.valueOf(item4Element.getAttribute("aria-disabled")));
    assertTrue("Item4 aria attribute should be selected",
            Boolean.valueOf(item4Element.getAttribute("aria-checked")));

    // verify item4 is disabled and selected
    assertTrue("Item4 should be disabled", getCmpBoolAttribute(menuItem4, "v.disabled"));
    assertTrue("Item4 should be selected", getCmpBoolAttribute(menuItem4, "v.selected"));

    // item4Element is not clickable as it's disabled via markup
    tryToClickDisabledElm(item4Element);

    assertTrue("Item4 aria attribute should be Selected even when clicked",
            Boolean.valueOf(item4Element.getAttribute("aria-checked")));
    assertTrue("Item4 should be Selected even when clicked", getCmpBoolAttribute(menuItem4, "v.selected"));

    assertFalse("default: Item3 aria attribute should be Unchecked",
            Boolean.valueOf(item3Element.getAttribute("aria-checked")));
    assertFalse("default: Item3 should be Unchecked", getCmpBoolAttribute(menuItem3, "v.selected"));

    // check item3 with click
    item3Element.click();
    getAuraUITestingUtil().waitUntil(check -> Boolean.valueOf(item3Element.getAttribute("aria-checked")),
            "Item3 aria attribute should be checked after the click");
    assertTrue("Item3 v.selected should be true after the click", getCmpBoolAttribute(menuItem3, "v.selected"));

    // uncheck item3 with ENTER key
    item3Element.sendKeys(Keys.ENTER);
    getAuraUITestingUtil().waitUntil(check -> !Boolean.valueOf(item3Element.getAttribute("aria-checked")),
            "Item3 aria attribute should be uncheked after pressing ENTER");
    assertFalse("Item3 v.selected should be false after pressing ENTER",
            getCmpBoolAttribute(menuItem3, "v.selected"));

    // check item3 with SPACE key
    item3Element.sendKeys(Keys.SPACE);
    getAuraUITestingUtil().waitUntil(check -> Boolean.valueOf(item3Element.getAttribute("aria-checked")),
            "Item3 aria attribute should be checked after pressing SPACE");
    assertTrue("Item3 v.selected should be true after pressing SPACE",
            getCmpBoolAttribute(menuItem3, "v.selected"));

    // check if focus changes when you use up and down arrow using keyboard
    item3Element.sendKeys(Keys.DOWN);
    waitForFocusOnElement(item4Element);
    item4Element.sendKeys(Keys.UP);
    waitForFocusOnElement(item3Element);

    // press Tab to close to menu
    item3Element.sendKeys(Keys.TAB);
    waitForMenuClose(menu);

    // click on submit button and verify the results
    assertEquals("label value should not get updated", "NFC West Teams", menuLabel.getText());
    button.click();
    getAuraUITestingUtil().waitForElementText(resultLocator, "St. Louis Rams,Arizona Cardinals", true);
}

From source file:org.auraframework.integration.test.components.ui.menu.MenuUITest.java

License:Apache License

@ExcludeBrowsers({ BrowserType.IE11 })
public void testMenuRadio() throws Exception {
    open(MENUTEST_APP);/*from ww  w . j a v  a2  s .  c o  m*/
    WebDriver driver = this.getDriver();
    String label = "radioMenuLabel";
    String menuName = "radioMenu";
    String menuItem3 = "radioItem3";
    String menuItem4 = "radioItem4";
    String menuItem5 = "radioItem5";
    WebElement menuLabel = driver.findElement(By.className(label));
    WebElement menu = driver.findElement(By.className(menuName));

    // check for default label present
    assertEquals("label is wrong", "National League West", menuLabel.getText());
    assertFalse("Default: CheckboxMenu list should not be visible",
            menu.getAttribute("class").contains("visible"));

    // open menu list
    openMenu(menuLabel, menu);

    WebElement item3 = driver.findElement(By.className(menuItem3));
    WebElement item3Element = getAnchor(item3);
    WebElement item4 = driver.findElement(By.className(menuItem4));
    WebElement item4Element = getAnchor(item4);
    WebElement item5 = driver.findElement(By.className(menuItem5));
    WebElement item5Element = getAnchor(item5);
    WebElement button = driver.findElement(By.className("radioButton"));
    WebElement result = driver.findElement(By.className("radioMenuResult"));

    // click and verify item3 got selected
    item3Element.click();
    getAuraUITestingUtil().waitUntil(check -> item3Element.getAttribute("class").contains("selected"),
            "Item3 should be selected after the click");

    // send key to go to item 4 using 'd'
    item3Element.sendKeys("d");
    waitForFocusOnElement(item4Element);

    // verify item is disabled
    assertTrue("Item4 aria attribute should be defaulted to disable",
            Boolean.valueOf(item4Element.getAttribute("aria-disabled")));
    assertTrue("Item4 v.disabled should default to true", getCmpBoolAttribute(menuItem4, "v.disabled"));

    // click on item4 and verify item4 should not be selectable
    tryToClickDisabledElm(item4Element);
    assertFalse("Item4 should not be selectable as it's disable item",
            item4Element.getAttribute("class").contains("selected"));

    // goto item 5 using down arrow and check focus
    item4Element.sendKeys(Keys.DOWN);
    waitForFocusOnElement(item5Element);

    // click on item 5 using space
    item5Element.sendKeys(Keys.SPACE);
    getAuraUITestingUtil().waitUntil(check -> item5Element.getAttribute("class").contains("selected"),
            "Item5 should be checked after pressing Space");

    assertFalse("Item3 should be unchecked after clicking item 5",
            item3Element.getAttribute("class").contains("selected"));

    // close the menu using esc key
    item5Element.sendKeys(Keys.ESCAPE);

    // check the result
    button.click();
    assertEquals("Checkbox items selected are not correct", "Colorado", result.getText());
}