Java 类org.openqa.selenium.Keys 实例源码

项目:kheera    文件:AbstractPage.java   
@Override
public boolean putText(WebElement w, String... args) throws Exception{
    boolean result = false;
    String d = args[0];
    boolean includesReturn = false;
    if(d.indexOf("\\n") > -1 || d.indexOf("\\r") > -1){
        d = d.replace("\\n", "");
        d = d.replace("\\r", "");
        includesReturn = true;
    }
    try{
        w.clear();
        w.sendKeys(d);
        if(includesReturn){
            w.sendKeys(Keys.RETURN);
        }
        result = true;
    }catch(Exception e){
        e.printStackTrace();
        result = false;
    }
    Assert.assertTrue(result, w.toString() + " insert text " + d);
    return result;
}
项目:marathonv5    文件:JScrollBarTest.java   
@Test(enabled = false) public void sendKeys() throws Throwable {
    driver = new JavaDriver();
    List<WebElement> scrollBars = driver.findElements(By.cssSelector("scroll-bar"));
    WebElement scrollbar = scrollBars.get(0);
    AssertJUnit.assertEquals("0", scrollbar.getAttribute("value"));
    scrollbar.sendKeys(Keys.ARROW_DOWN);
    AssertJUnit.assertEquals("28", scrollbar.getAttribute("value"));
    scrollbar.sendKeys(Keys.ARROW_UP);
    AssertJUnit.assertEquals("0", scrollbar.getAttribute("value"));

    scrollbar = scrollBars.get(1);
    AssertJUnit.assertEquals("0", scrollbar.getAttribute("value"));
    scrollbar.sendKeys(Keys.ARROW_RIGHT);
    AssertJUnit.assertEquals("28", scrollbar.getAttribute("value"));
    scrollbar.sendKeys(Keys.ARROW_LEFT);
    AssertJUnit.assertEquals("0", scrollbar.getAttribute("value"));
}
项目:marathonv5    文件:JTextAreaTest.java   
public void sendKeys() throws Throwable {
    driver = new JavaDriver();
    WebElement textArea = driver.findElement(By.cssSelector("text-area"));
    AssertJUnit.assertEquals("true", textArea.getAttribute("editable"));
    textArea.clear();
    AssertJUnit.assertEquals("", textArea.getText());
    textArea.sendKeys("Lewis CarrollR");
    textArea.sendKeys(Keys.BACK_SPACE);
    AssertJUnit.assertEquals("Lewis Carroll", textArea.getText());
    textArea.sendKeys(Keys.HOME + "Jhon ");
    AssertJUnit.assertEquals("Jhon Lewis Carroll", textArea.getText());
    for (int i = 0; i < 5; i++) {
        textArea.sendKeys(OSUtils.getKeysFor(textArea, "select-all"), OSUtils.getKeysFor(textArea, "copy-to-clipboard"),
                OSUtils.getKeysFor(textArea, "paste-from-clipboard"), Keys.END,
                OSUtils.getKeysFor(textArea, "paste-from-clipboard"));
    }
    textArea.sendKeys(OSUtils.getKeysFor(textArea, "select-all"));
    textArea.sendKeys(Keys.DELETE);
    AssertJUnit.assertEquals("", textArea.getText());
}
项目:marathonv5    文件:NativeEventsTest.java   
private void checkAltClickEvent(int eventToCheck) throws InterruptedException, InvocationTargetException, AWTException {
    events = eventToCheck;
    tclear();
    Point locationButton = EventQueueWait.call_noexc(button, "getLocationOnScreen");
    Dimension sizeButton = EventQueueWait.call_noexc(button, "getSize");
    Point locationTextArea = EventQueueWait.call_noexc(actionsArea, "getLocationOnScreen");
    Dimension sizeTextArea = EventQueueWait.call_noexc(actionsArea, "getSize");

    Robot robot = new Robot();
    robot.setAutoDelay(10);
    robot.setAutoWaitForIdle(true);
    robot.mouseMove(locationTextArea.x + sizeTextArea.width / 2, locationTextArea.y + sizeTextArea.height / 2);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    robot.mouseMove(locationButton.x + sizeButton.width / 2 + 1, locationButton.y + sizeButton.height / 2 + 1);
    robot.mouseMove(locationButton.x + sizeButton.width / 2, locationButton.y + sizeButton.height / 2);
    robot.keyPress(KeyEvent.VK_ALT);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    robot.keyRelease(KeyEvent.VK_ALT);
    robot.mouseMove(locationTextArea.x + sizeTextArea.width / 2, locationTextArea.y + sizeTextArea.height / 2);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    new EventQueueWait() {
        @Override public boolean till() {
            return actionsArea.getText().length() > 0;
        }
    }.wait("Waiting for actionsArea failed?");
    String expected = weTextArea.getText();
    tclear();
    System.err.println("================================");
    System.err.println(expected);
    System.err.println("=================================");
    new Actions(driver).moveToElement(weButton).keyDown(Keys.ALT).click().keyUp(Keys.ALT).moveToElement(weTextArea).perform();
    AssertJUnit.assertEquals(expected, weTextArea.getText());
}
项目:marathonv5    文件:NativeEventsTest.java   
private void checkAltRightClickEvent(int eventToCheck) throws InterruptedException, InvocationTargetException, AWTException {
    events = eventToCheck;
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            actionsArea.setText("");
        }
    });
    driver = new JavaDriver();
    WebElement b = driver.findElement(By.name("click-me"));
    WebElement t = driver.findElement(By.name("actions"));

    Point location = EventQueueWait.call_noexc(button, "getLocationOnScreen");
    Dimension size = EventQueueWait.call_noexc(button, "getSize");
    Robot r = new Robot();
    r.setAutoDelay(10);
    r.setAutoWaitForIdle(true);
    r.keyPress(KeyEvent.VK_ALT);
    r.mouseMove(location.x + size.width / 2, location.y + size.height / 2);
    r.mousePress(InputEvent.BUTTON3_MASK);
    r.mouseRelease(InputEvent.BUTTON3_MASK);
    r.keyRelease(KeyEvent.VK_ALT);
    new EventQueueWait() {
        @Override public boolean till() {
            return actionsArea.getText().length() > 0;
        }
    }.wait("Waiting for actionsArea failed?");
    String expected = t.getText();
    tclear();
    Point location2 = EventQueueWait.call_noexc(actionsArea, "getLocationOnScreen");
    Dimension size2 = EventQueueWait.call_noexc(button, "getSize");
    r.mouseMove(location2.x + size2.width / 2, location2.y + size2.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);

    new Actions(driver).moveToElement(b).keyDown(Keys.ALT).contextClick().keyUp(Keys.ALT).perform();
    AssertJUnit.assertEquals(expected, t.getText());
    // Wait till the previous click is processed by the EDT
    Thread.sleep(500);
}
项目:marathonv5    文件:NativeEventsTest.java   
public void enteredGeneratesSameEvents() throws Throwable {
    events = MouseEvent.MOUSE_ENTERED;
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            actionsArea.setText("");
        }
    });
    driver = new JavaDriver();
    WebElement b = driver.findElement(By.name("click-me"));
    WebElement t = driver.findElement(By.name("actions"));

    Point location = EventQueueWait.call_noexc(button, "getLocationOnScreen");
    Dimension size = EventQueueWait.call_noexc(button, "getSize");
    Robot r = new Robot();
    r.setAutoDelay(10);
    r.setAutoWaitForIdle(true);
    r.keyPress(KeyEvent.VK_ALT);
    r.mouseMove(location.x + size.width / 2, location.y + size.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);
    r.keyRelease(KeyEvent.VK_ALT);
    new EventQueueWait() {
        @Override public boolean till() {
            return actionsArea.getText().length() > 0;
        }
    }.wait("Waiting for actionsArea failed?");
    String expected = t.getText();
    tclear();
    Point location2 = EventQueueWait.call_noexc(actionsArea, "getLocationOnScreen");
    Dimension size2 = EventQueueWait.call_noexc(actionsArea, "getSize");
    r.mouseMove(location2.x + size2.width / 2, location2.y + size2.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);

    new Actions(driver).moveToElement(t).keyDown(Keys.ALT).moveToElement(b).click().keyUp(Keys.ALT).perform();
    AssertJUnit.assertEquals(expected, t.getText());

}
项目:marathonv5    文件:JCheckBoxTest.java   
public void sendKeys() throws Throwable {
    driver = new JavaDriver();
    List<WebElement> checkBoxes = driver.findElements(By.cssSelector("check-box"));
    AssertJUnit.assertEquals(4, checkBoxes.size());
    WebElement chkbox1 = checkBoxes.get(0);
    AssertJUnit.assertEquals("Chin", chkbox1.getAttribute("buttonText"));
    WebElement chkbox2 = checkBoxes.get(1);
    AssertJUnit.assertEquals("Glasses", chkbox2.getAttribute("buttonText"));
    WebElement chkbox3 = checkBoxes.get(2);
    AssertJUnit.assertEquals("Hair", chkbox3.getAttribute("buttonText"));
    WebElement chkbox4 = checkBoxes.get(3);
    AssertJUnit.assertEquals("Teeth", chkbox4.getAttribute("buttonText"));

    AssertJUnit.assertEquals("true", chkbox1.getAttribute("selected"));
    AssertJUnit.assertEquals("true", chkbox2.getAttribute("selected"));
    AssertJUnit.assertEquals("true", chkbox3.getAttribute("selected"));
    AssertJUnit.assertEquals("true", chkbox4.getAttribute("selected"));
    chkbox3.sendKeys(Keys.SPACE);
    AssertJUnit.assertEquals("true", chkbox1.getAttribute("selected"));
    AssertJUnit.assertEquals("true", chkbox2.getAttribute("selected"));
    AssertJUnit.assertEquals("false", chkbox3.getAttribute("selected"));
    AssertJUnit.assertEquals("true", chkbox4.getAttribute("selected"));
}
项目:marathonv5    文件:JTreeDynamicTreeTest.java   
public void editANodeWithEditor() throws Throwable {
    System.err.println("Ignore the following NPE. The DynamicTree class has a bug");
    WebElement tree = page.getTree();
    tree.click();
    final WebElement root = tree.findElement(By.cssSelector(".::root"));
    AssertJUnit.assertEquals("Root Node", root.getText());
    WebElement editor = root.findElement(By.cssSelector(".::editor"));
    editor.clear();
    editor.sendKeys("Hello World", Keys.ENTER);
    root.submit();
    new WebDriverWait(driver, 3).until(new Function<WebDriver, Boolean>() {
        @Override public Boolean apply(WebDriver input) {
            return root.getText().equals("Hello World");
        }
    });
    AssertJUnit.assertEquals("Hello World", root.getText());
}
项目:marathonv5    文件:JPasswordFieldTest.java   
public void login() throws Throwable {
    driver = new JavaDriver();
    WebElement passField = driver.findElement(By.cssSelector("password-field"));
    AssertJUnit.assertEquals("true", passField.getAttribute("enabled"));
    passField.clear();
    AssertJUnit.assertEquals("", passField.getText());
    passField.sendKeys("password");
    WebElement button = driver.findElement(By.cssSelector("button"));
    button.click();
    driver.switchTo().window("Error Message");
    WebElement label = driver.findElement(By.cssSelector("label[text*='Invalid']"));
    AssertJUnit.assertEquals("Invalid password. Try again.", label.getText());
    WebElement button1 = driver.findElement(By.cssSelector("button"));
    button1.click();
    driver.switchTo().window("JPasswordFieldTest");
    passField.clear();
    passField.sendKeys("bugaboo", Keys.ENTER);
    driver.switchTo().window("Message");
    WebElement label2 = driver.findElement(By.cssSelector("label[text*='Success']"));
    AssertJUnit.assertEquals("Success! You typed the right password.", label2.getText());
}
项目:marathonv5    文件:JListRunnerTest.java   
public void listMultipleSelectWithControl() throws Throwable {
    driver = new JavaDriver();

    WebElement pickNameButton = driver.findElement(By.cssSelector("button"));
    AssertJUnit.assertEquals("Pick a new name...", pickNameButton.getText());
    pickNameButton.click();

    WebDriver nameChooserWindow = driver.switchTo().window("Name Chooser");
    AssertJUnit.assertEquals("Name Chooser", nameChooserWindow.getTitle());

    List<WebElement> list = driver.findElements(By.cssSelector("list"));
    AssertJUnit.assertEquals(1, list.size());

    List<WebElement> listItems;
    listItems = driver.findElements(By.cssSelector("list::all-items"));
    AssertJUnit.assertEquals(12, listItems.size());

    WebElement listItem;
    listItem = driver.findElement(By.cssSelector("list::nth-item(1)"));
    WebElement listItem2 = driver.findElement(By.cssSelector("list::nth-item(3)"));
    new Actions(driver).click(listItem).sendKeys(Keys.COMMAND).click(listItem2).sendKeys(Keys.COMMAND).perform();
    AssertJUnit.assertEquals("[2]", list.get(0).getAttribute("selectedIndices"));
    List<WebElement> buttons = driver.findElements(By.cssSelector("button"));
    buttons.get(1).click();
    Thread.sleep(1000);
}
项目:marathonv5    文件:DragAndDropTest.java   
public void dndWithCopy() throws Throwable {
    DesiredCapabilities caps = new DesiredCapabilities();
    // caps.setCapability("nativeEvents", true);
    driver = new JavaDriver(caps, caps);
    WebElement list = driver.findElement(By.cssSelector("list"));
    assertEquals(
            "[[\"List Item 0\",\"List Item 1\",\"List Item 2\",\"List Item 3\",\"List Item 4\",\"List Item 5\",\"List Item 6\",\"List Item 7\",\"List Item 8\",\"List Item 9\"]]",
            list.getAttribute("content"));
    WebElement listitem1 = driver.findElement(By.cssSelector("list::nth-item(1)"));
    WebElement listitem5 = driver.findElement(By.cssSelector("list::nth-item(5)"));
    listitem1.click();
    driver.clearlogs(LogType.DRIVER);
    Keys copyKey = Keys.ALT;
    if (Platform.isWindows()) {
        copyKey = Keys.CONTROL;
    }
    new Actions(driver).keyDown(copyKey).dragAndDrop(listitem1, listitem5).keyUp(copyKey).perform();
    waitTillDropCompletes(
            "[[\"List Item 0\",\"List Item 1\",\"List Item 2\",\"List Item 3\",\"List Item 0(1)\",\"List Item 5\",\"List Item 6\",\"List Item 7\",\"List Item 8\",\"List Item 9\"]]",
            list);
    assertEquals(
            "[[\"List Item 0\",\"List Item 1\",\"List Item 2\",\"List Item 3\",\"List Item 0(1)\",\"List Item 5\",\"List Item 6\",\"List Item 7\",\"List Item 8\",\"List Item 9\"]]",
            list.getAttribute("content"));
}
项目:marathonv5    文件:JButtonTest.java   
public void sendKeys() throws Throwable {
    driver = new JavaDriver();
    List<WebElement> buttons = driver.findElements(By.cssSelector("button"));
    AssertJUnit.assertEquals(3, buttons.size());
    WebElement b1 = buttons.get(0);
    AssertJUnit.assertEquals("Disable middle button", b1.getText());
    WebElement b2 = buttons.get(1);
    AssertJUnit.assertEquals("Middle button", b2.getText());
    WebElement b3 = buttons.get(2);
    AssertJUnit.assertEquals("Enable middle button", b3.getText());
    AssertJUnit.assertEquals("true", b1.getAttribute("enabled"));
    AssertJUnit.assertEquals("true", b2.getAttribute("enabled"));
    AssertJUnit.assertEquals("false", b3.getAttribute("enabled"));
    b1.sendKeys(Keys.SPACE);
    AssertJUnit.assertEquals("false", b1.getAttribute("enabled"));
    AssertJUnit.assertEquals("false", b2.getAttribute("enabled"));
    AssertJUnit.assertEquals("true", b3.getAttribute("enabled"));
}
项目:marathonv5    文件:JButtonHtmlTest.java   
public void sendKeys() throws Throwable {
    driver = new JavaDriver();
    List<WebElement> buttons = driver.findElements(By.cssSelector("button"));
    AssertJUnit.assertEquals(3, buttons.size());
    WebElement b1 = buttons.get(0);
    AssertJUnit.assertEquals("<html><center><b><u>D</u>isable</b><br><font color=#ffffdd>middle button</font>", b1.getText());
    WebElement b2 = buttons.get(1);
    AssertJUnit.assertEquals("middle button", b2.getText());
    WebElement b3 = buttons.get(2);
    AssertJUnit.assertEquals("<html><center><b><u>E</u>nable</b><br><font color=#ffffdd>middle button</font>", b3.getText());
    AssertJUnit.assertEquals("true", b1.getAttribute("enabled"));
    AssertJUnit.assertEquals("true", b2.getAttribute("enabled"));
    AssertJUnit.assertEquals("false", b3.getAttribute("enabled"));
    b1.sendKeys(Keys.SPACE);
    AssertJUnit.assertEquals("false", b1.getAttribute("enabled"));
    AssertJUnit.assertEquals("false", b2.getAttribute("enabled"));
    AssertJUnit.assertEquals("true", b3.getAttribute("enabled"));
}
项目:marathonv5    文件:JFormattedTextFieldTest.java   
public void sendKeys() throws Throwable {
    driver = new JavaDriver();
    List<WebElement> textfields = driver.findElements(By.cssSelector("formatted-text-field"));
    WebElement tf = textfields.get(0);
    WebElement other = textfields.get(1);
    AssertJUnit.assertEquals("100,000", tf.getText());
    AssertJUnit.assertEquals("100000.0", tf.getAttribute("value"));
    tf.sendKeys(Keys.chord(Keys.SHIFT, Keys.END), "1234");
    AssertJUnit.assertEquals("1234", tf.getText());
    other.click();
    AssertJUnit.assertEquals("1234", tf.getAttribute("value"));
    AssertJUnit.assertEquals("1,234", tf.getText());

    tf = textfields.get(2);
    AssertJUnit.assertEquals("30", tf.getText());
    tf.sendKeys(Keys.chord(Keys.SHIFT, Keys.END), Keys.DELETE);
    AssertJUnit.assertEquals("", tf.getText());
    tf.sendKeys("123");
    AssertJUnit.assertEquals("123", tf.getText());
    other.click();
    AssertJUnit.assertEquals("123", tf.getAttribute("value"));

}
项目:marathonv5    文件:JTableDialogEditTest.java   
public void getCellEditor() throws Throwable {
    driver = new JavaDriver();
    WebElement cell = driver.findElement(By.cssSelector("table::mnth-cell(1,2)::editor"));
    AssertJUnit.assertEquals("button", cell.getTagName());
    cell.click();
    driver.switchTo().window("Pick a Color");
    WebElement tab = driver.findElement(By.cssSelector("tabbed-pane::all-tabs[text='RGB']"));
    tab.click();
    WebElement tabcomponent = driver.findElement(By.cssSelector("tabbed-pane::all-tabs[text='RGB']::component"));
    List<WebElement> spinners = tabcomponent.findElements(By.cssSelector("spinner"));
    List<WebElement> all = spinners.get(0).findElements(By.cssSelector("*"));
    List<String> s = new ArrayList<String>();
    for (WebElement webElement : all) {
        s.add(webElement.getTagName());
    }
    WebElement tf = spinners.get(0).findElement(By.cssSelector("formatted-text-field"));
    tf.clear();
    tf.sendKeys("234", Keys.TAB);
    driver.findElement(By.cssSelector("button[text='OK']")).click();
}
项目:marathonv5    文件:JMenuTest.java   
public void menuItemShortcuts() throws Throwable {
    // This test for testing keyboard shortcuts on menu items need to be
    // fixed after the bug fix in send keys.
    driver = new JavaDriver();
    WebElement textArea = driver.findElement(By.cssSelector("text-area"));
    textArea.click();

    textArea.sendKeys(Keys.chord(Keys.ALT, "1"));
    AssertJUnit.assertTrue(
            "Error:Expected to end with:\n" + "Event source: A text-only menu item (an instance of JMenuItem)\n" + "\nActual:\n"
                    + textArea.getText().trim(),
            textArea.getText().trim().endsWith("Event source: A text-only menu item (an instance of JMenuItem)\n".trim()));
    textArea.sendKeys(Keys.chord(Keys.ALT, "2"));
    AssertJUnit.assertTrue(
            "Error:Expected to end with:\n" + "Event source: A text-only menu item (an instance of JMenuItem)\n" + "\nActual:\n"
                    + textArea.getText().trim(),
            textArea.getText().trim().endsWith("Event source: An item in the submenu (an instance of JMenuItem)\n".trim()));
}
项目:mpay24-java    文件:TestToken.java   
@Test
public void testTokenPaymentWith3DS() throws ParseException, PaymentException {
    Token token = mpay24.token(getTestTokenRequest(null));
    assertEquals("REDIRECT", token.getReturnCode());
    assertNotNull(token.getApiKey());
    assertNotNull(token.getRedirectLocation());
    assertNotNull(token.getToken());

    RemoteWebDriver driver = openFirefoxAtUrl(token.getRedirectLocation());
    driver.findElement(By.name("cardnumber")).sendKeys("4444333322221111");
    driver.findElement(By.name("cardnumber")).sendKeys(Keys.TAB);
    driver.findElement(By.id("expiry")).sendKeys("1220");
    driver.findElement(By.id("expiry")).sendKeys(Keys.TAB);
    driver.findElement(By.name("cvc")).sendKeys("123");
    driver.findElement(By.name("cvc")).sendKeys(Keys.TAB);

    Payment response = mpay24.payment(getTestPaymentRequest(), getTokenPaymentType(token.getToken()));

    assertEquals("REDIRECT", response.getReturnCode());
    assertNotNull(response.getmPayTid());
}
项目:mpay24-java    文件:TestToken.java   
@Test
public void testTokenPaymentWithout3DS() throws ParseException, PaymentException, InterruptedException {
    Token token = mpay24.token(getTestTokenRequest(null));
    assertEquals("REDIRECT", token.getReturnCode());
    assertNotNull(token.getApiKey());
    assertNotNull(token.getRedirectLocation());
    assertNotNull(token.getToken());

    RemoteWebDriver driver = openFirefoxAtUrl(token.getRedirectLocation());
    driver.findElement(By.name("cardnumber")).sendKeys("4444333322221111");
    driver.findElement(By.name("cardnumber")).sendKeys(Keys.TAB);
    driver.findElement(By.id("expiry")).sendKeys("0520");
    driver.findElement(By.id("expiry")).sendKeys(Keys.TAB);
    driver.findElement(By.name("cvc")).sendKeys("123");
    driver.findElement(By.name("cvc")).sendKeys(Keys.TAB);

    TimeUnit.SECONDS.sleep(1l);

    Payment response = mpay24.payment(getTestPaymentRequest(), getTokenPaymentType(token.getToken()));

    assertEquals("OK", response.getReturnCode());
    assertNotNull(response.getmPayTid());
}
项目:mpay24-java    文件:TestCreateCustomerViaToken.java   
@Test
public void testCreateCustomerViaToken() throws PaymentException {
    String customerId = "12345678987633";
    deleteProfileForTest(customerId);
    Token token = mpay24.token(getTestTokenRequest(customerId));
    assertEquals("REDIRECT", token.getReturnCode());
    assertNotNull(token.getApiKey());
    assertNotNull(token.getRedirectLocation());
    assertNotNull(token.getToken());

    RemoteWebDriver driver = openFirefoxAtUrl(token.getRedirectLocation());
    driver.findElement(By.name("cardnumber")).sendKeys("4444333322221111");
    driver.findElement(By.name("cardnumber")).sendKeys(Keys.TAB);
    driver.findElement(By.id("expiry")).sendKeys("1220");
    driver.findElement(By.id("expiry")).sendKeys(Keys.TAB);
    driver.findElement(By.name("cvc")).sendKeys("123");
    driver.findElement(By.name("cvc")).sendKeys(Keys.TAB);

    mpay24.createCustomer(getCustomerWithAddress(customerId, "Xenia Wiesbauer", "Grüngasse 16"), "x", getTokenPaymentType(token.getToken()));

}
项目:opentest    文件:ActionsKeyUp.java   
@Override
public void run() {
    super.run();

    By locator = this.readLocatorArgument("locator", null);
    String keyValue = this.readStringArgument("key", null);
    String charValue = this.readStringArgument("char", null);

    CharSequence key = null;
    if (keyValue != null) {
        key = Keys.valueOf(keyValue);
    } else if (charValue != null) {
        key = charValue;
    } else {
        throw new RuntimeException(
                "You must either provide the \"key\" argument or the \"char\" "
                + "argument to specify the key you want to press.");
    }

    if (locator != null) {
        WebElement element = this.getElement(locator);
        SeleniumTestAction.getActionsInstance().keyUp(element, key);
    } else {
        SeleniumTestAction.getActionsInstance().keyUp(key);
    }
}
项目:opentest    文件:ActionsKeyDown.java   
@Override
public void run() {
    super.run();

    By locator = this.readLocatorArgument("locator", null);
    String keyValue = this.readStringArgument("key", null);
    String charValue = this.readStringArgument("char", null);

    CharSequence key = null;
    if (keyValue != null) {
        key = Keys.valueOf(keyValue);
    } else if (charValue != null) {
        key = charValue;
    } else {
        throw new RuntimeException(
                "You must either provide the \"key\" argument or the \"char\" "
                + "argument to specify the key you want to press.");
    }

    if (locator != null) {
        WebElement element = this.getElement(locator);
        SeleniumTestAction.getActionsInstance().keyDown(element, key);
    } else {
        SeleniumTestAction.getActionsInstance().keyDown(key);
    }
}
项目:SWET    文件:Utils.java   
public void inspectElement(WebElement element) {
    keyCTRL = osName.startsWith("Mac") ? Keys.COMMAND : Keys.CONTROL;

    if (osName.startsWith("Mac")) {
        actions.keyDown(keyCTRL).build().perform();
        actions.moveToElement(element).contextClick().build().perform();
        actions.keyUp(keyCTRL).build().perform();
    } else {
        actions.moveToElement(element).build().perform();
        actions.keyDown(keyCTRL).contextClick().keyUp(keyCTRL).build().perform();
    }
    // Assert
    try {
        Thread.sleep(100);
    } catch (InterruptedException e) {
    }
}
项目:Cognizant-Intelligent-Test-Scripter    文件:KeyActions.java   
/**
 * press enter key
 */
