Example usage for org.openqa.selenium Keys DOWN

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

Introduction

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

Prototype

Keys DOWN

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

Click Source Link

Usage

From source file:org.eclipse.che.selenium.core.action.MacOSActionsTest.java

License:Open Source License

@Test
public void testShouldReplacePageDownCharSequence() throws Exception {
    MacOSActions actions = new MacOSActions(webDriver);

    final CharSequence[] charSequences = actions.modifyCharSequence(Keys.ESCAPE, Keys.PAGE_DOWN);

    assertNotNull(charSequences);//w w w .ja  v a2  s .  c om
    assertEquals(charSequences.length, 2);

    assertEquals(charSequences[0], Keys.ESCAPE);
    assertEquals(charSequences[1], Keys.chord(Keys.COMMAND, Keys.DOWN));
}

From source file:org.eclipse.che.selenium.git.AddFilesToIndexTest.java

License:Open Source License

@Test
public void addFilesTest() throws InterruptedException {
    projectExplorer.waitProjectExplorer();
    projectExplorer.openItemByPath(PROJECT_NAME);
    menu.runCommand(TestMenuCommandsConstants.Git.GIT, TestMenuCommandsConstants.Git.INITIALIZE_REPOSITORY);
    askDialog.waitFormToOpen();//from  www  . j  a va 2 s .  c  o  m
    askDialog.clickOkBtn();
    askDialog.waitFormToClose();
    git.waitGitStatusBarWithMess(TestGitConstants.GIT_INITIALIZED_SUCCESS);
    events.clickProjectEventsTab();
    events.waitExpectedMessage(TestGitConstants.GIT_INITIALIZED_SUCCESS);

    // perform init commit
    projectExplorer.quickExpandWithJavaScript();
    projectExplorer.selectItem(PROJECT_NAME);
    menu.runCommand(TestMenuCommandsConstants.Git.GIT, TestMenuCommandsConstants.Git.COMMIT);
    git.waitAndRunCommit("init");
    loader.waitOnClosed();

    // check state of the index
    projectExplorer.selectItem(PROJECT_NAME);
    menu.runCommand(TestMenuCommandsConstants.Git.GIT, TestMenuCommandsConstants.Git.ADD_TO_INDEX);
    git.waitGitStatusBarWithMess(TestGitConstants.GIT_NOTHING_TO_ADD);
    events.clickProjectEventsTab();
    events.waitExpectedMessage(TestGitConstants.GIT_NOTHING_TO_ADD);

    //Edit index.jsp
    projectExplorer.openItemByVisibleNameInExplorer("index.jsp");
    editor.waitActiveEditor();
    editor.typeTextIntoEditor(Keys.PAGE_DOWN.toString());
    editor.typeTextIntoEditor(Keys.END.toString());
    editor.typeTextIntoEditor(Keys.ENTER.toString());
    editor.typeTextIntoEditor("<!-- Testing add to index-->");
    loader.waitOnClosed();

    //Add this file to index
    projectExplorer.selectItem(PROJECT_NAME + "/src/main/webapp/index.jsp");
    menu.runCommand(TestMenuCommandsConstants.Git.GIT, TestMenuCommandsConstants.Git.ADD_TO_INDEX);
    git.waitGitStatusBarWithMess(TestGitConstants.GIT_ADD_TO_INDEX_SUCCESS);
    events.clickProjectEventsTab();
    events.waitExpectedMessage(TestGitConstants.GIT_ADD_TO_INDEX_SUCCESS);

    //Check status
    menu.runCommand(TestMenuCommandsConstants.Git.GIT, TestMenuCommandsConstants.Git.STATUS);
    loader.waitOnClosed();
    git.waitGitStatusBarWithMess(STATUS_MESSAGE_ONE_FILE);

    //Edit GreetingController.java
    projectExplorer.openItemByPath(PROJECT_NAME + "/src/main/java/org/eclipse/qa/examples/AppController.java");
    editor.waitActiveEditor();
    editor.setCursorToLine(16);
    editor.typeTextIntoEditor("//Testing add to index");
    loader.waitOnClosed();

    //Create new.css file
    projectExplorer.selectItem(PROJECT_NAME + "/src/main/webapp");
    menu.runCommand(TestMenuCommandsConstants.Project.PROJECT, TestMenuCommandsConstants.Project.New.NEW,
            TestMenuCommandsConstants.Project.New.CSS_FILE);
    askForValueDialog.waitFormToOpen();
    askForValueDialog.typeAndWaitText("new");
    askForValueDialog.clickOkBtn();

    //Add all files to index
    projectExplorer.selectItem(PROJECT_NAME);
    menu.runCommand(TestMenuCommandsConstants.Git.GIT, TestMenuCommandsConstants.Git.ADD_TO_INDEX);
    git.waitAddToIndexFormToOpen();
    git.waitAddToIndexFileName("Add content of folder " + PROJECT_NAME + " to index?");
    git.confirmAddToIndexForm();
    git.waitGitStatusBarWithMess(TestGitConstants.GIT_ADD_TO_INDEX_SUCCESS);
    events.clickProjectEventsTab();
    events.waitExpectedMessage(TestGitConstants.GIT_ADD_TO_INDEX_SUCCESS);

    //Check status
    menu.runCommand(TestMenuCommandsConstants.Git.GIT, TestMenuCommandsConstants.Git.STATUS);
    git.waitGitStatusBarWithMess(STATUS_MESSAGE_ALL_FILES);

    //Edit GreetingController.java
    editor.selectTabByName("AppController");
    editor.waitActiveEditor();
    editor.typeTextIntoEditor(Keys.DOWN.toString());
    editor.typeTextIntoEditor(Keys.DOWN.toString());
    editor.typeTextIntoEditor(Keys.DOWN.toString());
    editor.typeTextIntoEditor("//Testing add to index");
    loader.waitOnClosed();

    //Edit index.jsp
    editor.selectTabByName("index.jsp");
    editor.waitActiveEditor();
    editor.typeTextIntoEditor(Keys.PAGE_DOWN.toString());
    editor.typeTextIntoEditor(Keys.ENTER.toString());
    editor.typeTextIntoEditor("<!-- Testing add to index-->");
    loader.waitOnClosed();

    //Edit new.css
    editor.selectTabByName("new.css");
    editor.waitActiveEditor();
    editor.typeTextIntoEditor(Keys.PAGE_DOWN.toString());
    editor.typeTextIntoEditor(Keys.ENTER.toString());
    editor.typeTextIntoEditor("/* Testing add to index */");
    loader.waitOnClosed();

    //Check status and add to index all files
    menu.runCommand(TestMenuCommandsConstants.Git.GIT, TestMenuCommandsConstants.Git.STATUS);
    git.waitGitStatusBarWithMess(STATUS_MESSAGE_AFTER_EDIT);
    projectExplorer.selectItem(PROJECT_NAME);
    menu.runCommand(TestMenuCommandsConstants.Git.GIT, TestMenuCommandsConstants.Git.ADD_TO_INDEX);
    git.waitGitStatusBarWithMess(TestGitConstants.GIT_ADD_TO_INDEX_SUCCESS);

    // delete README file and add to index
    deleteFromMenuFile();
    projectExplorer.selectItem(PROJECT_NAME);
    menu.runCommand(TestMenuCommandsConstants.Git.GIT, TestMenuCommandsConstants.Git.ADD_TO_INDEX);
    git.waitGitStatusBarWithMess(TestGitConstants.GIT_ADD_TO_INDEX_SUCCESS);
    menu.runCommand(TestMenuCommandsConstants.Git.GIT, TestMenuCommandsConstants.Git.STATUS);
    git.waitGitStatusBarWithMess(STATUS_AFTER_DELETE_FILE);
}

