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.components.ui.menu.MenuUITest.java

License:Apache License

private void testMenuCheckboxForApp(String appName) throws MalformedURLException, URISyntaxException {
    open(appName);/*from  w  w  w. j  a  v  a 2 s  . c o  m*/
    WebDriver driver = this.getDriver();
    String label = "checkboxMenuLabel";
    String menuName = "checkboxMenu";
    String menuItem3 = "checkboxItem3";
    String menuItem4 = "checkboxItem4";
    String globalIdItem3 = auraUITestingUtil.getCmpGlobalIdGivenElementClassName(menuItem3);
    String globalIdItem4 = auraUITestingUtil.getCmpGlobalIdGivenElementClassName(menuItem4);
    String disableValueM4Exp = auraUITestingUtil.getValueFromCmpExpression(globalIdItem4, "v.disabled");
    String selectedValueM4Exp = auraUITestingUtil.getValueFromCmpExpression(globalIdItem4, "v.selected");
    String selectedValueM3Exp = auraUITestingUtil.getValueFromCmpExpression(globalIdItem3, "v.selected");
    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 button = driver.findElement(By.className("checkboxButton"));
    WebElement result = driver.findElement(By.className("result"));

    // 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"));

    // click on label
    menuLabel.click();

    // verify menu list is visible
    assertTrue("CheckboxMenu list should be visible", menu.getAttribute("class").contains("visible"));

    // 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", (Boolean) auraUITestingUtil.getEval(disableValueM4Exp));
    assertTrue("Item4 should be selected", (Boolean) auraUITestingUtil.getEval(selectedValueM4Exp));

    // click on item4
    item4Element.click();
    assertTrue("Item4 aria attribute should be Selected even when clicked",
            Boolean.valueOf(item4Element.getAttribute("aria-checked")));
    assertTrue("Item4 should be Selected even when clicked",
            (Boolean) auraUITestingUtil.getEval(selectedValueM4Exp));

    assertFalse("default: Item3 aria attribute should be Uncheked",
            Boolean.valueOf(item3Element.getAttribute("aria-checked")));
    assertFalse("default: Item3 should be Uncheked", (Boolean) auraUITestingUtil.getEval(selectedValueM3Exp));

    // click on item3
    item3Element.click();
    assertTrue("Item3 aria attribute should be Selected after the click",
            Boolean.valueOf(item3Element.getAttribute("aria-checked")));
    assertTrue("Item3 should be Selected after the click",
            (Boolean) auraUITestingUtil.getEval(selectedValueM3Exp));

    // click on item3 again
    auraUITestingUtil.pressEnter(item3Element);
    // verify not selected
    assertFalse("Item3 aria attribute should be Uncheked after Pressing Enter",
            Boolean.valueOf(item3Element.getAttribute("aria-checked")));
    assertFalse("Item3 should be Uncheked after Pressing Enter",
            (Boolean) auraUITestingUtil.getEval(selectedValueM3Exp));

    item3Element.sendKeys(Keys.SPACE);
    assertTrue("Item3 aria attribute should be checked after Pressing Space",
            Boolean.valueOf(item3Element.getAttribute("aria-checked")));
    assertTrue("Item3 should be checked after Pressing Space",
            (Boolean) auraUITestingUtil.getEval(selectedValueM3Exp));

    // check if focus changes when you use up and down arrow using keyboard
    item3Element.sendKeys(Keys.DOWN);
    assertEquals("Focus should be on item 4", item4Element.getText(), auraUITestingUtil.getActiveElementText());
    item4Element.sendKeys(Keys.UP);
    assertEquals("Focus should be back to item 3", item3Element.getText(),
            auraUITestingUtil.getActiveElementText());

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

    // verify menu not visible
    assertFalse("CheckboxMenu list should not be visible after escape",
            menu.getAttribute("class").contains("visible"));

    // click on submit button and verify the results
    assertEquals("label value should not get updated", "NFC West Teams", menuLabel.getText());
    button.click();
    assertEquals("Checkbox items selected are not correct", "St. Louis Rams,Arizona Cardinals",
            result.getText());
}

From source file:org.auraframework.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./* ww w.java2s.  co m*/
 */
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();

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

    // check focus
    activeElement = (WebElement) auraUITestingUtil.getEval(ACTIVE_ELEMENT);
    assertTrue("Active element is not app input", activeElement.getAttribute("class").contains("appInput2"));
}

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

License:Apache License

