Example usage for org.openqa.selenium Keys ESCAPE

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

Introduction

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

Prototype

Keys ESCAPE

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

Click Source Link

Usage

From source file:info.magnolia.integrationtests.uitest.KeyboardShortcutUITest.java

License:Open Source License

/**
 * Get a confirmation to test by running 'Delete contact' action.
 * Hit the ESCAPE key and verify that a confirmation is closed, and the contact is not deleted.
 *//*  www  . j a v a 2  s .c o m*/
@Test
public void whenEscapePressedOnConfirmationItCloses() {
    // GIVEN
    WebElement confirmation;
    getAppIcon("Contacts").click();
    waitUntil(appIsLoaded());
    assertAppOpen("Contacts");

    // WHEN
    getTreeTableItem("Albert Einstein").click();
    getActionBarItem("Delete contact").click();

    waitUntil(visibilityOfElementLocated(byConfirmationOverlay));
    confirmation = getConfirmationOverlay();

    assertTrue("Delete action should have caused confirmation overlay.", isExisting(confirmation));
    simulateKeyPress(Keys.ESCAPE);

    waitUntil(invisibilityOfElementLocated(byConfirmationOverlay));

    // THEN
    WebElement contact = getTreeTableItem("Albert Einstein");
    assertTrue("Contact should not have been deleted.", isExisting(contact));
}

From source file:info.magnolia.integrationtests.uitest.KeyboardShortcutUITest.java

License:Open Source License

/**
 * Get a dialog to test by running 'Add page' action.
 * Fill in small form, then hit the ESCAPE key and verify that a confirmation is displayed.
 * Hit ESCAPE and verify that the confirmation closes.
 * Hit ESCAPE again and verify that confirmation is displayed.
 * Hit ENTER to confirm and verify the dialog is closed.
 *//*w  w w . ja  va  2  s . co m*/
@Test
public void escapeHandlingOnDialog() {
    //GIVEN
    final String pageName = "testEscapeHandling";
    WebElement confirmation;

    getAppIcon("Pages").click();
    waitUntil(appIsLoaded());
    assertAppOpen("Pages");
    getActionBarItem("Add page").click();
    waitUntil(dialogIsOpen(ADD_NEW_PAGE_DIALOG_TITLE));
    setFormTextFieldText("Page name", pageName);

    // First pass - we cancel the dialog closing.
    // WHEN
    simulateKeyPress(Keys.ESCAPE);
    waitUntil(visibilityOfElementLocated(byConfirmationOverlay));
    // THEN
    confirmation = getConfirmationOverlay();
    assertTrue("ESC key should have caused confirmation overlay.", isExisting(confirmation));

    // WHEN
    simulateKeyPress(Keys.ESCAPE);
    // THEN
    waitUntil(invisibilityOfElementLocated(byConfirmationOverlay));

    // Now do it again, but this time confirm the dialog closing.

    // WHEN
    simulateKeyPress(Keys.ESCAPE);
    waitUntil(visibilityOfElementLocated(byConfirmationOverlay));
    // THEN
    confirmation = getConfirmationOverlay();
    assertTrue("ESC key should have caused confirmation overlay.", isExisting(confirmation));
    // WHEN
    simulateKeyPress(Keys.ENTER);
    // THEN
    waitUntil(invisibilityOfElementLocated(byConfirmationOverlay));
}

From source file:info.magnolia.integrationtests.uitest.KeyboardShortcutUITest.java

License:Open Source License

/**
 * ESCAPE key over page editor is a special case because the pageeditor itself responds to the ESCAPE key,
 * the PageEditor SHOULD NOT handle the escape when a dialog is open.
 *
 * Get a dialog to test by opening the 'About' page and editing the Section Header component.
 * Then hit the ESCAPE key and verify that a confirmation is displayed.
 * Hit ENTER to confirm and verify the dialog is closed.
 * Verify that the sub app is still in editor view - not preview view.
 *///from w  ww.j a v a  2 s  . c o m