From source file:org.eclipse.che.selenium.git.GitPullTest.java

License:Open Source License

@Test
public void pullTest() throws Exception {
    //Reset test repository's HEAD to default commit
    gitHubClientService.hardResetHeadToCommit(REPO_NAME, DEFAULT_COMMIT_SSH, gitHubUsername, gitHubPassword);
    projectExplorer.waitProjectExplorer();

    String repoUrl = "git@github.com:" + gitHubUsername + "/gitPullTest.git";
    git.importJavaApp(repoUrl, SECOND_PROJECT_NAME, Wizard.TypeProject.MAVEN);
    git.importJavaApp(repoUrl, FIRST_PROJECT_NAME, Wizard.TypeProject.MAVEN);

    projectExplorer.quickExpandWithJavaScript();

    //Change contents index.jsp
    loader.waitOnClosed();//from www  . ja  v a  2  s .c o  m
    projectExplorer.openItemByPath(FIRST_PROJECT_NAME + "/my-webapp/src/main/webapp/index.jsp");
    editor.waitActiveEditor();
    editor.typeTextIntoEditor(NEW_CONTENT_JSP);
    editor.waitTextIntoEditor(NEW_CONTENT_JSP);
    editor.waitTabFileWithSavedStatus("index.jsp");
    loader.waitOnClosed();
    editor.closeFileByNameWithSaving("index.jsp");
    editor.waitWhileFileIsClosed("index.jsp");

    //Change contents in java file
    projectExplorer
            .openItemByPath(FIRST_PROJECT_NAME + "/my-webapp/src/main/java/helloworld/GreetingController.java");
    editor.waitActiveEditor();
    editor.typeTextIntoEditor(Keys.DOWN.toString());
    editor.typeTextIntoEditor(NEW_CONTENT_JAVA);
    editor.waitTextIntoEditor(NEW_CONTENT_JAVA);
    editor.waitTabFileWithSavedStatus("GreetingController");
    loader.waitOnClosed();
    editor.closeFileByNameWithSaving("GreetingController");
    editor.waitWhileFileIsClosed("GreetingController");

    //Remove web.xml from index
    projectExplorer.selectItem(FIRST_PROJECT_NAME + "/my-webapp/src/main/webapp/WEB-INF/web.xml");
    menu.runCommand(TestMenuCommandsConstants.Git.GIT, TestMenuCommandsConstants.Git.REMOVE_FROM_INDEX);
    git.waitRemoveFromIndexFormToOpen();
    git.waitRemoveFromIndexFileName("Remove file web.xml from index?");
    git.confirmRemoveFromIndexForm();
    loader.waitOnClosed();

    //Add all files to index
    projectExplorer
            .waitItem(FIRST_PROJECT_NAME + "/my-webapp/src/main/java/helloworld/GreetingController.java");
    projectExplorer.waitItem(FIRST_PROJECT_NAME + "/my-webapp/src/main/webapp/index.jsp");
    loader.waitOnClosed();
    projectExplorer.selectItem(FIRST_PROJECT_NAME);
    menu.runCommand(TestMenuCommandsConstants.Git.GIT, TestMenuCommandsConstants.Git.ADD_TO_INDEX);
    git.waitGitStatusBarWithMess(TestGitConstants.GIT_ADD_TO_INDEX_SUCCESS);
    events.clickProjectEventsTab();
    events.waitExpectedMessage(TestGitConstants.GIT_ADD_TO_INDEX_SUCCESS);

    //Commit and push changes
    menu.runCommand(TestMenuCommandsConstants.Git.GIT, TestMenuCommandsConstants.Git.COMMIT);
    git.waitAndRunCommit(COMMIT_MESSAGE);
    menu.runCommand(TestMenuCommandsConstants.Git.GIT, TestMenuCommandsConstants.Git.Remotes.REMOTES_TOP,
            TestMenuCommandsConstants.Git.Remotes.PUSH);
    git.waitPushFormToOpen();
    git.clickPush();
    git.waitPushFormToClose();
    consoles.waitProcessInProcessConsoleTree("Git push", LOADER_TIMEOUT_SEC);

    git.waitGitStatusBarWithMess("Successfully pushed");
    git.waitGitStatusBarWithMess("to git@github.com:" + gitHubUsername + "/gitPullTest.git");

    events.clickProjectEventsTab();
    events.waitExpectedMessage(PUSH_MSG);
    projectExplorer.openItemByPath(FIRST_PROJECT_NAME);

    // Perform git pull and check the message in the second project
    projectExplorer.selectItem(SECOND_PROJECT_NAME);
    loader.waitOnClosed();
    menu.runCommand(TestMenuCommandsConstants.Git.GIT, TestMenuCommandsConstants.Git.Remotes.REMOTES_TOP,
            TestMenuCommandsConstants.Git.Remotes.PULL);
    git.waitPullFormToOpen();
    git.clickPull();
    git.waitPullFormToClose();
    loader.waitOnClosed();
    consoles.waitProcessInProcessConsoleTree("Git pull", LOADER_TIMEOUT_SEC);

    git.waitGitStatusBarWithMess("Successfully pulled");
    git.waitGitStatusBarWithMess("from git@github.com:" + gitHubUsername + "/gitPullTest");

    events.clickProjectEventsTab();
    events.waitExpectedMessage("Pulled from git@github.com:" + gitHubUsername + "/gitPullTest.git");

    // check changes in the second project
    projectExplorer.openItemByPath(
            SECOND_PROJECT_NAME + "/my-webapp/src/main/java/helloworld/GreetingController.java");
    editor.waitActiveEditor();
    editor.waitTextIntoEditor(NEW_CONTENT_JAVA);
    projectExplorer.openItemByPath(SECOND_PROJECT_NAME + "/my-webapp/src/main/webapp/index.jsp");
    editor.waitActiveEditor();
    editor.waitTextIntoEditor(NEW_CONTENT_JSP);
    projectExplorer.waitItemIsDisappeared(SECOND_PROJECT_NAME + "/my-webapp/src/main/webapp/WEB-INF/web.xml");
}

