List of usage examples for org.openqa.selenium.support.ui ExpectedConditions presenceOfElementLocated
public static ExpectedCondition<WebElement> presenceOfElementLocated(final By locator)
From source file:org.oneandone.qxwebdriver.QxWebDriver.java
License:LGPL
/** * Find the first matching {@link Widget} using the given method. * //from w w w . j a va 2 s . c o m * @param by The locating mechanism * @param timeoutInSeconds time to wait for the widget * @return The first matching element on the current page * @throws NoSuchElementException If no matching widget was found before the timeout elapsed * @see org.oneandone.qxwebdriver.By */ protected Widget findWidget(By by, long timeoutInSeconds) throws NoSuchElementException { WebDriverWait wait = new WebDriverWait(driver, timeoutInSeconds); WebElement element; try { element = wait.until(ExpectedConditions.presenceOfElementLocated(by)); } catch (org.openqa.selenium.TimeoutException e) { throw new NoSuchElementException("Unable to find element for locator.", e); } return getWidgetForElement(element); }
From source file:org.openqa.selendroid.support.BaseAndroidTest.java
License:Apache License
protected void openWebdriverTestPage(String page) { driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); String activityClass = "org.openqa.selendroid.testapp." + "WebViewActivity"; driver.switchTo().window(NATIVE_APP); driver.get("and-activity://" + activityClass); waitFor(WaitingConditions.driverUrlToBe(driver, "and-activity://WebViewActivity")); WebDriverWait wait = new WebDriverWait(driver, 10); wait.until(ExpectedConditions.presenceOfElementLocated(By.linkText("Go to home screen"))); WebElement spinner = driver.findElement(By.id("spinner_webdriver_test_data")); spinner.click();/*from www . j a v a2 s. c o m*/ // Hack: to work around the bug that an already open page will not be opened again. // driver.findElement(By.linkText(HtmlTestData.ABOUT_BLANK)).click(); // try { // Thread.sleep(500); // } catch (InterruptedException e) { // e.printStackTrace(); // } // spinner.click(); WebElement entry = TestWaiter.waitForElement(By.linkText(page), 10, driver); entry.click(); driver.switchTo().window(WEBVIEW); }
From source file:org.openqa.selendroid.tests.CopyOfSayHelloWebviewTest.java
License:Apache License
@Test public void assertThatWebviewSaysHello() throws Exception { WebElement button = driver.findElement(By.id("buttonStartWebview")); button.click();/* www .jav a 2s .com*/ takeScreenShot("Main Activity started."); WebDriverWait wait = new WebDriverWait(driver, 10); wait.until(ExpectedConditions.presenceOfElementLocated(By.linkText("Go to home screen"))); driver.switchTo().window("WEBVIEW"); WebElement inputField = driver.findElement(By.id("name_input")); Assert.assertNotNull(inputField); inputField.clear(); inputField.sendKeys("Dominik"); takeScreenShot("After entering the name of the app user."); inputField.submit(); takeScreenShot("Result of web view: Hello app user."); }
From source file:org.openqa.selendroid.tests.SayHelloWebviewTest.java
License:Apache License
@Test public void assertThatWebviewSaysHello() throws Exception { WebElement button = driver.findElement(By.linkText("Start Webview")); takeScreenShot("Main Activity started."); button.click();//w w w . j ava2 s . co m WebDriverWait wait = new WebDriverWait(driver, 10); wait.until(ExpectedConditions.presenceOfElementLocated(By.linkText("Go to home screen"))); driver.switchTo().window("WEBVIEW"); WebElement inputField = driver.findElement(By.id("name_input")); Assert.assertNotNull(inputField); inputField.clear(); inputField.sendKeys("Dominik"); takeScreenShot("After entering the name of the app user."); inputField.submit(); takeScreenShot("Result of web view: Hello app user."); }
From source file:org.openqa.selendroid.tests.UserRegistrationTest.java
License:Apache License
private void registerUser(UserDO user) throws Exception { WebElement button = driver.findElement(By.id("startUserRegistration")); takeScreenShot("Main Activity started."); button.click();//from w w w . j a v a 2 s. c om WebDriverWait wait = new WebDriverWait(driver, 5); WebElement inputUsername = wait.until(ExpectedConditions.presenceOfElementLocated(By.id("inputUsername"))); inputUsername.sendKeys(user.getUsername()); driver.findElement(By.id("inputEmail")).sendKeys(user.getEmail()); driver.findElement(By.id("inputPassword")).sendKeys(user.getPassword()); WebElement nameInput = driver.findElement(By.id("inputName")); Assert.assertEquals(nameInput.getText(), "Mr. Burns"); nameInput.clear(); try { nameInput.submit(); Assert.fail("submit is not supported by SelendroidNativeDriver"); } catch (WebDriverException e) { // expected behavior } nameInput.sendKeys(user.getName()); driver.findElement(By.id("input_preferedProgrammingLanguage")).click(); driver.findElement(By.linkText(user.getProgrammingLanguage().getValue())).click(); WebElement acceptAddsCheckbox = driver.findElement(By.id("input_adds")); Assert.assertEquals(acceptAddsCheckbox.isSelected(), false); acceptAddsCheckbox.click(); takeScreenShot("User data entered."); Assert.assertEquals(driver.getCurrentUrl(), "and-activity://RegisterUserActivity"); try { driver.getTitle(); Assert.fail("Get title is not supported by SelendroidNativeDriver"); } catch (WebDriverException e) { // expected behavior } driver.findElement(By.id("btnRegisterUser")).click(); }
From source file:org.openqa.selendroid.tests.UserRegistrationTest.java
License:Apache License
private void verifyUser(UserDO user) throws Exception { WebDriverWait wait = new WebDriverWait(driver, 5); WebElement inputUsername = wait/* w ww .ja v a 2 s .c om*/ .until(ExpectedConditions.presenceOfElementLocated(By.id("label_username_data"))); Assert.assertEquals(inputUsername.getText(), user.getUsername()); Assert.assertEquals(driver.findElement(By.id("label_email_data")).getText(), user.getEmail()); Assert.assertEquals(driver.findElement(By.id("label_password_data")).getText(), user.getPassword()); Assert.assertEquals(driver.findElement(By.id("label_name_data")).getText(), user.getName()); Assert.assertEquals(driver.findElement(By.id("label_preferedProgrammingLanguage_data")).getText(), user.getProgrammingLanguage().getValue()); Assert.assertEquals(driver.findElement(By.id("label_acceptAdds_data")).getText(), "true"); takeScreenShot("User Data Verification Activity."); driver.findElement(By.id("buttonRegisterUser")).click(); }
From source file:org.openqa.selendroid.webviewdrivertests.ElementFindingTest.java
License:Apache License
private void openWebdriverTestPage(String page) { driver.switchTo().window(NATIVE_APP); driver.get("and-activity://" + ACTIVITY_CLASS); waitFor(WaitingConditions.driverUrlToBe(driver, "and-activity://WebViewActivity")); WebDriverWait wait = new WebDriverWait(driver, 10); wait.until(ExpectedConditions.presenceOfElementLocated(By.linkText("Go to home screen"))); driver.findElement(By.id("spinner_webdriver_test_data")).click(); driver.findElement(By.linkText(page)).click(); driver.switchTo().window(WEBVIEW);//from w w w . ja va 2 s. c om }
From source file:org.orcid.api.common.WebDriverHelper.java
License:Open Source License
public String obtainAuthorizationCode(String scopes, String orcid, String userId, String password, boolean isLoggedIn) throws InterruptedException { String url = String.format("%s/oauth/authorize?client_id=%s&response_type=code&scope=%s&redirect_uri=%s", webBaseUrl, orcid, scopes, redirectUri); webDriver.get(url);// ww w . jav a 2 s . c o m if (!isLoggedIn) { // Switch to the login form try { By switchFromLinkLocator = By.id("in-register-switch-form"); (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS)) .until(ExpectedConditions.presenceOfElementLocated(switchFromLinkLocator)); WebElement switchFromLink = webDriver.findElement(switchFromLinkLocator); switchFromLink.click(); } catch (Exception e) { System.out.println("Unable to load URL: " + url); e.printStackTrace(); throw e; } // Fill the form By userIdElementLocator = By.id("userId"); (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS)) .until(ExpectedConditions.presenceOfElementLocated(userIdElementLocator)); WebElement userIdElement = webDriver.findElement(userIdElementLocator); userIdElement.sendKeys(userId); WebElement passwordElement = webDriver.findElement(By.id("password")); passwordElement.sendKeys(password); WebElement submitButton = webDriver.findElement(By.id("authorize-button")); submitButton.click(); } else { By authorizeBtn = By.id("authorize"); (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS)) .until(ExpectedConditions.presenceOfElementLocated(authorizeBtn)); WebElement btn = webDriver.findElement(authorizeBtn); btn.click(); } (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS)).until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { return d.getTitle().equals("ORCID Playground"); } }); String currentUrl = webDriver.getCurrentUrl(); Matcher matcher = AUTHORIZATION_CODE_PATTERN.matcher(currentUrl); assertTrue(matcher.find()); String authorizationCode = matcher.group(1); assertNotNull(authorizationCode); return authorizationCode; }
From source file:org.orcid.api.common.WebDriverHelper.java
License:Open Source License
public void signIn(String userId, String password) throws InterruptedException { webDriver.get(String.format("%s/signin", webBaseUrl)); // Fill the form By userIdElementLocator = By.id("userId"); (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS)) .until(ExpectedConditions.presenceOfElementLocated(userIdElementLocator)); WebElement userIdElement = webDriver.findElement(userIdElementLocator); userIdElement.sendKeys(userId);//from w ww . ja va2 s. c o m WebElement passwordElement = webDriver.findElement(By.id("password")); passwordElement.sendKeys(password); WebElement submitButton = webDriver.findElement(By.id("form-sign-in-button")); submitButton.click(); (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS)) .until(ExpectedConditions.presenceOfElementLocated(By.linkText("SIGN OUT"))); }
From source file:org.orcid.api.common.WebDriverHelper.java
License:Open Source License
public String obtainAuthorizationCodeWhenAlreadySignedIn(String scopes, String orcid) throws InterruptedException { webDriver.get(String.format("%s/oauth/authorize?client_id=%s&response_type=code&scope=%s&redirect_uri=%s", webBaseUrl, orcid, scopes, redirectUri)); By authorizeButtonLocator = ByName.name("authorize"); (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS)) .until(ExpectedConditions.presenceOfElementLocated(authorizeButtonLocator)); WebElement submitButton = webDriver.findElement(authorizeButtonLocator); submitButton.click();//from w w w . jav a2 s . co m (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS)).until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { return d.getTitle().equals("ORCID Playground"); } }); String currentUrl = webDriver.getCurrentUrl(); Matcher matcher = AUTHORIZATION_CODE_PATTERN.matcher(currentUrl); assertTrue(matcher.find()); String authorizationCode = matcher.group(1); assertNotNull(authorizationCode); return authorizationCode; }