@Test
public void escapeHandlingOnDialogOverPageEditor() {
    //GIVEN
    String url;

    getAppIcon("Pages").click();
    waitUntil(appIsLoaded());
    assertAppOpen("Pages");

    doubleClick(getTreeTableItem("ftl-sample-site"));
    waitUntil(appIsLoaded());

    // Open component editor
    switchToPageEditorContent();
    getElement(By.xpath("//h3[text() = 'Main - Component One']")).click();
    getElement(By.xpath("//*[contains(@class, 'focus')]//*[contains(@class, 'icon-edit')]")).click();
    switchToDefaultContent();

    waitUntil(visibilityOfElementLocated(byTabContainingCaption("Settings")));

    // WHEN
    simulateKeyPress(Keys.ESCAPE);
    // THEN
    waitUntil(visibilityOfElementLocated(byConfirmationOverlay));

    // Validate that PageEditor is not in preview mode.
    url = getCurrentDriverUrl();
    assertTrue("Subapp should still be in edit mode.", url.contains("edit"));
    assertFalse("Subapp should still be in edit mode.", url.contains("view"));

    // WHEN
    simulateKeyPress(Keys.ENTER);
    // THEN
    waitUntil(invisibilityOfElementLocated(byConfirmationOverlay));

    // Validate that PageEditor is not in preview mode.
    url = getCurrentDriverUrl();
    assertTrue("Subapp should still be in edit mode.", url.contains("edit"));
    assertFalse("Subapp should still be in edit mode.", url.contains("view"));
}

From source file:info.magnolia.integrationtests.uitest.KeyboardShortcutUITest.java

License:Open Source License

/**
 * Get a detailEditor to test by running 'Add contact' action.
 * Fill in a field, then hit the ESCAPE key and verify that a confirmation is displayed.
 * Hit ESCAPE and verify that the confirmation closes.
 * Hit ESCAPE again and verify that confirmation is displayed.
 * Hit ENTER to confirm and verify the dialog is closed.
 *///from   w  ww .ja va  2  s .c o  m
@Test
public void escapeHandlingOnDetailEditor() {
    // GIVEN
    final String nameFirst = "escapeHandlingOnDetailEditor";
    WebElement confirmation;

    getAppIcon("Contacts").click();
    waitUntil(appIsLoaded());
    assertAppOpen("Contacts");
    getActionBarItem("Add contact").click();
    waitUntil(appIsLoaded());
    openTabWithCaption("Personal");
    waitUntil(tabIsOpen("Personal"));
    setFormTextFieldText("First name", nameFirst);

    // First pass - we cancel the ESCAPE action.
    // WHEN
    simulateKeyPress(Keys.ESCAPE);
    waitUntil(visibilityOfElementLocated(byConfirmationOverlay));
    // THEN
    confirmation = getConfirmationOverlay();
    assertTrue("ESC key should have caused confirmation overlay.", isExisting(confirmation));

    // WHEN
    simulateKeyPress(Keys.ESCAPE);
    // THEN
    waitUntil(invisibilityOfElementLocated(byConfirmationOverlay));

    // Now do it again, but this time confirm the detailEditor closing.

    // WHEN
    simulateKeyPress(Keys.ESCAPE);
    waitUntil(visibilityOfElementLocated(byConfirmationOverlay));
    // THEN
    confirmation = getConfirmationOverlay();
    assertTrue("ESC key should have caused confirmation overlay.", isExisting(confirmation));
    // WHEN
    simulateKeyPress(Keys.RETURN);
    // THEN
    waitUntil(invisibilityOfElementLocated(byConfirmationOverlay));
}

From source file:org.auraframework.components.ui.autocomplete.AutocompleteUITest.java

License:Apache License

/**
 * Test accessibility when autocompleteOptions is extended 
 *//*from   w w  w . j  av  a  2  s.  c  o m*/