From source file:org.eclipse.che.selenium.git.PushingChangesTest.java

License:Open Source License

@Test
public void pushChangesTest() throws Exception {
    gitHubClientService.hardResetHeadToCommit(REPO_NAME, DEFAULT_COMMIT_SSH, gitHubUsername, gitHubPassword);

    //Clone project
    projectExplorer.waitProjectExplorer();
    menu.runCommand(TestMenuCommandsConstants.Workspace.WORKSPACE,
            TestMenuCommandsConstants.Workspace.IMPORT_PROJECT);
    importProject.waitAndTypeImporterAsGitInfo("git@github.com:" + gitHubUsername + "/pushChangesTest.git",
            PROJECT_NAME);//from  www .j a v  a  2s .com
    projectWizard.waitCreateProjectWizardForm();
    projectWizard.selectTypeProject(Wizard.TypeProject.MAVEN);
    loader.waitOnClosed();
    projectWizard.clickSaveButton();
    loader.waitOnClosed();
    projectWizard.waitCreateProjectWizardFormIsClosed();
    projectExplorer.waitProjectExplorer();
    projectExplorer.waitItem(PROJECT_NAME);

    //Create new file and push it.
    git.createNewFileAndPushItToGitHub(PROJECT_NAME, "new.html");
    consoles.waitProcessInProcessConsoleTree("Git push", LOADER_TIMEOUT_SEC);

    git.waitGitStatusBarWithMess("Successfully pushed");
    git.waitGitStatusBarWithMess("to git@github.com:" + gitHubUsername + "/pushChangesTest.git");

    git.closeGitInfoPanel();
    events.clickProjectEventsTab();
    loader.waitOnClosed();
    events.waitExpectedMessage(PUSH_MSG);

    //Change contents index.jsp
    projectExplorer.quickExpandWithJavaScript();
    projectExplorer.openItemByPath(PROJECT_NAME + "/my-webapp/src/main/webapp/index.jsp");
    editor.waitActiveEditor();
    editor.typeTextIntoEditor(NEW_CONTENT_JSP);
    editor.waitTabFileWithSavedStatus("index.jsp");
    loader.waitOnClosed();
    editor.closeFileByNameWithSaving("index.jsp");
    editor.waitWhileFileIsClosed("index.jsp");

    //Edit GreetingController.java
    projectExplorer.openItemByVisibleNameInExplorer("GreetingController.java");
    editor.waitActiveEditor();
    editor.typeTextIntoEditor(Keys.DOWN.toString());
    editor.typeTextIntoEditor(NEW_CONTENT_JAVA);
    editor.waitTextIntoEditor(NEW_CONTENT_JAVA);
    editor.waitTabFileWithSavedStatus("GreetingController");
    loader.waitOnClosed();
    editor.closeFileByNameWithSaving("GreetingController");
    editor.waitWhileFileIsClosed("GreetingController");

    //Commit changes
    projectExplorer.selectVisibleItem("GreetingController.java");
    menu.runCommand(GIT, COMMIT);
    git.waitAndRunCommit(COMMIT_MESSAGE);
    loader.waitOnClosed();
    git.waitGitStatusBarWithMess(TestGitConstants.COMMIT_MESSAGE_SUCCESS);
    events.clickProjectEventsTab();
    events.waitExpectedMessage(TestGitConstants.COMMIT_MESSAGE_SUCCESS);

    //Push changes
    menu.runCommand(GIT, REMOTES_TOP, PUSH);
    loader.waitOnClosed();
    git.waitPushFormToOpen();
    git.clickPush();
    git.waitPushFormToClose();
    consoles.waitProcessInProcessConsoleTree("Git push", LOADER_TIMEOUT_SEC);
    git.waitGitStatusBarWithMess("Successfully pushed");
    git.waitGitStatusBarWithMess("to git@github.com:" + gitHubUsername + "/pushChangesTest.git");
    events.clickProjectEventsTab();
    events.waitExpectedMessage(PUSH_MSG);

    //Call Push again
    menu.runCommand(GIT, REMOTES_TOP, PUSH);
    loader.waitOnClosed();
    git.waitPushFormToOpen();
    git.clickPush();
    git.waitPushFormToClose();
    notifications.waitExpectedMessageOnProgressPanelAndClosed(PUSH_NOTHING);
    git.waitGitStatusBarWithMess(PUSH_NOTHING);
    events.clickProjectEventsTab();
    events.waitExpectedMessage(PUSH_MSG);
    events.clearAllMessages();

    //Soft reset
    gitHubClientService.hardResetHeadToCommit(REPO_NAME, DEFAULT_COMMIT_SSH, gitHubUsername, gitHubPassword);
    menu.runCommand(TestMenuCommandsConstants.Git.GIT, TestMenuCommandsConstants.Git.RESET);
    git.waitResetWindowOpen();
    git.selectCommitResetWindow(3);
    git.selectSoftReset();
    git.clickResetBtn();
    git.waitResetWindowClose();

    //Commit changes and push directly from commit window
    projectExplorer.selectItem(PROJECT_NAME);
    menu.runCommand(GIT, COMMIT);
    git.waitAndRunCommitWithPush(COMMIT_MESSAGE, "origin/master");
    loader.waitOnClosed();
    git.waitGitStatusBarWithMess(TestGitConstants.COMMIT_MESSAGE_SUCCESS);
    events.clickProjectEventsTab();
    events.waitExpectedMessage(TestGitConstants.COMMIT_MESSAGE_SUCCESS);
    events.waitExpectedMessage(PUSH_MSG);

    //Amend commit
    projectExplorer.selectVisibleItem("GreetingController.java");
    menu.runCommand(GIT, COMMIT);
    git.waitAndRunAmendCommitMessage(COMMIT_MESSAGE);
    loader.waitOnClosed();
    git.waitGitStatusBarWithMess(TestGitConstants.COMMIT_MESSAGE_SUCCESS);
    events.clickProjectEventsTab();
    events.waitExpectedMessage(TestGitConstants.COMMIT_MESSAGE_SUCCESS);

    //Force push
    menu.runCommand(GIT, REMOTES_TOP, PUSH);
    loader.waitOnClosed();
    git.waitPushFormToOpen();
    git.selectForcePushCheckBox();
    git.clickPush();
    git.waitPushFormToClose();
    consoles.waitProcessInProcessConsoleTree("Git push", LOADER_TIMEOUT_SEC);
    git.waitGitStatusBarWithMess("Successfully pushed");
    git.waitGitStatusBarWithMess("to git@github.com:" + gitHubUsername + "/pushChangesTest.git");
    events.clickProjectEventsTab();
    events.waitExpectedMessage(PUSH_MSG);
}

