Example usage for org.openqa.selenium Keys END

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

Introduction

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

Prototype

Keys END

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

Click Source Link

Usage

From source file:org.eclipse.che.selenium.refactor.move.CodeAssistAfterMoveItemTest.java

License:Open Source License

@Test
public void checkCodeAssistAfterMoveItem() {
    projectExplorer.openItemByPath(pathToPackageInChePrefix + "/org/eclipse/qa/examples/AppController.java");
    loader.waitOnClosed();//from  ww  w. j  a  v a 2 s  .  c  om
    editor.waitActiveEditor();
    editor.setCursorToLine(31);
    editor.typeTextIntoEditor(Keys.TAB.toString());
    loader.waitOnClosed();
    editor.typeTextIntoEditor("A5 a = new A5();");
    loader.waitOnClosed();
    editor.waitTextIntoEditor("A5 a = new A5();");
    editor.waitMarkerInPosition(ERROR_MARKER, 31);
    editor.typeTextIntoEditor(Keys.END.toString());
    editor.launchPropositionAssistPanel();
    loader.waitOnClosed();
    editor.waitTextIntoFixErrorProposition("Import 'A5' (r)");
    editor.enterTextIntoFixErrorPropByDoubleClick("Import 'A5' (r)");
    loader.waitOnClosed();
    editor.waitTextIntoEditor("import r.A5;");
    editor.waitMarkerDisappears(ERROR_MARKER, 33);

    // move item 'A5' into package 'p1'
    projectExplorer.selectItem(pathToPackageInChePrefix + "/r/A5.java");
    projectExplorer.launchRefactorMoveByKeyboard();
    refactor.waitMoveItemFormIsOpen();
    refactor.clickOnExpandIconTree(PROJECT_NAME);
    refactor.clickOnExpandIconTree("/src/main/java");
    refactor.chooseDestinationForItem("p1");
    refactor.clickOkButtonRefactorForm();
    refactor.waitMoveItemFormIsClosed();
    loader.waitOnClosed();
    projectExplorer.waitItem(pathToPackageInChePrefix + "/p1/A5.java");
    projectExplorer.waitDisappearItemByPath(pathToPackageInChePrefix + "/r/A5.java");
    editor.waitTextIntoEditor("import p1.A5;");
    editor.setCursorToLine(16);
    editor.deleteCurrentLine();
    loader.waitOnClosed();
    editor.waitMarkerInPosition(ERROR_MARKER, 32);
    editor.setCursorToDefinedLineAndChar(32, 5);
    editor.launchPropositionAssistPanel();
    loader.waitOnClosed();
    editor.waitTextIntoFixErrorProposition("Import 'A5' (p1)");
    editor.enterTextIntoFixErrorPropByEnter("Import 'A5' (p1)");
    editor.waitTextIntoEditor("import p1.A5;");
}

From source file:org.eclipse.che.selenium.refactor.parameters.RenameParametersTest.java

License:Open Source License

@Test(priority = 9)
public void checkRenameParameters28() throws Exception {
    setFieldsForTest("test28");
    projectExplorer.openItemByPath(pathToCurrentPackage + "/A.java");
    editor.waitActiveEditor();/*from  www .ja  v  a 2 s.  c o m*/
    editor.waitTextIntoEditor(contentFromInA);
    editor.setCursorToDefinedLineAndChar(14, 18);
    editor.typeTextIntoEditor(Keys.END.toString());
    editor.typeTextIntoEditor(Keys.ARROW_LEFT.toString());
    editor.typeTextIntoEditor(Keys.ARROW_LEFT.toString());
    editor.launchRefactorFormFromEditor();
    editor.typeTextIntoEditor("j");
    editor.typeTextIntoEditor(Keys.ENTER.toString());
    editor.waitTextIntoEditor(contentFromOutA);
    editor.closeFileByNameWithSaving("A");
}

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://from  w w w . j ava2 s  .c om
        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.musetest.selenium.values.KeystrokesStringSourceTests.java

License:Open Source License