// Excluding mobile devices since they dont have arrow key functionality
@ExcludeBrowsers({ BrowserType.IE7, BrowserType.IE8, BrowserType.ANDROID_PHONE, BrowserType.ANDROID_TABLET,
        BrowserType.IPAD, BrowserType.IPHONE })
public void _testAutoCompleteOptionExtentionAccessibility() throws Exception {
    open(URL);
    WebDriver driver = getDriver();
    WebElement input = getAutoCompleteInput(driver, AUTOCOMPLETE_COMPONENT.get("OptionExtention"));

    // do search
    input.sendKeys("o");
    WebElement list = getAutoCompleteList(driver, AUTOCOMPLETE_COMPONENT.get("OptionExtention"));
    waitForAutoCompleteListVisible(list, true);

    // go to second option in list.
    input.sendKeys(Keys.ARROW_DOWN + "" + Keys.ARROW_DOWN + "");
    list = getAutoCompleteList(driver, AUTOCOMPLETE_COMPONENT.get("OptionExtention"));
    List<WebElement> options = getAutoCompleteListOptions(list, OptionType.AUTOCOMPLETE_CUSTOM_OPTION);
    waitForOptionHighlighted(options.get(1));

    // verify aria attributes
    String ariaActiveDecendant = input.getAttribute("aria-activedescendant");
    String ariaExpanded = input.getAttribute("aria-expanded");
    String optionId = options.get(1).findElement(By.tagName("a")).getAttribute("id");
    assertTrue("aria-expanded should be true", Boolean.parseBoolean(ariaExpanded));
    assertEquals("aria-activedescendant incorrect", optionId, ariaActiveDecendant);

    // escape and verify everything gets reset
    input.sendKeys(Keys.ESCAPE);
    list = getAutoCompleteList(driver, AUTOCOMPLETE_COMPONENT.get("OptionExtention"));
    waitForAutoCompleteListVisible(list, false);

    ariaActiveDecendant = input.getAttribute("aria-activedescendant");
    ariaExpanded = input.getAttribute("aria-expanded");
    assertFalse("aria-expanded should be false after hitting escape", Boolean.parseBoolean(ariaExpanded));
    assertEquals("aria-activedescendant incorrect after hitting escape", "", ariaActiveDecendant);
}

From source file:org.auraframework.components.ui.dialogUITest.DialogUITest.java

License:Apache License

@ExcludeBrowsers({ BrowserType.ANDROID_PHONE, BrowserType.ANDROID_TABLET, BrowserType.IPAD,
        BrowserType.IPHONE })//from w w  w  . j  a v a 2  s.c o  m
public void testDialogNonModalEscapeButton() throws MalformedURLException, URISyntaxException {
    open(URL_NON_MODAL);

    WebDriver driver = getDriver();
    openDialogBox(driver);
    // Grab the focused element, then press escape to close dialog box
    String classOfActiveElem = "button[title*='" + auraUITestingUtil.getEval(TITLE) + "']";
    WebElement element = driver.findElement(By.cssSelector(classOfActiveElem));

    element.sendKeys(Keys.ESCAPE);

    // Wait for DialogBox to close
    waitForComponentToChangeStatus("div[class*='dialog']", "className", "hidden", false);

    // Make sure no data was submitted
    element = driver.findElement(By.cssSelector(RESULT_LABEL));
    assertEquals("The escape button submitted data, and it shouldn't have", NOT_SUBMITTED,
            element.getAttribute("value"));
}

From source file:org.auraframework.components.ui.inputDate.BaseInputDateUITester.java

License:Apache License

@ExcludeBrowsers({ BrowserType.ANDROID_PHONE, BrowserType.ANDROID_TABLET, BrowserType.IPAD,
        BrowserType.IPHONE })//ww w . java2 s  .c o  m