From source file:org.eclipse.scout.rt.testing.ui.rap.RapMock.java

License:Open Source License

protected Keys toSeleniumKey(Key key) {
    switch (key) {
    case Shift:/* www  .j a  v a2s  .co  m*/
        return Keys.SHIFT;
    case Control:
        return Keys.CONTROL;
    case Alt:
        return Keys.ALT;
    case Delete:
        return Keys.DELETE;
    case Backspace:
        return Keys.BACK_SPACE;
    case Enter:
        return Keys.ENTER;
    case Esc:
        return Keys.ESCAPE;
    case Tab:
        return Keys.TAB;
    case ContextMenu:
        throw new IllegalArgumentException("Unknown keyboard key: " + key);
    case Up:
        return Keys.UP;
    case Down:
        return Keys.DOWN;
    case Left:
        return Keys.LEFT;
    case Right:
        return Keys.RIGHT;
    case Windows:
        return Keys.META;
    case F1:
        return Keys.F1;
    case F2:
        return Keys.F2;
    case F3:
        return Keys.F3;
    case F4:
        return Keys.F4;
    case F5:
        return Keys.F5;
    case F6:
        return Keys.F6;
    case F7:
        return Keys.F7;
    case F8:
        return Keys.F8;
    case F9:
        return Keys.F9;
    case F10:
        return Keys.F10;
    case F11:
        return Keys.F11;
    case F12:
        return Keys.F12;
    case Home:
        return Keys.HOME;
    case End:
        return Keys.END;
    case PageUp:
        return Keys.PAGE_UP;
    case PageDown:
        return Keys.PAGE_DOWN;
    case NumPad0:
        return Keys.NUMPAD0;
    case NumPad1:
        return Keys.NUMPAD1;
    case NumPad2:
        return Keys.NUMPAD2;
    case NumPad3:
        return Keys.NUMPAD3;
    case NumPad4:
        return Keys.NUMPAD4;
    case NumPad5:
        return Keys.NUMPAD5;
    case NumPad6:
        return Keys.NUMPAD6;
    case NumPad7:
        return Keys.NUMPAD7;
    case NumPad8:
        return Keys.NUMPAD8;
    case NumPadMultiply:
        return Keys.MULTIPLY;
    case NumPadDivide:
        return Keys.DIVIDE;
    case NumPadAdd:
        return Keys.ADD;
    case NumPadSubtract:
        return Keys.SUBTRACT;
    case NumPadDecimal:
        return Keys.DECIMAL;
    case NumPadSeparator:
        return Keys.SEPARATOR;
    default:
        throw new IllegalArgumentException("Unknown keyboard key: " + key);
    }
}