@Test
void testSingleMixedAtStart() throws MuseInstantiationException, ValueSourceResolutionError {
    ValueSourceConfiguration source = ValueSourceConfiguration.forTypeWithSource(KeystrokesStringSource.TYPE_ID,
            ValueSourceConfiguration.forValue("{END}Z"));
    Object result = source.createSource(new SimpleProject()).resolveValue(new MockStepExecutionContext());
    Assertions.assertEquals(Keys.END + "Z", result.toString());
}

From source file:org.natica.expense.ExpenseImport.java

public void importExpenes(List<Expense> expenses, String username, String password) {
    setUpDriverConfig(ExpenseConstants.WAITSECONDS);
    openBrowser();//from   w  ww  .  j  ava2s.  c om
    login(username, password);
    goToExpensePage();
    for (Expense e : expenses) {
        WebElement calendarButton = driver.findElement(By.xpath(ExpenseConstants.CALENDARPOPUPXPATH));
        calendarButton.click();

        String activeMonthYear = driver.findElement(By.xpath(ExpenseConstants.CALENDARACTIVEMONTHXPATH))
                .getText();
        DateFormat format = new SimpleDateFormat("MMMM yyyy");
        Date activeDate = null;
        try {
            activeDate = format.parse(activeMonthYear);
        } catch (ParseException ex) {
            Logger.getLogger(ExpenseImport.class.getName()).log(Level.SEVERE, null, ex);
        }
        Calendar activeDateCal = Calendar.getInstance();
        activeDateCal.setTime(activeDate);

        Calendar expenseEntryDateCal = Calendar.getInstance();
        expenseEntryDateCal.setTime(e.getExpenseEntryDate());
        goToExpenseMonth(activeDateCal, expenseEntryDateCal);

        WebElement expenseDay = findDay(expenseEntryDateCal.get(Calendar.DAY_OF_MONTH),
                expenseEntryDateCal.getActualMaximum(Calendar.DATE));
        expenseDay.click();

        WebElement showButton = driver.findElement(By.xpath(ExpenseConstants.SHOWBUTTONXPATH));
        showButton.click();

        WebElement projectName = driver.findElement(By.xpath(ExpenseConstants.PROJECTNAMEXPATH));
        Select projectNameSelect = new Select(projectName);
        projectNameSelect.selectByVisibleText(e.getProjectName());

        WebElement expenseName = driver.findElement(By.xpath(ExpenseConstants.EXPENSENAMEXPATH));
        Select expenseNameSelect = new Select(expenseName);
        expenseNameSelect.selectByVisibleText(e.getExpenseName());
        expenseName.sendKeys(Keys.TAB);
        waitSeconds(3);

        WebElement description = driver.findElement(By.xpath(ExpenseConstants.EXPENSEDESCRIPTIONXPATH));
        description.sendKeys(Keys.chord(Keys.CONTROL, "a"), e.getDescription());
        description.sendKeys(Keys.TAB);

        WebElement paymentMethod = driver.findElement(By.xpath(ExpenseConstants.PAYMENTMETHODXPATH));
        Select paymentMethodSelect = new Select(paymentMethod);
        paymentMethodSelect.selectByVisibleText(e.getPaymentMethod());

        WebElement netAmount = driver.findElement(By.xpath(ExpenseConstants.NETAMOUNTXPATH));
        netAmount.sendKeys(Keys.HOME, Keys.chord(Keys.SHIFT, Keys.END),
                e.getNetAmount().toString().replace(".", ","));
        netAmount.sendKeys(Keys.TAB);
        waitSeconds(3);

        WebElement addButton = driver.findElement(By.xpath(ExpenseConstants.ADDBUTTONXPATH));
        addButton.click();
        acceptNextAlert = true;
        closeAlertAndGetItsText();

        WebElement submitButton = driver.findElement(By.xpath(ExpenseConstants.SUBMITBUTTONXPATH));
        submitButton.click();

    }
}

From source file:org.nvonop.selenium.framework.controls.TextBox.java