@Action(object = ObjectType.BROWSER, desc = "Press enter key")
public void enter() {
    try {
        if (!browserAction()) {
            if (Element != null) {
                (Element).sendKeys(Keys.ENTER);
                Report.updateTestLog(Action, "Enter pressed", Status.PASS);
            } else {
                throw new ElementException(
                        ElementException.ExceptionType.Element_Not_Found, Condition);
            }
        } else {
            ((AndroidDriver) Driver).pressKeyCode(AndroidKeyCode.KEYCODE_ENTER);
            Report.updateTestLog(Action, "Enter pressed", Status.PASS);
        }
    } catch (Exception ex) {
        Report.updateTestLog(Action, ex.getMessage(), Status.DEBUG);
        Logger.getLogger(KeyActions.class.getName()).log(Level.SEVERE, null, ex);
    }
}
项目:Actitime-Framework    文件:DeviceLogin.java   
/**
 * This method is used to login to ActiTime Application
 * 
 * @throws IOException
 **/
public String login() {
    try {
        if (Driver.getType().equalsIgnoreCase("Desktop")) {
            driver.get(Driver.getDesktopUrl());
        } else if (Driver.getType().equalsIgnoreCase("Device")) {
            driver.get(Driver.getDeviceUrl());
        }
        HelperManager.implicitWait(driver);
        userName.sendKeys(FileUtilityManager.getTestData().get("UserID"));
        passWord.sendKeys(FileUtilityManager.getTestData().get("Pwd"));
        passWord.sendKeys(Keys.TAB);
        passWord.sendKeys(Keys.TAB);
        passWord.sendKeys(Keys.ENTER);
        HelperManager.normalWait(driver, 2);
    } catch (NullPointerException e) {
        e.printStackTrace();
    }
    return driver.getTitle();
}
项目:Actitime-Framework    文件:WebLogin.java   
/**
 * This method is used to login to ActiTime Application
 * 
 * @throws IOException
 **/