From source file:org.openmrs.module.mirebalais.smoke.pageobjects.forms.DispenseMedicationForm.java

License:Open Source License

private void autocompleteMedicationWith(String name) throws InterruptedException {
    WebElement autocomplete = driver.findElement(medicationNameAutocompleteInput);

    autocomplete.sendKeys(name);// w  ww.j a  va 2s  .  co m
    wait5seconds.until(firstResultIsDisplayed);
    autocomplete.sendKeys(Keys.DOWN);
    autocomplete.sendKeys(Keys.ENTER);
}

From source file:org.richfaces.tests.metamer.ftest.abstractions.AbstractListScrollingTest.java

License:Open Source License

@SuppressWarnings("unchecked")
protected void checkScrollingWithKeyboard(WebElement focusElement, List<WebElement> listOfItems,
        Action actionBefore) {//www  .  j av a  2  s . c  om
    // to stabilize test in all templates
    getUnsafeAttributes("").set("listHeight", 60);

    if (actionBefore != null) {
        actionBefore.perform();
    }

    WebElement lastItem = ChoicePickerHelper.byIndex().last().pick(listOfItems);
    WebElement firstItem = listOfItems.get(0);

    lastItem.click();// focus on last item
    assertFalse(jsUtils.isElementInViewPort(firstItem), "First item should not be visible!");
    assertTrue(jsUtils.isElementInViewPort(lastItem), "Last item should be visible!");

    jsUtils.scrollToView(focusElement);
    keyboard.sendKeys(Keys.DOWN);
    assertTrue(jsUtils.isElementInViewPort(firstItem), "First item should be visible!");
    assertFalse(jsUtils.isElementInViewPort(lastItem), "Last item should not be visible!");

    keyboard.sendKeys(Keys.UP);
    assertFalse(jsUtils.isElementInViewPort(firstItem), "First item should not be visible!");
    assertTrue(jsUtils.isElementInViewPort(lastItem), "Last item should be visible!");

    for (int i = 0; i < 10; i++) {
        keyboard.sendKeys(Keys.UP);
    }
    assertFalse(jsUtils.isElementInViewPort(firstItem), "First item should not be visible!");
    assertFalse(jsUtils.isElementInViewPort(lastItem), "Last item should not be visible!");
}

