List of usage examples for org.openqa.selenium.support.ui ExpectedConditions visibilityOfElementLocated
public static ExpectedCondition<WebElement> visibilityOfElementLocated(final By locator)
From source file:ibw.updater.selenium.SeleniumTestCase.java
License:Open Source License
public WebElement waitAndSelectByValue(By by, String value) { WebDriverWait wait = new WebDriverWait(driver, MAX_WAIT_TIME); if (wait.until(ExpectedConditions.and(ExpectedConditions.visibilityOfElementLocated(by), ExpectedConditions.elementToBeClickable(by), webDriver -> isReady(webDriver)))) { WebElement elm = driver.findElement(by); new Select(elm).selectByValue(value); return elm; }// w w w . ja v a 2 s . c o m return null; }
From source file:ibw.updater.selenium.SeleniumTestCase.java
License:Open Source License
public WebElement waitAndSelectByIndex(By by, int index) { WebDriverWait wait = new WebDriverWait(driver, MAX_WAIT_TIME); if (wait.until(ExpectedConditions.and(ExpectedConditions.visibilityOfElementLocated(by), ExpectedConditions.elementToBeClickable(by), webDriver -> isReady(webDriver)))) { WebElement elm = driver.findElement(by); new Select(elm).selectByIndex(index); return elm; }/*from w ww . j a v a2s.c om*/ return null; }
From source file:ibw.updater.selenium.SeleniumTestCase.java
License:Open Source License
public WebElement waitForElement(By by) { WebDriverWait wait = new WebDriverWait(driver, MAX_WAIT_TIME); if (wait.until(ExpectedConditions.and(ExpectedConditions.visibilityOfElementLocated(by), webDriver -> isReady(webDriver)))) { WebElement elm = driver.findElement(by); return elm; }/*from w w w . jav a2 s .c o m*/ return null; }
From source file:io.atlasmap.standalone.E2ETest.java
License:Apache License
@Test public void testEmpty() throws IOException { driver.get("http://127.0.0.1:" + port); WebDriverWait waitForLoad = new WebDriverWait(driver, 5); waitForLoad.until(ExpectedConditions.visibilityOfElementLocated(By.id("Properties"))); WebElement container = driver.findElement(By.tagName("data-mapper-error")); List<WebElement> errors = container.findElements(By.className("alert-danger")); assertEquals("Some error message was found: " + container.getAttribute("innerHTML"), 0, errors.size()); }
From source file:io.pivotal.cla.webdriver.pages.BasePage.java
License:Apache License
protected void userMenu() { userMenu.click();// w w w . ja v a2s. c o m WebDriverWait wait = new WebDriverWait(driver, 5); wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(signout.getAttribute("id")))); }
From source file:io.pivotal.cla.webdriver.pages.BasePage.java
License:Apache License
protected void adminMenu() { adminMenu.click();//from w w w . j a va2 s . c o m WebDriverWait wait = new WebDriverWait(driver, 5); wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(link.getAttribute("id")))); }
From source file:io.selendroid.server.model.SelendroidStandaloneDriver.java
License:Apache License
public String createNewTestSession(JSONObject caps, Integer retries) throws AndroidSdkException, JSONException { SelendroidCapabilities desiredCapabilities = null; // Convert the JSON capabilities to SelendroidCapabilities try {//www .ja v a 2 s.c o m desiredCapabilities = new SelendroidCapabilities(caps); } catch (JSONException e) { throw new SelendroidException("Desired capabilities cannot be parsed."); } // Find the App being requested for use AndroidApp app = appsStore.get(desiredCapabilities.getAut()); if (app == null) { throw new SessionNotCreatedException( "The requested application under test is not configured in selendroid server."); } // adjust app based on capabilities (some parameters are session specific) app = augmentApp(app, desiredCapabilities); // Find a device to match the capabilities AndroidDevice device = null; try { device = getAndroidDevice(desiredCapabilities); } catch (AndroidDeviceException e) { SessionNotCreatedException error = new SessionNotCreatedException( "Error occured while finding android device: " + e.getMessage()); e.printStackTrace(); log.severe(error.getMessage()); throw error; } // If we are using an emulator need to start it up if (device instanceof AndroidEmulator) { AndroidEmulator emulator = (AndroidEmulator) device; try { if (emulator.isEmulatorStarted()) { emulator.unlockEmulatorScreen(); } else { Map<String, Object> config = new HashMap<String, Object>(); if (serverConfiguration.getEmulatorOptions() != null) { config.put(AndroidEmulator.EMULATOR_OPTIONS, serverConfiguration.getEmulatorOptions()); } config.put(AndroidEmulator.TIMEOUT_OPTION, serverConfiguration.getTimeoutEmulatorStart()); if (desiredCapabilities.asMap().containsKey(SelendroidCapabilities.DISPLAY)) { Object d = desiredCapabilities.getCapability(SelendroidCapabilities.DISPLAY); config.put(AndroidEmulator.DISPLAY_OPTION, String.valueOf(d)); } Locale locale = parseLocale(desiredCapabilities); emulator.start(locale, deviceStore.nextEmulatorPort(), config); } } catch (AndroidDeviceException e) { deviceStore.release(device, app); if (retries > 0) { return createNewTestSession(caps, retries - 1); } throw new SessionNotCreatedException( "Error occured while interacting with the emulator: " + emulator + ": " + e.getMessage()); } emulator.setIDevice(deviceManager.getVirtualDevice(emulator.getAvdName())); } boolean appInstalledOnDevice = device.isInstalled(app); if (!appInstalledOnDevice || serverConfiguration.isForceReinstall()) { device.install(app); } else { log.info("the app under test is already installed."); } int port = getNextSelendroidServerPort(); Boolean selendroidInstalledSuccessfully = device.isInstalled("io.selendroid." + app.getBasePackage()); if (!selendroidInstalledSuccessfully || serverConfiguration.isForceReinstall()) { AndroidApp selendroidServer = createSelendroidServerApk(app); selendroidInstalledSuccessfully = device.install(selendroidServer); if (!selendroidInstalledSuccessfully) { if (!device.install(selendroidServer)) { deviceStore.release(device, app); if (retries > 0) { return createNewTestSession(caps, retries - 1); } } } } else { log.info( "selendroid-server will not be created and installed because it already exists for the app under test."); } // Run any adb commands requested in the capabilities List<String> adbCommands = new ArrayList<String>(); adbCommands.add("shell setprop log.tag.SELENDROID " + serverConfiguration.getLogLevel().name()); adbCommands.addAll(desiredCapabilities.getPreSessionAdbCommands()); for (String adbCommandParameter : adbCommands) { device.runAdbCommand(adbCommandParameter); } // It's GO TIME! // start the selendroid server on the device and make sure it's up try { device.startSelendroid(app, port); } catch (AndroidSdkException e) { log.info("error while starting selendroid: " + e.getMessage()); deviceStore.release(device, app); if (retries > 0) { return createNewTestSession(caps, retries - 1); } throw new SessionNotCreatedException( "Error occurred while starting instrumentation: " + e.getMessage()); } long start = System.currentTimeMillis(); long startTimeOut = 20000; long timemoutEnd = start + startTimeOut; while (device.isSelendroidRunning() == false) { if (timemoutEnd >= System.currentTimeMillis()) { try { Thread.sleep(2000); } catch (InterruptedException e) { } } else { throw new SelendroidException( "Selendroid server on the device didn't came up after " + startTimeOut / 1000 + "sec:"); } } // arbitrary sleeps? yay... // looks like after the server starts responding // we need to give it a moment before starting a session? try { Thread.sleep(500); } catch (InterruptedException e1) { e1.printStackTrace(); } // create the new session on the device server RemoteWebDriver driver; try { driver = new RemoteWebDriver(new URL("http://localhost:" + port + "/wd/hub"), desiredCapabilities); } catch (Exception e) { e.printStackTrace(); deviceStore.release(device, app); throw new SessionNotCreatedException("Error occurred while creating session on Android device", e); } String sessionId = driver.getSessionId().toString(); SelendroidCapabilities requiredCapabilities = new SelendroidCapabilities(driver.getCapabilities().asMap()); ActiveSession session = new ActiveSession(sessionId, requiredCapabilities, app, device, port, this); this.sessions.put(sessionId, session); // We are requesting an "AndroidDriver" so automatically switch to the webview if (BrowserType.ANDROID.equals(desiredCapabilities.getAut())) { // arbitrarily high wait time, will this cover our slowest possible device/emulator? WebDriverWait wait = new WebDriverWait(driver, 60); // wait for the WebView to appear wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("android.webkit.WebView"))); driver.switchTo().window("WEBVIEW"); // the 'android-driver' webview has an h1 with id 'AndroidDriver' embedded in it wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("AndroidDriver"))); } return sessionId; }
From source file:io.selendroid.standalone.server.model.SelendroidStandaloneDriver.java
License:Apache License
private void switchToWebView(RemoteWebDriver driver) { // arbitrarily high wait time, will this cover our slowest possible device/emulator? WebDriverWait wait = new WebDriverWait(driver, 60); // wait for the WebView to appear wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("android.webkit.WebView"))); driver.switchTo().window("WEBVIEW"); // the 'android-driver' webview has an h1 with id 'AndroidDriver' embedded in it wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("AndroidDriver"))); }
From source file:io.wcm.qa.galenium.util.InteractionUtil.java
License:Apache License
/** * @param driver driver//w w w .j av a 2s. co m * @param selector used to find element * @param howLong how long to wait for element to be visible in seconds * @return matching element if it is visible or null */ public static WebElement getElementVisible(WebDriver driver, Selector selector, int howLong) { WebDriverWait wait = new WebDriverWait(driver, howLong); try { return wait.until(ExpectedConditions.visibilityOfElementLocated(selector.asBy())); } catch (TimeoutException tex) { return null; } }
From source file:IWDmainsiteProject.PageObjects.Verify_Pages.java
public static void Verify_Extension_Support_Contact_us_form(WebDriver driver) throws InterruptedException { WebDriverWait wait1 = new WebDriverWait(driver, 10); wait1.until(ExpectedConditions.visibilityOfElementLocated(By .cssSelector("iframe[src='https://joe568.typeform.com/to/ecFKHU?typeform-embed=popup-classic']"))); driver.switchTo().frame(driver.findElement(By .cssSelector("iframe[src='https://joe568.typeform.com/to/ecFKHU?typeform-embed=popup-classic']"))); driver.findElement(//from w w w. j a va2 s. c o m By.cssSelector("div[class='content'] div[class='button general full enabled hover-effect']")) .click(); driver.findElement(By.id("45706099")).click(); driver.findElement(By.cssSelector("li[id='36032111'] input[type='text']")).click(); driver.findElement(By.cssSelector("li[id='36032111'] input[type='text']")).sendKeys("test"); driver.findElement(By.cssSelector("li[id='36032111'] span[class='confirm']")).click(); driver.findElement(By.cssSelector("li[id='36032182'] input[type='text']")).click(); driver.findElement(By.cssSelector("li[id='36032182'] input[type='text']")).sendKeys("1222333444555"); driver.findElement(By.cssSelector("li[id='36032182'] span[class='confirm']")).click(); driver.findElement(By.cssSelector("li[id='36032179'] input[type='text']")).click(); driver.findElement(By.cssSelector("li[id='36032179'] input[type='text']")).sendKeys("testiwd@gmail.com"); driver.findElement(By.cssSelector("li[id='36032179'] span[class='confirm']")).click(); driver.findElement(By.cssSelector("li[id='36032232'] .textarea-wrapper>textarea")).click(); driver.findElement(By.cssSelector("li[id='36032232'] .textarea-wrapper>textarea")).sendKeys("IWD-test"); driver.findElement(By.cssSelector("li[id='36032232'] span[class='confirm']")).click(); driver.findElement(By.cssSelector("li[id='36033432'] .textarea-wrapper>textarea")).click(); driver.findElement(By.cssSelector("li[id='36033432'] .textarea-wrapper>textarea")) .sendKeys("IWD-test-comment"); driver.findElement(By.cssSelector("li[id='36033432'] span[class='confirm']")).click(); driver.findElement(By.cssSelector( "div[class='button-wrapper submit'] div[class='button general hover-effect enabled']")); System.out.println("Submit button was found"); driver.switchTo().defaultContent(); driver.findElement(By.cssSelector(".typeform-wrapper.show.drawer>img")).click(); System.out.println("Test Contact us form passed"); }