public String login() {
    try {
        if (Driver.getType().equalsIgnoreCase("Desktop")) {
            driver.get(Driver.getDesktopUrl());
        } else if (Driver.getType().equalsIgnoreCase("Device")) {
            driver.get(Driver.getDeviceUrl());
        }
        username.sendKeys(FileUtilityManager.getTestData().get("UserID"));
        password.sendKeys(FileUtilityManager.getTestData().get("Pwd"));
        password.sendKeys(Keys.TAB);
        password.sendKeys(Keys.TAB);
        password.sendKeys(Keys.ENTER);
        HelperManager.normalWait(driver, 5);
    } catch (NullPointerException e) {
        e.printStackTrace();
    }
    return driver.getTitle();
}
项目:automationAbstractions    文件:VisibleToDoEntry.java   
public VisibleToDoEntry edit(String newText){
    waitUntilClickable();

    EnsureWebElementIs.inViewOnThePage(driver, todoEntry);

    // have no choice but to use actions here
    new Actions(driver).doubleClick(todoEntry.findElement(By.cssSelector("div > label"))).perform();

    WebElement editField = todoEntry.findElement(By.cssSelector("input.edit"));
    wait.until(ExpectedConditions.elementToBeClickable(editField));
    editField.click();
    editField.clear();
    editField.sendKeys(newText);
    editField.sendKeys(Keys.ENTER);

    return this;
}
项目:automationAbstractions    文件:ApplicationPageStructuralLoadable.java   
public void editItem(int itemIndex, String editTheTitleTo) {
    List<WebElement> items = getTodoItems(ItemsInState.VISIBLE);
    WebElement todoListItem = items.get(itemIndex);
    wait.until(ExpectedConditions.elementToBeClickable(todoListItem));

    // have no choice but to use actions here
    new Actions(driver).doubleClick(todoListItem.findElement(By.cssSelector("div > label"))).perform();
    // have to be more specific about locators on the mac, the above works, the below doesn't
    //new Actions(driver).doubleClick(todoListItem).perform();

    WebElement editfield = todoListItem.findElement(By.cssSelector("input.edit"));
    wait.until(ExpectedConditions.elementToBeClickable(editfield));
    editfield.click();
    editfield.clear();
    editfield.sendKeys(editTheTitleTo);
    editfield.sendKeys(Keys.ENTER);
}
项目:automationAbstractions    文件:ApplicationPageStructural.java   
public void editItem(int itemIndex, String editTheTitleTo) {
    List<WebElement> items = getTodoItems(ItemsInState.VISIBLE);
    WebElement todoListItem = items.get(itemIndex);
    wait.until(ExpectedConditions.elementToBeClickable(todoListItem));

    // have no choice but to use actions here
    new Actions(driver).doubleClick(todoListItem.findElement(By.cssSelector("div > label"))).perform();
    // have to be more specific about locators on the mac, the above works, the below doesn't
    //new Actions(driver).doubleClick(todoListItem).perform();

    WebElement editfield = todoListItem.findElement(By.cssSelector("input.edit"));
    wait.until(ExpectedConditions.elementToBeClickable(editfield));
    editfield.click();
    editfield.clear();
    editfield.sendKeys(editTheTitleTo);
    editfield.sendKeys(Keys.ENTER);
}
项目:automationAbstractions    文件:NoAbstractionTest.java   
@Test
public void canCreateAToDoWithNoAbstraction(){

    driver.get(siteURL);

    int originalNumberOfTodos = driver.findElements(
                                    By.cssSelector("ul.todo-list li")).size();

    WebElement createTodo = driver.findElement(By.className("new-todo"));
    createTodo.click();
    createTodo.sendKeys("new task");
    createTodo.sendKeys(Keys.ENTER);

    assertThat(driver.findElement(
                        By.className("filters")).isDisplayed(), is(true));

    int newToDos = driver.findElements(
                            By.cssSelector("ul.todo-list li")).size();

    assertThat(newToDos, greaterThan(originalNumberOfTodos));
}
项目:automationAbstractions    文件:NoAbstractionTest.java   
@Test
public void implicitWaitExample(){

    driver.manage().timeouts().implicitlyWait(15L, TimeUnit.SECONDS);

    driver.get(siteURL);

    int originalNumberOfTodos = driver.findElements(
            By.cssSelector("ul.todo-list li")).size();

    WebElement createTodo = driver.findElement(By.className("new-todo"));
    createTodo.click();
    createTodo.sendKeys("new task");
    createTodo.sendKeys(Keys.ENTER);

    assertThat(driver.findElement(
            By.className("filters")).isDisplayed(), is(true));

    int newToDos = driver.findElements(
            By.cssSelector("ul.todo-list li")).size();

    assertThat(newToDos, greaterThan(originalNumberOfTodos));
}
项目:automationAbstractions    文件:NoAbstractionTest.java   
@Test
public void explicitWaitExample(){

    driver.manage().timeouts().implicitlyWait(0L, TimeUnit.SECONDS);
    WebDriverWait wait = new WebDriverWait(driver,15);

    driver.get(siteURL);

    int originalNumberOfTodos = driver.findElements(
            By.cssSelector("ul.todo-list li")).size();

    WebElement createTodo = driver.findElement(By.className("new-todo"));
    createTodo.click();
    createTodo.sendKeys("new task");
    createTodo.sendKeys(Keys.ENTER);

    wait.until(ExpectedConditions.elementToBeClickable(By.className("filters")));

    int newToDos = driver.findElements(
            By.cssSelector("ul.todo-list li")).size();

    assertThat(newToDos, greaterThan(originalNumberOfTodos));
}
项目:Auto-LinkedIn    文件:SearchResultsPage.java   
/**
 * Clicks on every persons LinkedIn profile and opens it as a new tab, to save having to go back to the previous page

 */