From source file:org.safs.selenium.webdriver.lib.WDLibrary.java

License:Open Source License

/**
 * Convert a Java KEYCODE to a Selenium WebDriver Keys Enum
 * @param keycode int, a java keycode//from   ww w.ja va  2  s .c o  m
 * @return Keys enum for (primarily) non-printable (control) characters, or null.
 */
public static Keys convertToKeys(int keycode) {
    Keys key = null;
    switch (keycode) {
    case java.awt.event.KeyEvent.VK_ADD:
        key = Keys.ADD;
        break;
    case java.awt.event.KeyEvent.VK_ALT:
        key = Keys.ALT;
        break;
    case java.awt.event.KeyEvent.VK_KP_DOWN:
        key = Keys.ARROW_DOWN;
        break;
    case java.awt.event.KeyEvent.VK_KP_LEFT:
        key = Keys.ARROW_LEFT;
        break;
    case java.awt.event.KeyEvent.VK_KP_RIGHT:
        key = Keys.ARROW_RIGHT;
        break;
    case java.awt.event.KeyEvent.VK_KP_UP:
        key = Keys.ARROW_UP;
        break;
    case java.awt.event.KeyEvent.VK_BACK_SPACE:
        key = Keys.BACK_SPACE;
        break;
    case java.awt.event.KeyEvent.VK_CANCEL:
        key = Keys.CANCEL;
        break;
    case java.awt.event.KeyEvent.VK_CLEAR:
        key = Keys.CLEAR;
        break;
    case java.awt.event.KeyEvent.VK_WINDOWS:
        key = Keys.COMMAND;
        break;
    case java.awt.event.KeyEvent.VK_CONTROL:
        key = Keys.CONTROL;
        break;
    case java.awt.event.KeyEvent.VK_DECIMAL:
        key = Keys.DECIMAL;
        break;
    case java.awt.event.KeyEvent.VK_DELETE:
        key = Keys.DELETE;
        break;
    case java.awt.event.KeyEvent.VK_DIVIDE:
        key = Keys.DIVIDE;
        break;
    case java.awt.event.KeyEvent.VK_DOWN:
        key = Keys.DOWN;
        break;
    case java.awt.event.KeyEvent.VK_END:
        key = Keys.END;
        break;
    case java.awt.event.KeyEvent.VK_ENTER:
        key = Keys.ENTER;
        break;
    case java.awt.event.KeyEvent.VK_EQUALS:
        key = Keys.EQUALS;
        break;
    case java.awt.event.KeyEvent.VK_ESCAPE:
        key = Keys.ESCAPE;
        break;
    case java.awt.event.KeyEvent.VK_F1:
        key = Keys.F1;
        break;
    case java.awt.event.KeyEvent.VK_F2:
        key = Keys.F2;
        break;
    case java.awt.event.KeyEvent.VK_F3:
        key = Keys.F3;
        break;
    case java.awt.event.KeyEvent.VK_F4:
        key = Keys.F4;
        break;
    case java.awt.event.KeyEvent.VK_F5:
        key = Keys.F5;
        break;
    case java.awt.event.KeyEvent.VK_F6:
        key = Keys.F6;
        break;
    case java.awt.event.KeyEvent.VK_F7:
        key = Keys.F7;
        break;
    case java.awt.event.KeyEvent.VK_F8:
        key = Keys.F8;
        break;
    case java.awt.event.KeyEvent.VK_F9:
        key = Keys.F9;
        break;
    case java.awt.event.KeyEvent.VK_F10:
        key = Keys.F10;
        break;
    case java.awt.event.KeyEvent.VK_F11:
        key = Keys.F11;
        break;
    case java.awt.event.KeyEvent.VK_F12:
        key = Keys.F12;
        break;
    case java.awt.event.KeyEvent.VK_HELP:
        key = Keys.HELP;
        break;
    case java.awt.event.KeyEvent.VK_HOME:
        key = Keys.HOME;
        break;
    case java.awt.event.KeyEvent.VK_INSERT:
        key = Keys.INSERT;
        break;
    case java.awt.event.KeyEvent.VK_LEFT:
        key = Keys.LEFT;
        break;
    case java.awt.event.KeyEvent.VK_META:
        key = Keys.META;
        break;
    case java.awt.event.KeyEvent.VK_MULTIPLY:
        key = Keys.MULTIPLY;
        break;
    case java.awt.event.KeyEvent.VK_NUMPAD0:
        key = Keys.NUMPAD0;
        break;
    case java.awt.event.KeyEvent.VK_NUMPAD1:
        key = Keys.NUMPAD1;
        break;
    case java.awt.event.KeyEvent.VK_NUMPAD2:
        key = Keys.NUMPAD2;
        break;
    case java.awt.event.KeyEvent.VK_NUMPAD3:
        key = Keys.NUMPAD3;
        break;
    case java.awt.event.KeyEvent.VK_NUMPAD4:
        key = Keys.NUMPAD4;
        break;
    case java.awt.event.KeyEvent.VK_NUMPAD5:
        key = Keys.NUMPAD5;
        break;
    case java.awt.event.KeyEvent.VK_NUMPAD6:
        key = Keys.NUMPAD6;
        break;
    case java.awt.event.KeyEvent.VK_NUMPAD7:
        key = Keys.NUMPAD7;
        break;
    case java.awt.event.KeyEvent.VK_NUMPAD8:
        key = Keys.NUMPAD8;
        break;
    case java.awt.event.KeyEvent.VK_NUMPAD9:
        key = Keys.NUMPAD9;
        break;
    case java.awt.event.KeyEvent.VK_PAGE_DOWN:
        key = Keys.PAGE_DOWN;
        break;
    case java.awt.event.KeyEvent.VK_PAGE_UP:
        key = Keys.PAGE_UP;
        break;
    case java.awt.event.KeyEvent.VK_PAUSE:
        key = Keys.PAUSE;
        break;
    case java.awt.event.KeyEvent.VK_RIGHT:
        key = Keys.RIGHT;
        break;
    case java.awt.event.KeyEvent.VK_SEMICOLON:
        key = Keys.SEMICOLON;
        break;
    case java.awt.event.KeyEvent.VK_SEPARATOR:
        key = Keys.SEPARATOR;
        break;
    case java.awt.event.KeyEvent.VK_SHIFT:
        key = Keys.SHIFT;
        break;
    case java.awt.event.KeyEvent.VK_SPACE:
        key = Keys.SPACE;
        break;
    case java.awt.event.KeyEvent.VK_SUBTRACT:
        key = Keys.SUBTRACT;
        break;
    case java.awt.event.KeyEvent.VK_TAB:
        key = Keys.TAB;
        break;
    case java.awt.event.KeyEvent.VK_UP:
        key = Keys.UP;
        break;
    }
    return key;
}

