Example usage for org.openqa.selenium Keys TAB

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

Introduction

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

Prototype

Keys TAB

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

Click Source Link

Usage

From source file:org.auraframework.integration.test.components.ui.inlineEditGrid.InlineEditGridUITest.java

License:Apache License

/**
 * Test can navigate to inlineEditKeyNavCell using keyboard
 *//*from  w  w  w.j  a va  2 s .  c o m*/
@Test
public void testInlineEditKeyNavCellNavigateTo() throws Exception {
    open("/uitest/inlineEditKeyNavCell_test.cmp");
    WebDriver driver = getDriver();
    switchKeyboardMode(driver);

    pressKey(driver, Keys.TAB);
    WebElement activeCell = driver.findElement(By.cssSelector(ACTIVE_CELL_CLASS));
    assertEquals("inlineEditKeyNavCell was not navigated to", "Name0", activeCell.getText());
}

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

License:Apache License

@UnAdaptableTest
// Checking functionality of the shift tab button
// temporarily disabled due to a bug in the initial positioning. Will re-enable once that issue is fixed
@ExcludeBrowsers({ BrowserType.IE9, BrowserType.IE10, BrowserType.SAFARI, BrowserType.ANDROID_PHONE,
        BrowserType.ANDROID_TABLET, BrowserType.IPAD, BrowserType.IPHONE })
public void _testShiftTab() throws Exception {
    open(URL);//  w  ww  .  j a v  a2 s  .com

    WebDriver driver = getDriver();

    // Getting input textbox in focus
    WebElement element = findDomElement(By.cssSelector(DATE_INPUT_BOX_SEL));
    element.click();
    element.sendKeys("20151111");
    getAuraUITestingUtil().pressTab(element);

    String classOfActiveElem = "a[class*='" + getAuraUITestingUtil().getEval(CLASSNAME) + "']";
    element = findDomElement(By.cssSelector(classOfActiveElem));
    String elementClass = element.getAttribute("class");
    assertTrue("Tabbing did not take us to the date picker icon",
            elementClass.indexOf("datePicker-openIcon") >= 0);
    element.click();

    // Focused on Today's date
    classOfActiveElem = "td[class*='" + getAuraUITestingUtil().getEval(CLASSNAME) + "']";
    element = findDomElement(By.cssSelector(classOfActiveElem));
    elementClass = element.getAttribute("class");
    assertTrue("Tabbing did not take us to the selected date", elementClass.indexOf("selectedDate") >= 0);
    getAuraUITestingUtil().pressTab(element);

    String shftTab = Keys.SHIFT + "" + Keys.TAB;

    // Going from SELECTED_DATE to next-year
    gotToNextElem(driver, shftTab);

    // Going from next-year to next-month
    gotToNextElem(driver, shftTab);

    // Going from next-month to prev-month
    gotToNextElem(driver, shftTab);

    // Going from prev-month to prev-Year
    gotToNextElem(driver, shftTab);

    // Going from prev-Year to icon
    gotToNextElem(driver, shftTab);

    // Going from icon to input box
    gotToNextElem(driver, shftTab);

    // Getting the input textbox in focus and getting the value, which should not have changed
    classOfActiveElem = "input[class*='" + getAuraUITestingUtil().getEval(CLASSNAME) + "']";
    element = findDomElement(By.cssSelector(classOfActiveElem));

    assertEquals("Shift Tabbing did not get us to the input textbox", "2015-11-11",
            element.getAttribute("value"));
}

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

License:Apache License

/**
 * Test Flow://from   w w  w.  ja  va 2 s  . c o  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.listSorter.ListSorterUITest.java

License:Apache License

/**
 * Tab out should not close the sorter dialog The focus should remain in the Sorter Menu Test case for W-1985435
 * //from  w  w w.  j av a 2  s  .c  o m
 * @throws MalformedURLException
 * @throws URISyntaxException
 */
@PerfTest
@Test
public void testTabOutOfListSorter() throws MalformedURLException, URISyntaxException {
    verifyTabOutAndEscBehaviour(Keys.TAB, true);
}

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 .  j a v  a  2s  . c  om*/
    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

/**
 * Tabbing out of open menu should close menu and focuses on next DOM element
 * Bug: W-3197504/* w w  w  . j a  v a  2s. co  m*/
 */
/*
    @Test
    public void testFocusWhenTabOnOpenMenuWithAttachToBodySet() throws Exception {
open(MENUTEST_ATTACHTOBODY_APP);
String nextFocusableElmClassName = "triggerAttachToBody";
verifyFocusOnTabOnOpenMenu(nextFocusableElmClassName);
    }
*/

private void verifyFocusOnTabOnOpenMenu(String nextFocusableElmClassName) {
    WebDriver driver = this.getDriver();
    WebElement menuElm = driver.findElement(By.className("actionMenu"));
    WebElement triggerElm = driver.findElement(By.className("trigger"));

    // open menu and make sure focus is on the trigger label
    openMenu(triggerElm, menuElm);
    waitForFocusOnElement(triggerElm);

    WebElement item1Elm = driver.findElement(By.className("actionItem1"));
    WebElement nextFocusableElm = driver.findElement(By.className(nextFocusableElmClassName));

    // move the focus to the menuList by moving to the first item
    triggerElm.sendKeys(Keys.DOWN);
    waitForFocusOnElement(item1Elm);

    // tab out to close the menu and check the focus is set to the right element
    if (getBrowserType().equals(BrowserType.FIREFOX)) {
        // firefox closes the menu on the first tab, but the focus is still on the item
        // need a second tab to get to the next element
        getAnchor(item1Elm).sendKeys(Keys.TAB, Keys.TAB);
    } else {
        getAuraUITestingUtil().pressTab(getAnchor(item1Elm));
    }

    waitForFocusOnElement(nextFocusableElm);
}

