Example usage for org.openqa.selenium WebElement sendKeys

List of usage examples for org.openqa.selenium WebElement sendKeys

Introduction

In this page you can find the example usage for org.openqa.selenium WebElement sendKeys.

Prototype

void sendKeys(CharSequence... keysToSend);

Source Link

Document

Use this method to simulate typing into an element, which may set its value.

Usage

From source file:com.novartis.opensource.yada.test.YADAAdminTest.java

License:Apache License

/**
 * Test App Manager new app creation//  w ww . j a  v a  2  s .co m
 * @throws InterruptedException if any thread has interrupted the current thread
 */
@Test(dependsOnMethods = { "testLoginSuccess" })
public void testAppCreation() throws InterruptedException {
    String t = new String(Long.valueOf(new Date().getTime()).toString());
    this.app = "FOO" + t.substring(t.length() < 17 ? 0 : t.length() - 17);
    WebDriver d = getDriver();
    d.findElement(By.id("app-hdr-new")).click();
    Thread.sleep(100);
    Assert.assertTrue(d.findElement(By.id("app-new")).isDisplayed());
    d.findElement(By.id("app-code-new")).sendKeys(this.app);
    d.findElement(By.id("app-active-new")).click();
    d.findElement(By.id("app-name-new")).sendKeys(this.app);
    d.findElement(By.id("app-desc-new")).sendKeys("This is a test of new app functions using app " + this.app);
    StringBuilder conf = new StringBuilder();
    conf.append("jdbcUrl=");
    conf.append(this.dbUrl);
    conf.append("\nusername=");
    conf.append(this.dbUser);
    conf.append("\npassword=");
    conf.append(this.dbPw);
    conf.append("\ndriverClassName=");
    conf.append(this.dbDriver);
    conf.append("\nautoCommit=false");
    conf.append("\nconnectionTimeout=300000");
    conf.append("\nidleTimeout=600000");
    conf.append("\nmaxLifetime=1800000");
    conf.append("\nminimumIdle=5");
    conf.append("\nmaximumPoolSize=100");
    WebElement e = d.findElement(By.id("app-conf-new"));
    e.clear();
    e.sendKeys(conf.toString());
    d.findElement(By.id("app-submit-new")).click();
    e = new WebDriverWait(d, 20)
            .until(ExpectedConditions.presenceOfElementLocated(By.id("app-hdr-" + this.app)));
    Assert.assertTrue(e.isDisplayed());
}

From source file:com.novartis.opensource.yada.test.YADAAdminTest.java

License:Apache License

/**
 * <ol>//from w  w w  . j a  v a 2 s  .  com
 * <li>Opens the query editor</li>
 * <li>Validates all the buttons are present</li>
 * <li>Opens the security panel</li>
 * <li>Sets URL validation policy</li>
 * <li>Sets TokenValidation policy</li>
 * <li>Sets ExecutionPolicy</li>
 * <li>Sets ContentPolicy</li>
 * </ol>
 * @throws InterruptedException if any thread has interrupted the current thread
 * @throws IOException when the test URL can't be accessed 
 */