From source file:org.testeditor.fixture.web.EclipseRapFixture.java

License:Open Source License

/**
 * Selects the given value from drop down.
 * /*from   w  ww .j av  a 2 s.  c  o m*/
 * @param value
 *            the value to select
 * @param elementListKey
 *            the input field of the combo box
 * @param replaceArgs
 *            values to replace the place holders in the element list entry
 * @return true if value was selectable
 */
public boolean selectInDropDown(String value, String elementListKey, String... replaceArgs) {
    boolean result = false;

    /*
     * Because RAP doesn't render drop downs as select-tags with options, we
     * can't use the standard web driver Select-class. RAP creates combo
     * boxes as input field with attached divs. Input field and divs don't
     * share a common XPATH.
     */

    WebElement element = findWebelement(elementListKey, replaceArgs);

    element.click();
    element.sendKeys(Keys.PAGE_UP);

    String currentValue = element.getAttribute("value");
    String before = null;

    do {
        if (value.equals(currentValue)) {
            element.click();
            result = true;
        } else {
            before = currentValue;
            element.sendKeys(Keys.DOWN);
            currentValue = element.getAttribute("value");
        }
    } while (!currentValue.equals(before) && !result);

    return result;
}

From source file:org.testeditor.fixture.web.RapWebFixture.java