From source file:org.auraframework.integration.test.components.ui.modalOverlay.Panel2ModalOverlayUITest.java

License:Apache License

/**
 * Tab out closes panel and sets focus back on element that called it. Test panel focuses on reference element after
 * its been closed.//from   w  w  w.ja v a 2s  .c  o  m
 */
@Test
public void testPanelTabOutFocus() throws Exception {
    String url = APP + "?" + PARAM_PANEL_TYPE + "panel" + PARAM_DIRECTION + "south";

    open(url);

    // open panel
    WebElement input = findDomElement(By.cssSelector(APP_INPUT2));
    input.click();
    waitForPanelDialogOpen();

    waitTillFocusOnParticularElement(CLOSE_BTN, "Focus should be on closeBtn");

    // tab out to close
    WebElement activeElement = (WebElement) getAuraUITestingUtil().getEval(ACTIVE_ELEMENT);
    activeElement.sendKeys(Keys.TAB);
    waitForPanelDialogClose();

    // check focus
    waitTillFocusOnParticularElement("appInput2", "Active element is not app input");
}

From source file:org.auraframework.integration.test.components.ui.modalOverlay.Panel2ModalOverlayUITest.java

License:Apache License

private void cycleThroughPanelInputElements(String url, String panelType, boolean doesPanelClose)
        throws Exception {
    openPanel();//w ww  .j  a  v  a 2 s  .c o m
    if (panelType.equals("modal")) {
        waitForModalOpen();
    } else {
        waitForPanelDialogOpen();
    }
    List<WebElement> firstInput = findDomElements(By.cssSelector(INPUT_PANELTYPE));
    firstInput.get(1).click();
    WebElement activeElement = (WebElement) getAuraUITestingUtil().getEval(ACTIVE_ELEMENT);
    // assertEquals("Focus should be on first element", panelType, auraUITestingUtil.getEval(ACTIVE_ELEMENT_TEXT));
    int numElements = 27;
    // cycle through input elements on panel
    for (int i = 1; i < numElements; i++) {
        WebElement prevActiveElement = activeElement;
        activeElement.sendKeys(Keys.TAB);
        activeElement = (WebElement) getAuraUITestingUtil().getEval(ACTIVE_ELEMENT);
        getAuraUITestingUtil().waitUntil(new ExpectedCondition<Boolean>() {
            @Override
            public Boolean apply(WebDriver d) {
                WebElement activeElement = (WebElement) getAuraUITestingUtil().getEval(ACTIVE_ELEMENT);
                return activeElement != prevActiveElement;
            }
        }, String.format("Tab event was not fired for element with className: %s",
                prevActiveElement.getAttribute("class")));
    }

    // on close button
    activeElement.sendKeys(Keys.TAB);

    if (doesPanelClose) {
        if (panelType.equals("modal")) {
            waitForModalClose();
        } else {
            waitForPanelDialogClose();
        }
    } else {
        /*
         * activeElement = (WebElement) auraUITestingUtil.getEval(ACTIVE_ELEMENT);
         * assertEquals("Panel should not be close and focus should be on first element", panelType,
         * auraUITestingUtil.getEval(ACTIVE_ELEMENT_TEXT));
         */
        if (panelType.equals("modal")) {
            waitForModalOpen();
        } else {
            waitForPanelDialogOpen();
        }
    }
}

From source file:org.auraframework.integration.test.components.ui.popup.PopupUITest.java

License:Apache License

/**
 * Helper to create a custom popup trigger and closer.  Trigger is
 * selecting an input box; popup closing is done via clicking on a
 * button OR via the keyboard TAB key.//  w w  w.j  a  v  a  2 s. co  m
 *
 * @param closeOnTabKey true if using the TAB key to close the popup;
 *                      false if using the button to close the popup
 * @throws Exception
 */
private void verifyCustomTrigger(boolean closeOnTabKey) throws Exception {
    WebDriver driver = this.getDriver();
    String triggerLocator = "customTriggerInput";
    String buttonLocator = "customTriggerButton";
    String targetLocator = "customTriggerTargetContainer";
    String appUrl = "/uitest/popupTest.app";
    open(appUrl);

    // Click on the trigger and verify the popup opens
    getAuraUITestingUtil().waitForElementDisplayed(By.cssSelector(triggerLocator),
            "Trigger input box not present");
    WebElement triggerInput = driver.findElement(By.className(triggerLocator));
    triggerInput.click();
    getAuraUITestingUtil().waitForElementDisplayed(By.cssSelector(targetLocator), "Popup did not launch");
    // Close the popup either by the TAB key or the close button
    if (closeOnTabKey) {
        Actions builder = new Actions(this.getDriver());
        builder.sendKeys(Keys.TAB, Keys.NULL).build().perform();
    } else {
        WebElement customTriggerButton = driver.findElement(By.className(buttonLocator));
        customTriggerButton.click();
    }

    getAuraUITestingUtil().waitForElementNotDisplayed(By.cssSelector(targetLocator), "Popup did not close");
}

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();
}