public void clickAllUsersProfiles() {

    /*
     * http://stackoverflow.com/questions/6032230/selenium-2-open-link-in-new-tab-and-close-tabs
     * Chrome key combos:
     * SHIFT + CTRL + click = Open in new tab (and switch to new tab)
     * SHIFT + CTRL + RETURN = Open in new tab (in background)
     */
    Actions act = new Actions(driver);
    act.keyDown(Keys.LEFT_CONTROL).keyDown(Keys.LEFT_SHIFT).perform();
    for (WebElement userImage: userImages) {

        userImage.click();
    }

    act.keyUp(Keys.LEFT_CONTROL).keyDown(Keys.LEFT_SHIFT).perform(); // finished up, important to stop holding down those keys
}
项目:helium    文件:BaseTest.java   
protected void esperaFinExecucioMassiva(List<String[]> expedientes, String botoMassiuPath) throws InterruptedException {
    final int esperaMax = 1000*60*2;
    int espera = esperaMax;

    if (existeixElement(botoMassiuPath)) {
        if (expedientes == null) {
            // Supondremos que es la última
            while (espera > 0 && !terminadaUltimaExecucioMassiva(botoMassiuPath)) {
                espera -= 1000*15;
                Thread.sleep(1000*15);
            };
        } else {
            for (String[] expedient : expedientes) {
                while (espera > 0 && !finalizadoExpedientExecucioMassiva(expedient, botoMassiuPath))  {
                    espera -= 1000*15;
                    Thread.sleep(1000*15);
                };
            }
        }
    } else {
        // No se tenían permisos
        Thread.sleep(espera);
    }

    actions.sendKeys(Keys.ESCAPE);
}
项目:helium    文件:BaseTest.java   
protected int estadoExpedientExecucioMassiva(String expedient, String botoMassiuPath) throws InterruptedException {
    // -1 : No encontrado
    //  0 : Pendiente
    //  1 : Finalizado
    //  2 : Error
    int estado = -1;
    driver.findElement(By.xpath(botoMassiuPath)).click();
    for (WebElement fila : driver.findElements(By.xpath("//span[contains(@class,'ui-icon-triangle-1-')]"))) {
        if (fila.getAttribute("class").contains("ui-icon-triangle-1-e"))
            fila.click();           
        if (existeixElement("//tbody/tr[contains(td/text(),'"+expedient+"')]//label")) {
            if (existeixElement("//tbody/tr[contains(td/text(),'"+expedient+"')][1]//img[contains(@src,'/img/mass_error.png')]")) {
                estado = 2;                 
            } else if (existeixElement("//tbody/tr[contains(td/text(),'"+expedient+"')][1]//img[contains(@src,'/img/mass_fin.png')]")) {
                estado = 1;
            } else if (existeixElement("//tbody/tr[contains(td/text(),'"+expedient+"')][1]//img[contains(@src,'/img/mass_pend.png')]")) {
                estado = 0;
            }
            break;
        }
    }
    actions.sendKeys(Keys.ESCAPE);
    return estado;
}
项目:bobcat    文件:AemRichText.java   
/**
 * Clears the content of richtext's text area.
 *
 * @return This instance.
 */