@Test(dependsOnMethods = { "testNewQueryForNewAppSave" })
public void testSecurityConfigForQuery() throws InterruptedException, IOException {
    WebDriver d = getDriver();
    String protector = this.app + " Test Protector";
    this.createQueryForNewApp(" Test Protector", "SELECT 1 AS COL1", "save");
    WebElement save = d.findElement(By.id("button-save"));

    // validate ui
    WebElement e = new WebDriverWait(d, 20)
            .until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".alert-success")));
    String expected = "Hooray! Query " + protector + " was saved successfully.";
    Assert.assertEquals(e.getText(), expected);
    Assert.assertFalse(save.isDisplayed());

    // close dialog
    d.findElement(By.id("button-cancel")).click();
    Thread.sleep(3000);

    // restore app-mgr
    d.findElement(By.id("app")).click();
    new WebDriverWait(d, 20).until(ExpectedConditions.presenceOfElementLocated(By.id("app-mgr")));
    Thread.sleep(3000);

    // nav to queries
    d.findElement(By.id("app-qname-" + this.app)).click();
    Thread.sleep(3000);

    // open query for edit
    String qname = this.app + " Test Save";
    d.findElement(By.xpath("//*[text()[contains(.,\"" + qname + "\")]]")).click();
    this.switchToActiveElement(d, 3000);
    new WebDriverWait(d, 20)
            .until(ExpectedConditions.presenceOfElementLocated(By.id("query-editor-container")));

    // validate buttons
    List<WebElement> list = d.findElements(By.cssSelector("#query-editor-container .modal-footer button"));
    Assert.assertEquals(list.size(), 5);
    for (WebElement b : list) {
        Assert.assertTrue(b.isDisplayed() && b.isEnabled());
    }

    // open security panel
    d.findElement(By.id("headingTwo")).click();
    Thread.sleep(3000);

    // Confirm query result
    String result = getUrl(qname);
    l.debug("EXPECT NORMAL RESULT:\n" + result);
    Assert.assertTrue(result.contains(qname) && result.toUpperCase().contains("\"ROWS\":[{\"COL1\":\"1\"}]"));

    // "Mark this query as secure" and confirm "unauth"
    d.findElement(By.id("secure-query-ckbx")).click();
    d.findElement(By.id("button-save")).click();
    Thread.sleep(3000);
    result = getUrl(qname);
    l.debug("EXPECT UNAUTHORIZED RESULT:\n" + result);
    //   should be rejected at this point due to checkbox + lack of plugin
    Assert.assertFalse(result.contains(qname) && result.toUpperCase().contains("\"ROWS\":[{\"COL1\":\"1\"}]"));
    Assert.assertTrue(result.contains("Server returned HTTP response code: 403"));
    d.findElement(By.id("button-cancel")).click(); // back to app-mgr
    Thread.sleep(3000);

    // open query for edit
    e = new WebDriverWait(d, 20).until(ExpectedConditions
            .presenceOfElementLocated(By.xpath("//*[text()[contains(.,\"" + qname + "\")]]")));
    e.click();
    this.switchToActiveElement(d, 3000);
    new WebDriverWait(d, 20)
            .until(ExpectedConditions.presenceOfElementLocated(By.id("query-editor-container")));

    if (!d.findElement(By.id("secure-query-ckbx")).isDisplayed()) {
        d.findElement(By.id("headingTwo")).click();
        Thread.sleep(3000);
    }

    // confirm "Mark this query as not secure"
    d.findElement(By.id("secure-query-ckbx")).click();
    d.findElement(By.id("button-save")).click();
    Thread.sleep(3000);
    result = getUrl(qname);
    l.debug("EXPECT NORMAL RESULT:\n" + result);
    //   should be accepted, as box is unchecked
    Assert.assertTrue(result.contains(qname) && result.toUpperCase().contains("\"ROWS\":[{\"COL1\":\"1\"}]"));
    d.findElement(By.id("button-cancel")).click();
    Thread.sleep(3000);

    // open query for edit
    e = new WebDriverWait(d, 20).until(ExpectedConditions
            .presenceOfElementLocated(By.xpath("//*[text()[contains(.,\"" + qname + "\")]]")));
    e.click();
    this.switchToActiveElement(d, 3000);
    new WebDriverWait(d, 20)
            .until(ExpectedConditions.presenceOfElementLocated(By.id("query-editor-container")));

    if (!d.findElement(By.id("secure-query-ckbx")).isDisplayed()) {
        d.findElement(By.id("headingTwo")).click();
    }
    //    l.debug("Sleeping for 2 minutes to enable manual investigation");
    Thread.sleep(3000);
    // validate all components
    //   what is there before any data entry?

    WebElement plugin = d.findElement(By.className("policy-plugin"));
    WebElement policyArg = d.findElement(By.className("policy-arg"));
    WebElement argString = d.findElement(By.className("arg-string"));

    Assert.assertTrue(d.findElement(By.className("policy-group")).isDisplayed());
    Assert.assertTrue(plugin.isDisplayed());
    Assert.assertTrue(d.findElement(By.className("policy-action")).isDisplayed());
    Assert.assertTrue(argString.isDisplayed());
    Assert.assertTrue(d.findElement(By.className("policy-type")).isDisplayed());
    Assert.assertTrue(policyArg.isDisplayed());
    Assert.assertTrue(d.findElement(By.className("remove-policy")).isDisplayed());

    // enter policies

    //   what is there after each policy entry  
    plugin.sendKeys("Gatekeeper");
    Select policyType = new Select(d.findElement(By.className("policy-type")));
    policyType.selectByVisibleText("URL Pattern Matching");
    policyArg.clear();
    policyArg.sendKeys("auth.path.rx=^(https?://)?localhost:8080/.+$");
    Assert.assertEquals(argString.getText(), "auth.path.rx=^(https?://)?localhost:8080/.+$");

    Select policyAction = new Select(d.findElement(By.className("policy-action")));
    policyAction.selectByValue("save");
    Thread.sleep(2000);
    policyAction.selectByValue("add-same");
    //Thread.sleep(3000);

    String xpath = "//div[contains(@class,\"security-options\")][2]";
    e = new WebDriverWait(d, 20).until(ExpectedConditions.presenceOfElementLocated(By.xpath(xpath)));

    List<WebElement> policies = d.findElements(By.className("security-options"));
    List<WebElement> policyTypes = d.findElements(By.className("policy-type"));
    List<WebElement> policyArgs = d.findElements(By.className("policy-arg"));

    policyType = new Select(policyTypes.get(1));
    policyType.selectByVisibleText("Execution Policy (Indices)");
    policyArgs.get(1).clear();
    policyArgs.get(1).sendKeys("execution.policy.indices=0:getToken()");
    Assert.assertTrue(d.findElement(By.className("policy-protector")).isDisplayed());
    d.findElement(By.className("policy-protector")).sendKeys(protector);

    policyAction.selectByValue("save");
    Thread.sleep(3000);
    policyAction.selectByValue("add-same");
    //Thread.sleep(3000);

    xpath = "//div[contains(@class,\"security-options\")][3]";
    e = new WebDriverWait(d, 20).until(ExpectedConditions.presenceOfElementLocated(By.xpath(xpath)));

    policies = d.findElements(By.className("security-options"));
    policyTypes = d.findElements(By.className("policy-type"));
    policyArgs = d.findElements(By.className("policy-arg"));
    List<WebElement> policyProtectors = d.findElements(By.className("policy-protector"));

    policyType = new Select(policyTypes.get(2));
    policyType.selectByVisibleText("Execution Policy (Columns)");
    policyArgs.get(2).clear();
    policyArgs.get(2).sendKeys("execution.policy.columns=0:getToken()");

    Assert.assertEquals(policyProtectors.size(), 2);
    policyProtectors.get(1).sendKeys(protector);

    policyAction.selectByValue("save");
    Thread.sleep(2000);
    policyAction.selectByValue("add-same");

    xpath = "(//input[contains(@class,\"security-options\")])[3]";
    e = new WebDriverWait(d, 20).until(ExpectedConditions.presenceOfElementLocated(By.xpath(xpath)));

    policies = d.findElements(By.className("security-options"));
    policyTypes = d.findElements(By.className("policy-type"));
    policyArgs = d.findElements(By.className("policy-arg"));
    policyProtectors = d.findElements(By.className("policy-protector"));

    policyType = new Select(policyTypes.get(3));
    policyType.selectByVisibleText("Content Policy");
    policyArgs.get(3).clear();
    policyArgs.get(3).sendKeys("content.policy.predicate=x=y");

    expected = "auth.path.rx=^(https?://)?localhost:8080.+$,execution.policy.indices=0:getToken(),execution.policy.columns=token:getToken(),content.policy.predicate=x=y";
    Assert.assertEquals(argString.getText(), expected);

    // save 
    //   multiple ways to save? (not yet)
    policyAction.selectByValue("save");

    // TODO validate data is in db
    // TODO validate security works? or is this just for a standard integration test?
    // TODO alert user when security setting is invalid or unsavable for any reason
    // TODO alert user to save security settings (this may enable safety net after all)
    // TODO parse security param into UI when appropriate (it currently doesn't) 

    d.findElement(By.id("button-save")).click();
    Thread.sleep(3000);

    d.findElement(By.id("app")).click();
    new WebDriverWait(d, 20).until(ExpectedConditions.presenceOfElementLocated(By.id("app-mgr")));
    Thread.sleep(3000);

    // nav to queries
    d.findElement(By.id("app-qname-" + this.app)).click();
    Thread.sleep(3000);

    // open query for edit
    d.findElement(By.xpath("//*[text()[contains(.,\"" + qname + "\")]]")).click();
    this.switchToActiveElement(d, 3000);
    new WebDriverWait(d, 20)
            .until(ExpectedConditions.presenceOfElementLocated(By.id("query-editor-container")));

    d.findElement(By.id("headingThree")).click();
    Thread.sleep(3000);
    String actual = d.findElement(By.cssSelector("$('#default-params tbody tr:eq(0) td input:eq(1)')"))
            .getAttribute("value");
    Assert.assertEquals(actual, expected);

}