License:Open Source License

/**
 * Selects an option from an available drop down element by the visible
 * text.//from w w  w  .  j  ava2 s .  co m
 * 
 * <p/>
 * <b>Hint:</b> Doesn't work for drop down lists with duplicate entries.
 * 
 * @param value
 *            the value to select
 * @param elementListKey
 *            key in the element list to find the technical locator
 * @param replaceArgs
 *            values to replace the place holders in the element list entry
 * @return {@code true} if the {@code value} was selectable, {@code false}
 *         otherwise
 * @throws StopTestException
 *             if element not available (hidden, not present) or a timeout
 *             occurred
 */
public boolean selectOption(String value, String elementListKey, String... replaceArgs)
        throws StopTestException {
    /*
     * Because RAP doesn't render drop downs as select-tags with options, we
     * can't use the standard web driver Select-class. RAP creates combo
     * boxes as input field with attached divs. Input field and divs don't
     * share a common XPATH.
     */

    boolean result = false;
    WebElement element = findAvailableWebElement(elementListKey, replaceArgs);

    element.click();
    // start on top of the list
    element.sendKeys(Keys.DOWN);
    element.sendKeys(Keys.PAGE_UP);

    String currentValue = element.getAttribute("value");
    String before = null;

    do {
        if (value.equals(currentValue)) {
            element.click();
            result = true;
        } else {
            before = currentValue;
            // go on to the next element in the list
            element.sendKeys(Keys.DOWN);
            currentValue = element.getAttribute("value");
        }
        // stop execution, if last and current analyzed value are the same
    } while (!currentValue.equals(before) && !result);

    return result;
}