org.openqa.selenium.support.ui.WebDriverWait Java Examples
The following examples show how to use
org.openqa.selenium.support.ui.WebDriverWait.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Browser.java From kurento-java with Apache License 2.0 | 7 votes |
public Object executeScriptAndWaitOutput(final String command) { WebDriverWait wait = new WebDriverWait(driver, timeout); wait.withMessage("Timeout executing script: " + command); final Object[] out = new Object[1]; wait.until(new ExpectedCondition<Boolean>() { @Override public Boolean apply(WebDriver d) { try { out[0] = executeScript(command); } catch (WebDriverException we) { log.warn("Exception executing script", we); out[0] = null; } return out[0] != null; } }); return out[0]; }
Example #2
Source File: AssertElementHasClass.java From opentest with MIT License | 6 votes |
@Override public void run() { super.run(); By locator = this.readLocatorArgument("locator"); String className = this.readStringArgument("class"); this.waitForAsyncCallsToFinish(); WebElement element = this.getElement(locator); try { WebDriverWait wait = new WebDriverWait(this.driver, this.getExplicitWaitSec()); wait.until(CustomConditions.elementToHaveClass(element, className)); } catch (Exception ex) { throw new RuntimeException(String.format( "Failed to find class \"%s\" on element. The value of the element's class attribute was \"%s\"", className, element.getAttribute("class")), ex); } }
Example #3
Source File: Edition080_iOS_FaceId.java From appiumpro with Apache License 2.0 | 6 votes |
@Test public void testIOSFaceId() { driver.executeScript("mobile:enrollBiometric", ImmutableMap.of("isEnabled", true)); WebElement loginButton = driver.findElementByAccessibilityId("Log In"); loginButton.click(); driver.switchTo().alert().accept(); driver.executeScript("mobile:sendBiometricMatch", ImmutableMap.of("type", "faceId", "match", true)); WebDriverWait wait = new WebDriverWait(driver, 5); wait.until(ExpectedConditions.presenceOfElementLocated(By.name("Log Out"))); WebElement logoutButton = driver.findElementByAccessibilityId("Log Out"); logoutButton.click(); wait.until(ExpectedConditions.presenceOfElementLocated(By.name("Log In"))); loginButton = driver.findElementByAccessibilityId("Log In"); loginButton.click(); driver.executeScript("mobile:sendBiometricMatch", ImmutableMap.of("type", "faceId", "match", false)); wait.until(ExpectedConditions.alertIsPresent()); driver.switchTo().alert().dismiss(); }
Example #4
Source File: AbstractSeleniumTest.java From archiva with Apache License 2.0 | 6 votes |
public WebElement selectValue( String locator, String value, boolean scrollToView ) { int count = 5; boolean check = true; WebDriverWait wait = new WebDriverWait( getWebDriver( ), 10 ); WebElement element = null; while(check && count-->0) { try { element = findElement( locator ); List<WebElement> elementList = new ArrayList<>( ); elementList.add( element ); wait.until( ExpectedConditions.visibilityOfAllElements( elementList ) ); check=false; } catch (Throwable e) { logger.info("Waiting for select element {} to be visible", locator); } } Select select = new Select(element); select.selectByValue( value ); return element; }
Example #5
Source File: AutoSuggestBehavior.java From adf-selenium with Apache License 2.0 | 6 votes |
public void typeAndWait(String value) { component.clear(); component.sendKeys(Keys.BACK_SPACE, value); final AdfComponent comp = component; new WebDriverWait(component.getDriver(), 10, 100).until(new Predicate<WebDriver>() { @Override public boolean apply(WebDriver webDriver) { if (isPopupVisible()) { comp.waitForPpr(); return true; } else { return false; } } }); }
Example #6
Source File: NativeAppDriver.java From edx-app-android with Apache License 2.0 | 6 votes |
/** * Wait till the element is displayed and swipe till the particular time * slot * * @param id * - id of the element */ public void swipe(String id) { try { if (isAndroid()) { new WebDriverWait(appiumDriver, 20).until(ExpectedConditions .presenceOfElementLocated(By.id(id))); Dimension dimension = appiumDriver.manage().window().getSize(); int ht = dimension.height; int width = dimension.width; appiumDriver.swipe((width / 2), (ht / 4), (width / 2), (ht / 2), 1000); } else { new WebDriverWait(appiumDriver, 20).until(ExpectedConditions .presenceOfElementLocated(By.id(id))); if (deviceName.equalsIgnoreCase("iphone 5")) { appiumDriver.swipe((int) 0.1, 557, 211, 206, 500); } else if (deviceName.equalsIgnoreCase("iphone 6")) { appiumDriver.swipe((int) 0.1, 660, 50, 50, 500); } } } catch (Throwable e) { Reporter.log("Element by Id " + id + " not visible"); captureScreenshot(); throw e; } }
Example #7
Source File: CommandsExplorer.java From che with Eclipse Public License 2.0 | 6 votes |
public void deleteCommandByName(String commandName) { selectCommandByName(commandName); loader.waitOnClosed(); new WebDriverWait(seleniumWebDriver, LOAD_PAGE_TIMEOUT_SEC) .until( ExpectedConditions.visibilityOfElementLocated( By.xpath("//div[@id='command_" + commandName + "']"))) .click(); new WebDriverWait(seleniumWebDriver, LOAD_PAGE_TIMEOUT_SEC) .until( ExpectedConditions.visibilityOfElementLocated( By.xpath( "//div[@id='command_" + commandName + "']//span[@id='commands_tree-button-remove']"))) .click(); askDialog.waitFormToOpen(); askDialog.confirmAndWaitClosed(); }
Example #8
Source File: ImplicitWaitTest.java From selenium with Apache License 2.0 | 6 votes |
@Test @NotYetImplemented(SAFARI) public void testShouldRetainImplicitlyWaitFromTheReturnedWebDriverOfFrameSwitchTo() { driver.manage().timeouts().implicitlyWait(1, SECONDS); driver.get(pages.xhtmlTestPage); driver.findElement(By.name("windowOne")).click(); Wait<WebDriver> wait = new WebDriverWait(driver, Duration.ofSeconds(1)); wait.until(ExpectedConditions.numberOfWindowsToBe(2)); String handle = (String)driver.getWindowHandles().toArray()[1]; WebDriver newWindow = driver.switchTo().window(handle); long start = System.currentTimeMillis(); newWindow.findElements(By.id("this-crazy-thing-does-not-exist")); long end = System.currentTimeMillis(); long time = end - start; assertThat(time).isGreaterThanOrEqualTo(1000); }
Example #9
Source File: JTreeDynamicTreeTest.java From marathonv5 with Apache License 2.0 | 6 votes |
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()); }
Example #10
Source File: MBeanFieldGroupRequiredErrorMessageTest.java From viritin with Apache License 2.0 | 6 votes |
@Test @Ignore("See if can be run with phantomjs and/or update to geckodriver") public void testErrorMessageForNonNullAnnotatedComponent() throws InterruptedException { driver.navigate().to( "http://localhost:5678/" + MBeanFieldGroupRequiredErrorMessage.class.getCanonicalName()); new WebDriverWait(driver, 30).until(VaadinConditions::ajaxCallsCompleted); WebElement txtField = driver.findElement(By.id("txtStreet")); Actions toolAct = new Actions(driver); toolAct.moveToElement(txtField).build().perform(); Thread.sleep(1000); WebElement toolTipElement = driver.findElement(By.cssSelector(".v-app.v-overlay-container > .v-tooltip > .popupContent .v-errormessage > div > div")); assertThat(toolTipElement.getText(), is(expectedMessage)); }
Example #11
Source File: CheTerminal.java From che with Eclipse Public License 2.0 | 6 votes |
/** * scroll terminal by pressing key 'End' * * @param item is the name of the highlighted item */ public void moveDownListTerminal(String item) { loader.waitOnClosed(); typeIntoActiveTerminal(Keys.END.toString()); WaitUtils.sleepQuietly(2); WebElement element = seleniumWebDriver.findElement( By.xpath(format("(//span[contains(text(), '%s')])[position()=1]", item))); if (!element.getCssValue("background-color").equals(LINE_HIGHLIGHTED_GREEN)) { typeIntoActiveTerminal(Keys.ARROW_UP.toString()); element = seleniumWebDriver.findElement( By.xpath(format("(//span[contains(text(), '%s')])[position()=1]", item))); WaitUtils.sleepQuietly(2); } new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC) .until(visibilityOf(element)); WebElement finalElement = element; new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC) .until( (WebDriver input) -> finalElement.getCssValue("background-color").equals(LINE_HIGHLIGHTED_GREEN)); }
Example #12
Source File: FindText.java From che with Eclipse Public License 2.0 | 5 votes |
/** wait the 'Search' button is disabled on the main form */ public void waitSearchBtnMainFormIsDisabled() { new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC) .until( ExpectedConditions.not( ExpectedConditions.elementToBeClickable(By.id(Locators.SEARCH_BUTTON)))); }
Example #13
Source File: VaadinLocaleTest.java From viritin with Apache License 2.0 | 5 votes |
@Test @Ignore("See if can be run with phantomjs and/or update to geckodriver") public void testLanguageByBrowser() { driver.navigate().to( "http://localhost:5678/" + VaadinLocaleDemo.class.getCanonicalName()); new WebDriverWait(driver, 30).until(VaadinConditions::ajaxCallsCompleted); VaadinComboBox languageSelectionBox = new VaadinComboBox( driver.findElement(By.id("language-selection"))); assertThat(languageSelectionBox.getValue(), is(expectedLanguage)); }
Example #14
Source File: Edition046_W3C_Keys.java From appiumpro with Apache License 2.0 | 5 votes |
@Before public void setUp() throws IOException { DesiredCapabilities caps = new DesiredCapabilities(); caps.setCapability("platformName", "Android"); caps.setCapability("deviceName", "Android Emulator"); caps.setCapability("automationName", "UiAutomator2"); caps.setCapability("app", APP); driver = new AppiumDriver(new URL("http://localhost:4723/wd/hub"), caps); wait = new WebDriverWait(driver, 10); }
Example #15
Source File: GitCommit.java From che with Eclipse Public License 2.0 | 5 votes |
/** * Wait for item check-box in the 'Git changed files tree panel' to be indeterminate. * * @param itemName name of the item */ public void waitItemCheckBoxToBeIndeterminate(String itemName) { new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC) .until( (ExpectedCondition<Boolean>) webDriver -> seleniumWebDriver .findElement( By.xpath( String.format(Locators.TREE_ITEM_CHECK_BOX + "//input", itemName))) .getAttribute("id") .endsWith("indeterminate")); }
Example #16
Source File: WebPage.java From kurento-java with Apache License 2.0 | 5 votes |
public void syncTimeForOcr(String videoTagId, String peerConnectionId) { browser.executeScript( "kurentoTest.syncTimeForOcr('" + videoTagId + "', '" + peerConnectionId + "');"); log.debug("Sync time in {} {}", browser.getId(), videoTagId); WebDriverWait wait = new WebDriverWait(browser.getWebDriver(), browser.getTimeout()); wait.until(new ExpectedCondition<Boolean>() { @Override public Boolean apply(WebDriver d) { return (Boolean) ((JavascriptExecutor) d).executeScript("return kurentoTest.sync;"); } }); log.debug("[Done] Sync time in {} {}", browser.getId(), videoTagId); }
Example #17
Source File: ConfigureClasspath.java From che with Eclipse Public License 2.0 | 5 votes |
/** close the 'Configure Classpath' form by click on the close icon */ public void closeConfigureClasspathFormByIcon() { new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC) .until( ExpectedConditions.visibilityOfElementLocated(By.xpath(CONFIGURE_CLASSPATH_CLOSE_ICON))) .click(); waitConfigureClasspathFormIsClosed(); }
Example #18
Source File: NativeAppDriver.java From edx-app-android with Apache License 2.0 | 5 votes |
/** * Verifies element is visible * * @param id */ public void verifyVisibilityOfElementLocatedById(String id) { try { WebDriverWait wait = (WebDriverWait) new WebDriverWait( appiumDriver, maxWaitTime, 500); wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(id))); } catch (Throwable t) { Reporter.log("Elment by Id " + id + " not visible"); captureScreenshot(); throw t; } }
Example #19
Source File: CheTerminal.java From che with Eclipse Public License 2.0 | 5 votes |
/** * scroll terminal by pressing key 'PageDown' * * @param item is the name of the highlighted item */ public void movePageDownListTerminal(String item) { loader.waitOnClosed(); typeIntoActiveTerminal(Keys.PAGE_DOWN.toString()); WaitUtils.sleepQuietly(2); WebElement element = seleniumWebDriver.findElement( By.xpath(format("(//span[contains(text(), '%s')])[position()=1]", item))); new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC) .until(visibilityOf(element)); new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC) .until( (WebDriver input) -> element.getCssValue("background-color").equals(LINE_HIGHLIGHTED_GREEN)); }
Example #20
Source File: FindHasLoggedIn.java From find with MIT License | 5 votes |
@Override public boolean hasLoggedIn() { try { new WebDriverWait(driver, 30) .withMessage("logging in to Find") .until(ExpectedConditions.visibilityOfElementLocated(By.className("find-pages-container"))); return true; } catch (final Exception e) { if (signedInTextVisible()) { throw new SSOFailureException(); } } return false; }
Example #21
Source File: Edition064_Android_Toast.java From appiumpro with Apache License 2.0 | 5 votes |
@Test public void testToast() { WebDriverWait wait = new WebDriverWait(driver, 10); final String toastText = "Catch me if you can!"; raiseToast(toastText); wait.until(toastMatches(toastText, false)); raiseToast(toastText); wait.until(toastMatches("^Catch.+!", true)); }
Example #22
Source File: GitPush.java From che with Eclipse Public License 2.0 | 5 votes |
/** Set checked 'force push' check-box. */ public void selectForcePushCheckBox() { forcePush.click(); new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC) .until( ExpectedConditions.elementToBeSelected(By.id(Locators.FORCE_PUSH_CHECKBOX + "-input"))); }
Example #23
Source File: ITCreateMultipleBuckets.java From nifi-registry with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { WebDriverManager.chromedriver().setup(); driver = new ChromeDriver(); baseUrl = "http://localhost:18080/nifi-registry"; wait = new WebDriverWait(driver, 30); }
Example #24
Source File: WaitStepDefinitions.java From IridiumApplicationTesting with MIT License | 5 votes |
/** * Waits the given amount of time for an element with the supplied attribute and attribute value to be displayed * (i.e. to be visible) on the page. * * @param waitDuration The maximum amount of time to wait for * @param attribute The attribute to use to select the element with * @param alias If this word is found in the step, it means the selectorValue is found from the * data set. * @param selectorValue The value used in conjunction with the selector to match the element. If alias * was set, this value is found from the data set. Otherwise it is a literal value. * @param ignoringTimeout Include this text to ignore a timeout while waiting for the element to be present */ @When("^I wait \"(\\d+)\" seconds for (?:a|an|the) element with (?:a|an|the) attribute of \"([^\"]*)\" " + "equal to( alias)? \"([^\"]*)\" to be present(,? ignoring timeouts?)?") public void presentAttrWait( final String waitDuration, final String attribute, final String alias, final String selectorValue, final String ignoringTimeout) { final String attributeValue = autoAliasUtils.getValue( selectorValue, StringUtils.isNotBlank(alias), State.getFeatureStateForThread()); try { final WebDriver webDriver = State.getThreadDesiredCapabilityMap().getWebDriverForThread(); final WebDriverWait wait = new WebDriverWait( webDriver, Integer.parseInt(waitDuration), Constants.ELEMENT_WAIT_SLEEP_TIMEOUT); wait.until(ExpectedConditions.presenceOfElementLocated( By.cssSelector("[" + attribute + "='" + attributeValue + "']"))); } catch (final TimeoutException ex) { /* Rethrow if we have not ignored errors */ if (StringUtils.isBlank(ignoringTimeout)) { throw ex; } } }
Example #25
Source File: PageObject.java From testing_security_development_enterprise_systems with GNU Lesser General Public License v3.0 | 5 votes |
protected Boolean waitForPageToLoad() { JavascriptExecutor jsExecutor = (JavascriptExecutor) driver; WebDriverWait wait = new WebDriverWait(driver, 10); //give up after 10 seconds //keep executing the given JS till it returns "true", when page is fully loaded and ready return wait.until((ExpectedCondition<Boolean>) input -> { String res = jsExecutor.executeScript("return /loaded|complete/.test(document.readyState);").toString(); return Boolean.parseBoolean(res); }); }
Example #26
Source File: JwalaUi.java From jwala with Apache License 2.0 | 5 votes |
@Deprecated public WebElement clickTreeItemExpandCollapseIcon(final String itemLabel) { final WebElement webElement = driver.findElement(By.xpath("//li[span[text()='" + itemLabel + "']]/img[contains(@class, 'expand-collapse-padding')]")); new WebDriverWait(driver, 5).until(ExpectedConditions.visibilityOf(webElement)); webElement.click(); return webElement; }
Example #27
Source File: WorkspaceProjects.java From che with Eclipse Public License 2.0 | 5 votes |
/** * wait the project is present in the 'All projects' tab * * @param projectName name of project */ public void waitProjectIsPresent(String projectName) { new WebDriverWait(seleniumWebDriver, ELEMENT_TIMEOUT_SEC) .until( visibilityOfElementLocated( By.xpath(String.format(Locators.PROJECT_BY_NAME, projectName)))); }
Example #28
Source File: ValidationStepDefinitions.java From IridiumApplicationTesting with MIT License | 5 votes |
/** * Verifies that the element is not displayed (i.e. to be visible) on the page within a given amount of time. * You can use this step to verify that the page is in the correct state before proceeding with the script. * * @param waitDuration The maximum amount of time to wait for * @param selector Either ID, class, xpath, name or css selector * @param alias If this word is found in the step, it means the selectorValue is found from the * data set. * @param selectorValue The value used in conjunction with the selector to match the element. If alias * was set, this value is found from the data set. Otherwise it is a literal * value. * @param ignoringTimeout include this text to continue the script in the event that the element can't be * found */ @Then("^(?:I verify(?: that)? )?(?:a|an|the) element with " + "(?:a|an|the) (ID|class|xpath|name|css selector)( alias)? of \"([^\"]*)\" is not displayed" + "(?: within \"(\\d+)\" seconds?)(,? ignoring timeouts?)?") public void notDisplayWaitStep( final String selector, final String alias, final String selectorValue, final String waitDuration, final String ignoringTimeout) { final WebDriver webDriver = State.getThreadDesiredCapabilityMap().getWebDriverForThread(); final By by = getBy.getBy(selector, StringUtils.isNotBlank(alias), selectorValue, State.getFeatureStateForThread()); final WebDriverWait wait = new WebDriverWait( webDriver, NumberUtils.toLong(waitDuration, State.getFeatureStateForThread().getDefaultWait()), Constants.ELEMENT_WAIT_SLEEP_TIMEOUT); try { final boolean result = wait.until( ExpectedConditions.not(ExpectedConditions.visibilityOfAllElementsLocatedBy(by))); if (!result) { throw new TimeoutException( "Gave up after waiting " + Integer.parseInt(waitDuration) + " seconds for the element to not be displayed"); } } catch (final TimeoutException ex) { /* Rethrow if we have not ignored errors */ if (StringUtils.isBlank(ignoringTimeout)) { throw ex; } } }
Example #29
Source File: CommandsPalette.java From che with Eclipse Public License 2.0 | 5 votes |
@Inject public CommandsPalette( SeleniumWebDriver seleniumWebDriver, Loader loader, ActionsFactory actionsFactory) { this.seleniumWebDriver = seleniumWebDriver; this.loader = loader; this.actionsFactory = actionsFactory; this.redrawUiElementTimeout = new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC); this.actions = new Actions(seleniumWebDriver); PageFactory.initElements(seleniumWebDriver, this); }
Example #30
Source File: JwalaUi.java From jwala with Apache License 2.0 | 5 votes |
public void testForBusyIcon(final int showTimeout, final int hideTimeout) { new FluentWait(driver).withTimeout(showTimeout, TimeUnit.SECONDS).pollingEvery(100, TimeUnit.MILLISECONDS) .until(ExpectedConditions.numberOfElementsToBe( By.xpath("//div[contains(@class, 'AppBusyScreen') and contains(@class, 'show')]"), 1)); // Please take note that when "display none" is re-inserted, the whitespace in between the attribute and the value is not there anymore e.g. // display: none => display:none hence the xpath => contains(@style,'display:none') new WebDriverWait(driver, hideTimeout) .until(ExpectedConditions.numberOfElementsToBe( By.xpath("//div[contains(@class, 'AppBusyScreen') and contains(@class, 'show')]"), 0)); }