public void testEscape() throws Exception {
    open(URL);

    boolean escButtonClosedCal = false;

    // Setting focus to the Calendar Icon and clicking on it
    WebElement element = findDomElement(By.cssSelector(DATE_ICON_SEL));
    element.click();

    // Looking for the current date, which should be focused on
    element = findDomElement(By.cssSelector(SELECTED_DATE));

    // Hitting escape to close the Calendar
    element.sendKeys(Keys.ESCAPE);

    // Want to get a NoSuchElementExpection when looking for the class
    // if visible exists, that means that the calendar did not close
    element = findDomElement(By.cssSelector("div[class*='uiDatePicker']"));

    escButtonClosedCal = !element.getAttribute("class").contains("visible");

    assertTrue("Escape button did not close the calendar", escButtonClosedCal);
}

From source file:org.auraframework.components.ui.listSorter.ListSorterUITest.java

License:Apache License

/**
 * Verify pressing ESC while listSorter is opened should close the list sorter
 * // w w w  .  j  av a2s .c o  m
 * @throws MalformedURLException
 * @throws URISyntaxException
 */
public void testEscOfListSorter() throws MalformedURLException, URISyntaxException {
    verifyTabOutAndEscBehaviour(Keys.ESCAPE, false);
}

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

License:Apache License

private void testActionMenuViaKeyboardInteractionForApp(String appName)
        throws MalformedURLException, URISyntaxException {
    open(appName);/* w  w  w.  java 2 s. c o m*/
    WebDriver driver = this.getDriver();
    String label = "trigger";
    String menuName = "actionMenu";
    String menuItem1 = "actionItem1";
    String menuItem3 = "actionItem3";
    String menuItem4 = "actionItem4";
    WebElement menuLabel = driver.findElement(By.className(label));
    WebElement actionMenu = driver.findElement(By.className(menuName));
    WebElement actionItem1 = driver.findElement(By.className(menuItem1));
    WebElement actionItem1Element = actionItem1.findElement(By.tagName("a"));
    WebElement actionItem3 = driver.findElement(By.className(menuItem3));
    WebElement actionItem3Element = actionItem3.findElement(By.tagName("a"));
    WebElement actionItem4 = driver.findElement(By.className(menuItem4));
    WebElement actionItem4Element = actionItem4.findElement(By.tagName("a"));

    // click on menu list
    menuLabel.click();
    // check menu list is visible after the click
    assertTrue("Menu list should be visible", actionMenu.getAttribute("class").contains("visible"));

    // default focus on action item1
    assertEquals("Focus should be on actionItem1", actionItem1Element.getText(),
            auraUITestingUtil.getActiveElementText());

    // press down key twice
    actionItem1Element.sendKeys(Keys.DOWN, Keys.DOWN);

    // verify focus on action item3
    auraUITestingUtil.setHoverOverElement(menuItem3);
    assertEquals("Focus should be on actionItem3", actionItem3Element.getText(),
            auraUITestingUtil.getActiveElementText());

    actionItem3.click();
    assertEquals("Item3 unchecked after pressing Enter key", "Inter Milan", menuLabel.getText());

    menuLabel.click();
    // focus on action item4
    auraUITestingUtil.setHoverOverElement(menuItem4);
    assertEquals("Focus should be on actionItem4", actionItem4Element.getText(),
            auraUITestingUtil.getActiveElementText());

    actionItem4Element.sendKeys(Keys.UP);
    // verify focus on action item3
    assertEquals("Focus should be on actionItem3", actionItem3Element.getText(),
            auraUITestingUtil.getActiveElementText());

    // press space key and check if item3 got selected
    actionItem3Element.sendKeys(Keys.SPACE);
    assertEquals("Item3 not selected after pressing space key", "Inter Milan", menuLabel.getText());

    menuLabel.click();
    assertTrue("Menu list should be visible", actionMenu.getAttribute("class").contains("visible"));
    auraUITestingUtil.setHoverOverElement(menuItem1);
    actionItem1Element.sendKeys(Keys.ESCAPE);
    assertFalse("Menu list should not be visible", actionMenu.getAttribute("class").contains("visible"));
}

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

License:Apache License

public void testMenuRadio() throws MalformedURLException, URISyntaxException {
    open(MENUTEST_APP);/* w ww . java  2s .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());
}