From source file:com.nowsprinting.hellotesting.appiumtest.appium.page.DetailPage.java

License:Apache License

/**
 * ??????/*from   w  w w.j ava 2s . co m*/
 * ?null?????????
 * 
 * @param name ?
 * @return ???
 */
public DetailPage inputName(String name) {
    if (name != null) {
        WebElement nameTextField = mDriver.findElement(MobileBy.AccessibilityId("name textfield"));
        nameTextField.sendKeys(name);
    }
    return this;
}

From source file:com.nowsprinting.hellotesting.appiumtest.appium.page.DetailPage.java

License:Apache License

/**
 * mail???//from  ww  w  .  j  ava  2s  .  c  o m
 * ?null?????????
 * 
 * @param mailAddress ?
 * @return ???
 */
public DetailPage inputMailAddress(String mailAddress) {
    if (mailAddress != null) {
        WebElement mailTextField = mDriver.findElement(MobileBy.AccessibilityId("mail textfield"));
        mailTextField.sendKeys(mailAddress);

    }
    return this;
}

From source file:com.nowsprinting.hellotesting.appiumtest.selendroid.page.SelendroidDetailPage.java

License:Apache License

@Override
public DetailPage inputName(String name) {
    if (name != null) {
        WebElement nameTextField = mDriver.findElement(By.name("name textfield"));
        nameTextField.sendKeys(name);
    }//www .  j  a  v  a 2 s .co m
    return this;
}