License:Open Source License

@Override
public void write(String value) {
    getUnderlyingWebElement().sendKeys(Keys.HOME);
    getUnderlyingWebElement().sendKeys(Keys.SHIFT, Keys.END, Keys.DELETE);
    getUnderlyingWebElement().sendKeys(value);
}

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// w  w w  .  jav  a  2 s. co  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.tomitribe.tribestream.registryng.webapp.EditApplicationPage.java

License:Apache License

public void enterName(final WebDriver driver, final String newTitle) {
    titleField.click();/*  w w  w  .  j  a v  a 2 s  .  c o m*/
    new WebDriverWait(driver, 5000).until((Function<WebDriver, Boolean>) (dontcare -> titleField
            .findElement(By.cssSelector("input[type='text']")).isDisplayed()));
    WebElement textField = titleField.findElement(By.cssSelector("input[type='text']"));
    textField.sendKeys(Keys.END);
    System.out.println("TEXT: " + textField.getText());
    while (textField.getText().length() > 0) {
        textField.sendKeys(Keys.BACK_SPACE);
        System.out.println("TEXT: " + textField.getText());
    }
    textField.sendKeys(newTitle, "\n");
}

From source file:org.xmlium.test.web.commons.xml.XMLTestSteps.java

License:LGPL

protected void processStep(StepType step) throws Exception {
    WebElement element = null;//www . j  a v a 2s .  co m
    Alert a = null;
    if (step.getScrollX() != null && step.getScrollY() != null) {
        JavascriptExecutor js = (JavascriptExecutor) getSuite().getDriver();
        js.executeScript("window.scrollTo(" + step.getScrollX() + ", " + step.getScrollY() + ");");
    }
    if (step.isBack() != null && step.isBack()) {
        getSuite().getDriver().navigate().back();
    }
    if (step.isForward() != null && step.isForward()) {
        getSuite().getDriver().navigate().forward();
    }
    Element e = null;
    if (step.getLoad() != null && step.getLoad().getKey() != null) {
        e = store.get(step.getLoad().getKey());
        element = findElement(e.getFinds());
    }
    if (step.getElement() != null) {
        if (step.getElement().getFinds() != null) {
            e = step.getElement();
            checkStore(e);

            element = checkWaitFor(e);
            if (element == null && step.getElement().isCheckNullElement()) {
                return;
            }
            checkStoreValue(e, element);
            checkSetValue(e, element);
            checkSendKeys(e, element);
            checkClick(e, element);
            checkChangeState(e);
            checkText(e, element);
            checkMoveX(e, element);
        }
    }
    if (step.getSwitchTo() != null) {
        Object to = switchTo(step.getSwitchTo());
        if (to instanceof Alert) {
            a = (Alert) to;
            if (step.getSwitchTo().getAlert() != null && step.getSwitchTo().getAlert().isAccept()) {
                a.accept();
            }
        } else {
            a = null;
        }
    }
    if (step.getSelect() != null) {
        org.xmlium.testsuite.Select stepSelect = step.getSelect();

        if (element != null && stepSelect.getSelectBy().getByIndex() != null) {
            Index index = stepSelect.getSelectBy().getByIndex();
            SelectData selectData = new SelectData();
            initSelectIndexes(element, index, selectData);
            if (selectData.selectIndex >= 0) {
                Select select = new Select(element);
                List<WebElement> options = select.getOptions();
                WebElement option = options.get(selectData.selectIndex);
                option.click();
            } else {
                throw new RuntimeException("selectedIndex=" + selectData.selectIndex);
            }
        } else {
            if (element == null) {
                element = findElement(step.getSelect().getFinds());
            }
            if (element != null) {
                Select select = new Select(element);
                if (step.getSelect().getSelectBy() != null) {
                    selectBy(select, step.getSelect().getSelectBy());
                }
            }
        }
    }
    if (step.getPrettySelect() != null) {
        PrettySelect stepSelect = step.getPrettySelect();
        if (element == null) {
            if (stepSelect.getFinds() != null) {
                element = findElement(stepSelect.getFinds());
            }
        }
        if (element != null && stepSelect.getSelectBy() != null) {
            SelectData selectData = new SelectData();
            Select select = null;
            select = new Select(element);
            Index index = null;
            if (stepSelect.getSelectBy().getByIndex() != null) {
                index = stepSelect.getSelectBy().getByIndex();
                initSelectIndexes(element, index, selectData);
            } else if (stepSelect.getSelectBy().getByVisibleText() != null) {
                List<WebElement> elems = select.getOptions();
                getOptionIndexBuVisibleText(stepSelect.getSelectBy().getByVisibleText(), elems, selectData);
            }

            if (selectData.selectIndex >= 0) {
                WebElement arrowArea = null;
                WebElement scrollArea = null;
                if (stepSelect.getSelectBy().getArrowArea() != null) {
                    arrowArea = findElement(stepSelect.getSelectBy().getArrowArea());
                } else {
                    throw new RuntimeException("arrowArea not defined in xml");
                }

                if (arrowArea != null) {
                    arrowArea.click();

                    if (stepSelect.getSelectBy().getScrollArea() != null) {
                        Finds scrollAreaFinds = stepSelect.getSelectBy().getScrollArea();
                        if (scrollAreaFinds.getFind() != null) {
                            scrollArea = findElement(scrollAreaFinds.getFind());
                        } else if (scrollAreaFinds.getWaitFor() != null) {
                            scrollArea = waitFor(scrollAreaFinds.getWaitFor());
                        }
                        if (scrollArea == null) {
                            if (scrollAreaFinds.getFind() != null || scrollAreaFinds.getWaitFor() != null) {
                                String text = "";
                                if (scrollAreaFinds.getFind() != null
                                        && scrollAreaFinds.getFind().getByXPath() != null) {
                                    text = unformatValue(scrollAreaFinds.getFind().isUnformat(),
                                            scrollAreaFinds.getFind().getByXPath().getValue());
                                } else if (scrollAreaFinds.getWaitFor() != null
                                        && scrollAreaFinds.getWaitFor().getByXPath() != null) {
                                    text = unformatValue(scrollAreaFinds.getWaitFor().isUnformat(),
                                            scrollAreaFinds.getWaitFor().getByXPath().getValue());
                                }

                                throw new RuntimeException("scrollArea not found: " + text);
                            } else {
                                throw new RuntimeException("scrollArea not defined in xml");
                            }
                        }
                    }

                    if (index.isFirst() != null || index.isLast() != null) {
                        Actions actions = new Actions(getSuite().getDriver());
                        String text = null;
                        if (index.isFirst() != null && index.isFirst()) {
                            actions.keyDown(Keys.CONTROL).sendKeys(Keys.HOME).perform();
                        } else if (index.isLast() != null && index.isLast()) {
                            actions.keyDown(Keys.CONTROL).sendKeys(Keys.END).perform();
                        }

                        if (index.isFirst() != null && index.isFirst()) {
                            text = select.getOptions().get(0).getText();
                        } else if (index.isLast() != null && index.isLast()) {
                            text = select.getOptions().get(select.getOptions().size() - 1).getText();
                        }
                        if (stepSelect.getSelectBy().getOptionsTag() != null) {
                            Find f = new Find();
                            ByXPath xPath = new ByXPath();
                            if (text != null && !text.isEmpty()) {
                                xPath.setValue("//" + stepSelect.getSelectBy().getOptionsTag()
                                        + "[contains(@class, '" + stepSelect.getSelectBy().getOptionsClasses()
                                        + "') and text()='" + text + "']");
                            } else {
                                xPath.setValue("(//" + stepSelect.getSelectBy().getOptionsTag()
                                        + "[contains(@class, '" + stepSelect.getSelectBy().getOptionsClasses()
                                        + "')])[" + Integer.toString(selectData.selectIndex + 1) + "]");
                            }
                            f.setByXPath(xPath);
                            WebElement optionElemnt = findElement(f);
                            WebDriverWait wait = new WebDriverWait(getSuite().getDriver(), 30);
                            wait.until(ExpectedConditions.elementToBeClickable(optionElemnt));
                            optionElemnt.click();
                        }
                    } else {
                        if (selectData.selectIndex < 0
                                || selectData.selectIndex >= select.getOptions().size()) {
                            throw new RuntimeException("selectIndex: " + selectData.selectIndex
                                    + ", options.size: " + select.getOptions().size());
                        }
                        WebElement option = select.getOptions().get(selectData.selectIndex);
                        String text = option.getText();
                        if (text == null || text.isEmpty()) {
                            logger.debug("text is null or empty: " + option);
                            text = null;
                        }
                        if (stepSelect.getSelectBy().getOptionsTag() != null) {
                            Find f = new Find();
                            ByXPath xPath = new ByXPath();
                            if (text != null) {
                                xPath.setValue("//" + stepSelect.getSelectBy().getOptionsTag()
                                        + "[contains(@class, '" + stepSelect.getSelectBy().getOptionsClasses()
                                        + "') and text()='" + text + "']");
                            } else {
                                xPath.setValue("(//" + stepSelect.getSelectBy().getOptionsTag()
                                        + "[contains(@class, '" + stepSelect.getSelectBy().getOptionsClasses()
                                        + "')])[" + Integer.toString(selectData.selectIndex + 1) + "]");
                            }
                            f.setByXPath(xPath);
                            WebElement optionElemnt = findElement(f);

                            Coordinates coordinate = ((Locatable) optionElemnt).getCoordinates();
                            coordinate.onPage();
                            coordinate.inViewPort();
                            WebDriverWait wait = new WebDriverWait(getSuite().getDriver(), 30);
                            wait.until(ExpectedConditions.elementToBeClickable(optionElemnt));
                            optionElemnt.click();
                        }
                    }
                } else {
                    throw new RuntimeException("can't click the arrow");
                }
            } else if (stepSelect.getSelectBy().getByVisibleText() != null) {
                WebElement arrowArea = null;
                WebElement scrollArea = null;
                if (stepSelect.getSelectBy().getArrowArea() != null) {
                    arrowArea = findElement(stepSelect.getSelectBy().getArrowArea());
                } else {
                    throw new RuntimeException("arrowArea not defined in xml");
                }

                if (arrowArea != null) {
                    arrowArea.click();
                    String scrollAreaXPath = null;
                    if (stepSelect.getSelectBy().getScrollArea() != null) {
                        Finds scrollAreaFinds = stepSelect.getSelectBy().getScrollArea();
                        if (scrollAreaFinds.getFind() != null) {
                            scrollArea = findElement(scrollAreaFinds.getFind());
                        } else if (scrollAreaFinds.getWaitFor() != null) {
                            scrollArea = waitFor(scrollAreaFinds.getWaitFor());
                        }

                        if (scrollAreaXPath == null) {
                            if (scrollAreaFinds.getFind() != null || scrollAreaFinds.getWaitFor() != null) {
                                if (scrollAreaFinds.getFind() != null
                                        && scrollAreaFinds.getFind().getByXPath() != null) {
                                    scrollAreaXPath = unformatValue(scrollAreaFinds.getFind().isUnformat(),
                                            scrollAreaFinds.getFind().getByXPath().getValue());
                                } else if (scrollAreaFinds.getWaitFor() != null
                                        && scrollAreaFinds.getWaitFor().getByXPath() != null) {
                                    scrollAreaXPath = unformatValue(scrollAreaFinds.getWaitFor().isUnformat(),
                                            scrollAreaFinds.getWaitFor().getByXPath().getValue());
                                }
                                // throw new RuntimeException("scrollArea
                                // not found: " + text);
                            } else {
                                throw new RuntimeException("scrollArea not defined in xml");
                            }
                        }
                    }

                    Actions actions = new Actions(getSuite().getDriver());
                    String text = null;
                    // actions.keyDown(Keys.CONTROL).sendKeys(Keys.HOME).perform();
                    WebDriverWait wait = new WebDriverWait(getSuite().getDriver(), 30);
                    wait.until(ExpectedConditions.elementToBeClickable(scrollArea));
                    actions.moveToElement(scrollArea).build().perform();

                    text = stepSelect.getSelectBy().getByVisibleText();
                    logger.debug("text: " + text);
                    if (stepSelect.getSelectBy().getOptionsTag() != null) {
                        Find f = new Find();
                        ByXPath xPath = new ByXPath();
                        if (text != null) {

                            xPath.setValue(scrollAreaXPath + "/descendant::"
                                    + stepSelect.getSelectBy().getOptionsTag() + "[contains(@class, '"
                                    + stepSelect.getSelectBy().getOptionsClasses() + "') and text()='" + text
                                    + "']");
                        } else {
                            xPath.setValue("(//" + stepSelect.getSelectBy().getOptionsTag()
                                    + "[contains(@class, '" + stepSelect.getSelectBy().getOptionsClasses()
                                    + "')])[" + Integer.toString(selectData.selectIndex + 1) + "]");
                        }
                        f.setByXPath(xPath);
                        logger.debug("xPath: " + xPath);
                        WebElement optionElemnt = findElement(f);

                        Coordinates coordinate = ((Locatable) optionElemnt).getCoordinates();
                        coordinate.onPage();
                        coordinate.inViewPort();
                        wait = new WebDriverWait(getSuite().getDriver(), 30);
                        wait.until(ExpectedConditions.visibilityOf(optionElemnt));
                        actions.moveToElement(optionElemnt).click().build().perform();
                    }
                }
            } else {
                throw new RuntimeException("selectedIndex=" + selectData.selectIndex);
            }
        } else {
            if (element == null) {
                element = findElement(step.getPrettySelect().getFinds());
            }
            if (element != null) {
                Select select = new Select(element);
                if (step.getPrettySelect().getSelectBy() != null) {
                    selectBy(select, step.getPrettySelect().getSelectBy());
                }
            }
        }
    }

    if (step.getSleepAfter() != null) {
        long sleep = step.getSleepAfter().longValue();
        try {
            Thread.sleep(sleep);
        } catch (Exception e2) {
            // TODO: handle exception
        }
    }
}