public AemRichText clear() {
  switchToTextArea();
  try {
    bobcatWait.withTimeout(Timeouts.BIG).until(driver -> {
      actions.sendKeys(Keys.chord(Keys.CONTROL, "a")).sendKeys(Keys.BACK_SPACE).sendKeys(Keys.BACK_SPACE).
          perform();
      WebElement activeElement = webDriver.switchTo().activeElement();
      String text = activeElement.getText();
      return text.isEmpty();
    }, 2);
    return this;
  } finally {
    frameSwitcher.switchBack();
  }
}
项目:bobcat    文件:AemRichText.java   
/**
 * Selects text in the text area between indices provided as parameters.
 *
 * @param startPos the beginning position
 * @param endPos   the ending position
 * @return This instance.
 */
public AemRichText selectText(int startPos, int endPos) {
  switchToTextArea();
  try {
    actions.sendKeys(Keys.chord(Keys.CONTROL, Keys.HOME)).perform();
    for (int i = 0; i < startPos; i++) {
      actions.sendKeys(Keys.ARROW_RIGHT).perform();
    }
    actions.keyDown(Keys.SHIFT);
    for (int i = 0; i < endPos - startPos; i++) {
      actions.sendKeys(Keys.ARROW_RIGHT);
    }
    actions.keyUp(Keys.SHIFT).perform();
    return this;
  } finally {
    frameSwitcher.switchBack();
  }
}
项目:xframium-java    文件:KeyPressGesture.java   
@Override
protected boolean _executeGesture( WebDriver webDriver )
{
    String[] keyCodes = getKeyCode().split("\\+");
    String keyPressed = null;
    List<CharSequence> charSequence = new ArrayList<CharSequence>();

    for (String keyCode : keyCodes) {

        if (Keys.valueOf(keyCode) != null) {
            charSequence.add(Keys.valueOf(keyCode.toUpperCase()));

        } else {
            throw new IllegalArgumentException( "Unsupported KeyPressGesture Type " + keyCode );
        }

    }

    if (charSequence.size() > 0) {
        Iterable<CharSequence> iterable = charSequence;
        keyPressed = Keys.chord(iterable);
        new Actions( webDriver ).moveToElement( webElement ).sendKeys(keyPressed).perform();
    }
    return true;
}
项目:mpay24-java    文件:TestToken.java   
@Test
public void testTokenPaymentWith3DS() throws ParseException, PaymentException {
    Token token = mpay24.token(getTestTokenRequest(null));
    assertEquals("REDIRECT", token.getReturnCode());
    assertNotNull(token.getApiKey());
    assertNotNull(token.getRedirectLocation());
    assertNotNull(token.getToken());

    RemoteWebDriver driver = openFirefoxAtUrl(token.getRedirectLocation());
    driver.findElement(By.name("cardnumber")).sendKeys("4444333322221111");
    driver.findElement(By.name("cardnumber")).sendKeys(Keys.TAB);
    driver.findElement(By.id("expiry")).sendKeys("1220");
    driver.findElement(By.id("expiry")).sendKeys(Keys.TAB);
    driver.findElement(By.name("cvc")).sendKeys("123");
    driver.findElement(By.name("cvc")).sendKeys(Keys.TAB);

    Payment response = mpay24.payment(getTestPaymentRequest(), getTokenPaymentType(token.getToken()));

    assertEquals("REDIRECT", response.getReturnCode());
    assertNotNull(response.getmPayTid());
}
项目:mpay24-java    文件:TestToken.java   
@Test
public void testTokenPaymentWithout3DS() throws ParseException, PaymentException, InterruptedException {
    Token token = mpay24.token(getTestTokenRequest(null));
    assertEquals("REDIRECT", token.getReturnCode());
    assertNotNull(token.getApiKey());
    assertNotNull(token.getRedirectLocation());
    assertNotNull(token.getToken());

    RemoteWebDriver driver = openFirefoxAtUrl(token.getRedirectLocation());
    driver.findElement(By.name("cardnumber")).sendKeys("4444333322221111");
    driver.findElement(By.name("cardnumber")).sendKeys(Keys.TAB);
    driver.findElement(By.id("expiry")).sendKeys("0520");
    driver.findElement(By.id("expiry")).sendKeys(Keys.TAB);
    driver.findElement(By.name("cvc")).sendKeys("123");
    driver.findElement(By.name("cvc")).sendKeys(Keys.TAB);

    TimeUnit.SECONDS.sleep(1l);

    Payment response = mpay24.payment(getTestPaymentRequest(), getTokenPaymentType(token.getToken()));

    assertEquals("OK", response.getReturnCode());
    assertNotNull(response.getmPayTid());
}
项目:mpay24-java    文件:TestCreateCustomerViaToken.java   
@Test
public void testCreateCustomerViaToken() throws PaymentException {
    String customerId = "12345678987633";
    deleteProfileForTest(customerId);
    Token token = mpay24.token(getTestTokenRequest(customerId));
    assertEquals("REDIRECT", token.getReturnCode());
    assertNotNull(token.getApiKey());
    assertNotNull(token.getRedirectLocation());
    assertNotNull(token.getToken());

    RemoteWebDriver driver = openFirefoxAtUrl(token.getRedirectLocation());
    driver.findElement(By.name("cardnumber")).sendKeys("4444333322221111");
    driver.findElement(By.name("cardnumber")).sendKeys(Keys.TAB);
    driver.findElement(By.id("expiry")).sendKeys("1220");
    driver.findElement(By.id("expiry")).sendKeys(Keys.TAB);
    driver.findElement(By.name("cvc")).sendKeys("123");
    driver.findElement(By.name("cvc")).sendKeys(Keys.TAB);

    mpay24.createCustomer(getCustomerWithAddress(customerId, "Xenia Wiesbauer", "Grüngasse 16"), "x", getTokenPaymentType(token.getToken()));

}