From source file:com.nowsprinting.hellotesting.appiumtest.selendroid.page.SelendroidDetailPage.java

License:Apache License

@Override
public DetailPage inputMailAddress(String mailAddress) {
    if (mailAddress != null) {
        WebElement mailTextField = mDriver.findElement(By.name("mail textfield"));
        mailTextField.sendKeys(mailAddress);

    }//from w w  w.  j av  a 2 s . co m
    return this;
}

From source file:com.nowsprinting.hellotesting.appiumtest.selendroid.page.SelendroidDetailPage.java

License:Apache License

@Override
public DetailPage inputAge(int age) {
    /*/*from   w w  w  . j  a v  a 2 s  .  c  o  m*/
     * ---------------------------
     * NumberPicker
     * Button (1??)
     * EditText (?: 4?)
     * Button (1??)
     * ---------------------------
     * ???????????
     * NumberPicker??EditText????
     */
    WebElement numberPicker = mDriver.findElement(By.className(WIDGET_NUMBER_PICKER));
    WebElement ageTextField = numberPicker.findElement(By.className(WIDGET_EDIT_TEXT));
    ageTextField.sendKeys(String.valueOf(age));
    ageTextField.click();
    return this;
}

From source file:com.nuxeo.functionaltests.ITAssetViewTest.java

License:Open Source License

@Test
public void testIntellectualProperty() throws Exception {
    login("leela", "test");

    DAMPage damPage = getDAMPage();//from  www.ja  v  a2  s  . c om
    damPage = damPage.createAsset("File", "One File", "One File description", "Leela", "1/1/2012");

    AssetViewFragment assetViewFragment = damPage.getAssetViewFragment();
    FoldableBoxFragment ipBox = assetViewFragment.getFoldableBox("Intellectual Property", true);
    ipBox.checkTextToBeNotPresent("New holder");
    ipBox.edit();

    WebElement copyrightHolderInput = driver.findElement(
            By.id("nxl_gridDamLayout:nxw_damAssetViewIpRights_toggledForm:nxl_ip_rights:nxw_copyright_holder"));
    copyrightHolderInput.clear();
    copyrightHolderInput.sendKeys("New holder");
    ipBox.save();

    Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(5, TimeUnit.SECONDS)
            .pollingEvery(100, TimeUnit.MILLISECONDS).ignoring(NoSuchElementException.class);

    try {
        wait.until(new Function<WebDriver, WebElement>() {
            public WebElement apply(WebDriver driver) {
                return driver
                        .findElement(By.xpath("//div[contains(.,'" + FILE_MODIFIED_NOTIFICATION_LABEL + "')]"));
            }
        });
    } catch (TimeoutException e) {
        log.warn("Could not see saved message, maybe I was too slow and it "
                + "has already disappeared. Let's see if I can restore.");
    }

    ipBox.open();
    ipBox.waitForTextToBePresent("New holder");

    logout();
}

From source file:com.openones.auto.selen.Sample01.java

License:Apache License

public static void main(String[] args) {
    // Create a new instance of the Firefox driver
    // Notice that the remainder of the code relies on the interface, 
    // not the implementation.
    WebDriver driver = new FirefoxDriver();
    //WebDriver driver = new InternetExplorerDriver();

    // And now use this to visit Google
    driver.get("http://www.google.com");
    // Alternatively the same thing can be done like this
    // driver.navigate().to("http://www.google.com");

    // Find the text input element by its name
    WebElement element = driver.findElement(By.name("q"));

    // Enter something to search for
    element.sendKeys("Cheese!");

    // Now submit the form. WebDriver will find the form for us from the element
    element.submit();//from   w ww  .ja v  a 2  s  .  co  m

    // Check the title of the page
    System.out.println("Page title is: " + driver.getTitle());

    // Google's search is rendered dynamically with JavaScript.
    // Wait for the page to load, timeout after 10 seconds
    (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver d) {
            return d.getTitle().toLowerCase().startsWith("cheese!");
        }
    });

    // Should see: "cheese! - Google Search"
    System.out.println("Page title is: " + driver.getTitle());

    //Close the browser
    driver.quit();
}

From source file:com.opera.core.systems.HTML5FormTest.java

License:Apache License

@Test
public void setInputFileValue() {
    WebElement fileField = driver.findElement(By.id("file"));
    fileField.sendKeys(resources.textFile().getAbsolutePath());
    assertThat(fileField.getAttribute("value"), is("C:\\fakepath\\" + resources.textFile().getName()));
}