From source file:org.xwiki.test.selenium.WikiEditorTest.java

License:Open Source License

/**
 * Tests that the specified tool bar button works.
 * /*from  w  w  w  .  ja  v  a  2 s.  c o  m*/
 * @param buttonTitle the title of a tool bar button
 * @param format the format of the text inserted by the specified button
 * @param defaultText the default text inserted if there's no text selected in the text area
 */
private void testToolBarButton(String buttonTitle, String format, String defaultText) {
    editInWikiEditor(this.getClass().getSimpleName(), getTestMethodName(), SYNTAX);
    WebElement textArea = getDriver().findElement(By.id("content"));
    textArea.clear();
    textArea.sendKeys("a");
    String buttonLocator = "//img[@title = '" + buttonTitle + "']";
    getSelenium().click(buttonLocator);
    // Type b and c on two different lines and move the caret after b.
    textArea.sendKeys("b", Keys.RETURN, "c", Keys.ARROW_LEFT, Keys.ARROW_LEFT);
    getSelenium().click(buttonLocator);
    // Move the caret after c, type d and e, then select d.
    textArea.sendKeys(Keys.PAGE_DOWN, Keys.END, "de", Keys.ARROW_LEFT, Keys.chord(Keys.SHIFT, Keys.ARROW_LEFT));
    getSelenium().click(buttonLocator);
    if (defaultText.isEmpty()) {
        assertEquals("a" + format + "b" + format + "\nc" + format + "de", textArea.getAttribute("value"));
    } else {
        assertEquals(String.format("a" + format + "b" + format + "\nc" + format + "e", defaultText, defaultText,
                "d"), textArea.getAttribute("value"));
    }
}