private void cycleThroughPanelInputElements(String url, String panelType, boolean doesPanelClose)
        throws Exception {
    openPanel();//  ww w.ja va  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) auraUITestingUtil.getEval(ACTIVE_ELEMENT);
    // assertEquals("Focus should be on first element", panelType, auraUITestingUtil.getEval(ACTIVE_ELEMENT_TEXT));
    int numElements = 24;
    // cycle through input elements on panel
    for (int i = 1; i < numElements; i++) {
        activeElement.sendKeys(Keys.TAB);
        activeElement = (WebElement) auraUITestingUtil.getEval(ACTIVE_ELEMENT);
    }

    // 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.components.ui.modalOverlay.PanelModalOverlayUITest.java

License:Apache License

/**
 * Verify pressing TAB key behavior for modal and nonModal overlay wrt to focus trapping 
 * @param button/*from  ww w  .  ja  v a 2s. c  om*/
 * @throws MalformedURLException
 * @throws URISyntaxException
 * @throws InterruptedException
 */
private void verifyFocusTrappingForModalAndNonModalDialog(String button, Boolean isFocusTrapped)
        throws MalformedURLException, URISyntaxException, InterruptedException {
    open(APP);
    verifyOverlayActive(MODAL_OVERLAY_CMP, false);
    openOverlay(button);
    verifyOverlayActive(MODAL_OVERLAY_CMP, true);
    assertEquals("Button1 should be active element", "button 1",
            auraUITestingUtil.getEval(ACTIVE_ELEMENT_TEXT));
    WebElement activeElement = (WebElement) auraUITestingUtil.getEval(ACTIVE_ELEMENT);
    activeElement.sendKeys(Keys.TAB);
    assertEquals("Button1 should be active element", "button 2",
            auraUITestingUtil.getEval(ACTIVE_ELEMENT_TEXT));
    activeElement = (WebElement) auraUITestingUtil.getEval(ACTIVE_ELEMENT);
    activeElement.sendKeys(Keys.TAB);
    activeElement = (WebElement) auraUITestingUtil.getEval(ACTIVE_ELEMENT);
    activeElement.sendKeys(Keys.TAB);
    activeElement = (WebElement) auraUITestingUtil.getEval(ACTIVE_ELEMENT);
    activeElement.sendKeys(Keys.TAB);
    if (isFocusTrapped) {
        assertEquals("Button1 should be active element", "button 1",
                auraUITestingUtil.getEval(ACTIVE_ELEMENT_TEXT));
    } else {
        //Test case for W-2424553
        //assertEquals("Show panel slider button should be active element", "Show panel slider", auraUITestingUtil.getEval(ACTIVE_ELEMENT_TEXT));
    }
    verifyOverlayActive(MODAL_OVERLAY_CMP, isFocusTrapped);
}

From source file:org.auraframework.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 .ja  v  a2  s . c o 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
    waitForElementPresent("Trigger input box not present", driver.findElement(By.className(triggerLocator)));
    WebElement triggerInput = driver.findElement(By.className(triggerLocator));
    triggerInput.click();
    WebElement popContainerTgtElem = driver.findElement(By.className(targetLocator));
    waitForElementPresent("Popup did not launch", popContainerTgtElem);
    // Close the popup either by the TAB key or the close button
    if (closeOnTabKey) {
        Actions builder = new Actions(this.currentDriver);
        builder.sendKeys(Keys.TAB, Keys.NULL).build().perform();
    } else {
        WebElement customTriggerButton = driver.findElement(By.className(buttonLocator));
        customTriggerButton.click();
    }

    waitForElementAbsent("Popup did not close", popContainerTgtElem);
}

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

License:Apache License

@Test
public void testTabIntoInlineEditGrid() throws Exception {
    open(inlineURL);/* w  w w . jav  a  2s. c  o  m*/
    WebDriver driver = getDriver();
    switchKeyboardMode(driver);
    pressKey(driver, Keys.TAB);
    for (int i = 0; i < 8; ++i) {
        WebElement activeCell = waitForActiveCellToLoad(driver);
        // verify active cell is in correct place
        assertEquals("Name" + i, activeCell.findElement(By.className("uiOutputText")).getText());
        for (int j = 0; j < 12; ++j) {
            pressKey(driver, Keys.TAB);
        }
    }
}

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

License:Apache License

@Test
public void testUpDownArrow() throws Exception {
    open(inlineURL);// w  w w . j ava2  s  . c o  m
    WebDriver driver = getDriver();
    switchKeyboardMode(driver);
    pressKey(driver, Keys.TAB);
    for (int i = 0; i < 7; ++i) {
        WebElement activeCell = waitForActiveCellToLoad(driver);
        // verify active cell is in correct place
        assertEquals("Name" + i, activeCell.findElement(By.className("uiOutputText")).getText());
        pressKey(driver, Keys.ARROW_DOWN);
    }
    for (int i = 0; i < 7; ++i) {
        pressKey(driver, Keys.ARROW_UP);
    }
    WebElement activeCell = waitForActiveCellToLoad(driver);
    assertEquals("Name0", activeCell.findElement(By.className("uiOutputText")).getText());
}

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

License:Apache License

/**
 * Test tabing out of edit panel.
 */
@Test
public void testTabOutOfEditPanel() throws Exception {
    verifyKeypressEventOnEditPanel(Keys.TAB);
}

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

License:Apache License

private void verifyKeypressEventOnEditPanel(Keys keyPress) throws MalformedURLException, URISyntaxException {
    open(inlineURL);//from  ww  w  .  j a v a  2  s .  com
    WebDriver driver = getDriver();
    switchKeyboardMode(driver);
    pressKey(driver, Keys.TAB);

    // open edit on cell
    pressKey(driver, EDIT_TRIGGER_SELECTOR, Keys.ENTER);
    waitForEditPanelOpen(driver);
    editPanelContent(driver, "abc");

    if (keyPress.equals(Keys.TAB)) {
        // tab out to close
        pressKey(driver, INPUT_PANEL_INPUT_SELECTOR, keyPress);
    } else {
        // shift tab out to close
        driver.findElement(By.cssSelector(INPUT_PANEL_INPUT_SELECTOR)).sendKeys(Keys.SHIFT, Keys.TAB);
    }

    waitForEditPanelClose(driver);

    verifyCellContent(driver, 0, 1, "abc");

}

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

License:Apache License

/**
  * Test click out of panel/*from w  w  w . jav  a 2s.c o m*/
  */
@Test
public void testClickOutOfEditPanel() throws Exception {
    open(inlineURL);
    WebDriver driver = getDriver();
    switchKeyboardMode(driver);
    pressKey(driver, Keys.TAB);

    // open edit on cell
    pressKey(driver, EDIT_TRIGGER_SELECTOR, Keys.ENTER);
    waitForEditPanelOpen(driver);
    editPanelContent(driver, "abc");

    // click out to close
    WebElement input = driver.findElement(By.cssSelector(INPUT_TXT_SELECTOR));
    input.click();
    waitForEditPanelClose(driver);

    verifyCellContent(driver, 0, 1, "abc");
}