List of usage examples for org.openqa.selenium.support.ui ExpectedConditions visibilityOf
public static ExpectedCondition<WebElement> visibilityOf(final WebElement element)
From source file:com.owncloud.android.test.ui.testSuites.UploadTestSuite.java
License:Open Source License
@Test @Category({ NoIgnoreTestCategory.class, SmokeTestCategory.class }) public void testUploadFile() throws Exception { FileListView fileListView = Actions.login(Config.URL, Config.user, Config.password, Config.isTrusted, driver);/*from ww w .java 2 s.c om*/ common.assertIsInFileListView(); //check if the file already exists and if true, delete it Actions.deleteElement(FILE_NAME, fileListView, driver); FileListView fileListViewAfterUploadFile = Actions.uploadFile(FILE_NAME, fileListView); fileListViewAfterUploadFile.scrollTillFindElement(FILE_NAME); assertTrue(fileListViewAfterUploadFile.getFileElement().isDisplayed()); Common.waitTillElementIsNotPresentWithoutTimeout(fileListViewAfterUploadFile.getProgressCircular(), 1000); common.wait.until(ExpectedConditions.visibilityOf(fileListViewAfterUploadFile.getFileElementLayout() .findElement(By.id(FileListView.getLocalFileIndicator())))); assertTrue(fileListViewAfterUploadFile.getFileElementLayout() .findElement(By.id(FileListView.getLocalFileIndicator())).isDisplayed()); fileListView = new FileListView(driver); fileListView.scrollTillFindElement(FILE_NAME); assertTrue(fileHasBeenUploaded = fileListView.getFileElement().isDisplayed()); }
From source file:com.owncloud.android.test.ui.testSuites.UploadTestSuite.java
License:Open Source License
@Test @Category({ UnfinishedTestCategory.class }) public void testUploadBigFile() throws Exception { FileListView fileListView = Actions.login(Config.URL, Config.user, Config.password, Config.isTrusted, driver);//from w w w . jav a2s . c o m common.assertIsInFileListView(); //check if the file already exists and if true, delete it Actions.deleteElement(BIG_FILE_NAME, fileListView, driver); FileListView fileListViewAfterUploadFile = Actions.uploadFile(BIG_FILE_NAME, fileListView); driver.openNotifications(); NotificationView notificationView = new NotificationView(driver); try { if (notificationView.getUploadingNotification().isDisplayed()) { Common.waitTillElementIsPresent(notificationView.getUploadSucceededNotification(), 300000); driver.sendKeyEvent(android.view.KeyEvent.KEYCODE_HOME); driver.startActivity("com.owncloud.android", ".ui.activity.FileDisplayActivity"); } } catch (NoSuchElementException e) { driver.sendKeyEvent(android.view.KeyEvent.KEYCODE_HOME); driver.startActivity("com.owncloud.android", ".ui.activity.FileDisplayActivity"); } fileListViewAfterUploadFile.scrollTillFindElement(BIG_FILE_NAME); assertTrue(fileListViewAfterUploadFile.getFileElement().isDisplayed()); Common.waitTillElementIsNotPresentWithoutTimeout(fileListViewAfterUploadFile.getProgressCircular(), 1000); common.wait.until(ExpectedConditions.visibilityOf(fileListViewAfterUploadFile.getFileElementLayout() .findElement(By.id(FileListView.getLocalFileIndicator())))); assertTrue(fileListViewAfterUploadFile.getFileElementLayout() .findElement(By.id(FileListView.getLocalFileIndicator())).isDisplayed()); fileListView = new FileListView(driver); fileListView.scrollTillFindElement(BIG_FILE_NAME); assertTrue(fileHasBeenUploaded = fileListView.getFileElement().isDisplayed()); }
From source file:com.pivotal.gemfire.tools.pulse.tests.PulseBaseTests.java
License:Open Source License
public void waitForElement(WebElement element) { driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); WebDriverWait wait = new WebDriverWait(driver, 20); wait.until(ExpectedConditions.visibilityOf(element)); }
From source file:com.seleniumtests.it.driver.TestDriver.java
License:Apache License
/** * issue #194: check that the WebDriverWait timeout is the one really applied *///from ww w. ja v a2 s . com @Test(groups = { "it", "ut" }) public void testWebDriverWaitWithLowTimeout() { long start = new Date().getTime(); try { new WebDriverWait(driver, 2) .until(ExpectedConditions.visibilityOf(new HtmlElement("", By.id("someNonExistentId")))); } catch (TimeoutException e) { } // we cannot check precise timing as it depends on the hardware, but we should never wait more that 10 secs (the default timeout for searching element is 30 secs) Assert.assertTrue(new Date().getTime() - start < 10000); }
From source file:com.seleniumtests.uipage.htmlelements.HtmlElement.java
License:Apache License
/** * Finds the element using By type. Implicit Waits is built in createWebDriver() in WebUIDriver to handle dynamic * element problem. This method is invoked before all the basic operations like click, sendKeys, getText, etc. Use * waitForPresent to use Explicit Waits to deal with special element which needs long time to present. * @param waitForVisibility wait for element to be visible * @param makeVisible whether we try to make the element visible. Should be true except when trying to know if element is displayed *//*from w w w . j a v a 2s .c o m*/ public void findElement(boolean waitForVisibility, boolean makeVisible) { // TODO: https://discuss.appium.io/t/how-can-i-scroll-to-an-element-in-appium-im-using-android-native-app/10618/14 // String DESTINATION_ELEMENT_TEXT= "KUBO"; //((AndroidDriver) driver).findElementByAndroidUIAutomator("new UiScrollable(new UiSelector()) // .scrollIntoView(new UiSelector().text(DESTINATION_ELEMENT_TEXT))"); ElementInfo elementInfo = null; // search element information. Do not stop if something goes wrong here if (SeleniumTestsContextManager.getThreadContext().getAdvancedElementSearch() != ElementInfo.Mode.FALSE) { try { elementInfo = ElementInfo.getInstance(this); } catch (Throwable e) { } } // if a parent is defined, search for it before getting the sub element driver = updateDriver(); if (parent != null) { parent.findElement(false, false); // issue #166: add a dot in front of xpath expression if we search the element inside a parent if (by instanceof ByXPath) { try { Field xpathExpressionField = ByXPath.class.getDeclaredField("xpathExpression"); xpathExpressionField.setAccessible(true); String xpath = (String) xpathExpressionField.get(by); if (xpath.startsWith("//")) { by = By.xpath("." + xpath); } } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { throw new CustomSeleniumTestsException(e); } } element = findSeleniumElement(parent.element, elementInfo); } else { element = findSeleniumElement(driver, elementInfo); } if (makeVisible) { makeWebElementVisible(element); ((CustomEventFiringWebDriver) driver).scrollToElement(element, -200); } // wait for element to be really visible. should be done only for actions on element if (waitForVisibility && makeVisible) { new WebDriverWait(driver, 1).until(ExpectedConditions.visibilityOf(element)); } // If we are here, element has been found, update elementInformation if (elementInfo != null) { try { elementInfo.updateInfo(this, driver); elementInfo.exportToJsonFile(this); } catch (Throwable e) { logger.warn("Error storing element information: " + e.getMessage()); } } }
From source file:com.seleniumtests.uipage.htmlelements.HtmlElement.java
License:Apache License
/** * Make element visible. Sometimes useful when real elements are backed by an image element */// w w w . ja v a 2 s .co m protected void makeWebElementVisible(WebElement element) { if (SeleniumTestsContextManager.isWebTest()) { if (element.isDisplayed()) { return; } try { if (element.getLocation().x < 0) { Long viewportHeight = (Long) ((JavascriptExecutor) driver) .executeScript("return document.documentElement.clientHeight"); Integer heightPosition = element.getLocation().y > viewportHeight ? element.getLocation().y - viewportHeight.intValue() : element.getLocation().y; changeCssAttribute(element, "left", "20px"); changeCssAttribute(element, "top", heightPosition + "px"); changeCssAttribute(element, "position", "inherit"); } if (element.getAttribute("style").toLowerCase().replace(" ", "").contains("display:none")) { changeCssAttribute(element, "display", "block"); } // changeCssAttribute(element, "clip", "auto"); changeCssAttribute(element, "zIndex", "100000"); } catch (Exception e) { return; } // wait for element to be displayed try { new WebDriverWait(driver, 1).until(ExpectedConditions.visibilityOf(element)); } catch (ElementNotVisibleException e) { TestLogging.info(String.format("element %s not visible", element)); } catch (Exception e) { logger.warn("Could not make element visible", e); } } }
From source file:com.sios.stc.coseng.test.User.java
License:Open Source License
@Test(description = "Verify bad credentials deny access past the login page", dataProvider = "credentials") // @Parameters({ "x,x", "y,y" }) // public void aInvalidLogin(final String username, final String password) public void invalidLogin(final String username, final String password) throws Exception { User.log.log(Level.INFO, logTestName() + " Username: " + username + " Password: " + password); driver.get(baseUrl + "/ui/#/login"); acceptSslCertificate(driver);/*from ww w . j a va2s .co m*/ final WebDriverWait wait = new WebDriverWait(driver, 10); final Actions actions = new Actions(driver); final WebElement weUsername = driver.findElement(By.name("userName")); final WebElement wePassword = driver.findElement(By.name("password")); final WebElement weSubmit = driver.findElement(By.className("login_submit_button")); wait.until(ExpectedConditions.visibilityOf(weUsername)); wait.until(ExpectedConditions.visibilityOf(wePassword)); wait.until(ExpectedConditions.visibilityOf(weSubmit)); saveScreenshot(driver, "aftervisible-" + username); actions.moveToElement(wePassword).click().sendKeys(wePassword, password).build().perform(); actions.moveToElement(weUsername).click().sendKeys(weUsername, username).build().perform(); actions.click(weSubmit).build().perform(); final WebElement weDialogBox = driver.findElement(By.className("dialog_box")); final WebElement weDialogBtnOk = driver.findElement(By.className("dialog_button")); wait.until(ExpectedConditions.visibilityOf(weDialogBox)); actions.click(weDialogBtnOk).build().perform(); }
From source file:com.sios.stc.coseng.test.User.java
License:Open Source License
@Test(description = "Verity initial login, change password.", dataProvider = "credentials") public void firstLogin(final String username, final String password, final String newPassword) throws Exception { User.log.log(Level.INFO,//from w w w.j av a 2 s . co m "Username: " + username + " Password: " + password + " NewPassword: " + newPassword); driver.get(baseUrl + "/ui/#/login"); final WebDriverWait wait = new WebDriverWait(driver, 10); final Actions actions = new Actions(driver); WebElement weUsername = driver.findElement(By.name("userName")); WebElement wePassword = driver.findElement(By.name("password")); WebElement weSubmit = driver.findElement(By.className("login_submit_button")); actions.moveToElement(weUsername).sendKeys(weUsername, username).moveToElement(wePassword) .sendKeys(wePassword, password).click(weSubmit).build().perform(); WebElement weNewPassword = driver.findElement(By.name("newpassword")); WebElement weRePassword = driver.findElement(By.name("repassword")); final WebElement weCancel = driver.findElement(By.linkText("Cancel")); wait.until(ExpectedConditions.visibilityOf(weNewPassword)); actions.moveToElement(weNewPassword).sendKeys(weNewPassword, newPassword).build().perform(); actions.moveToElement(weRePassword).sendKeys(weRePassword, newPassword).build().perform(); actions.click(weCancel).build().perform(); weUsername = driver.findElement(By.name("userName")); wePassword = driver.findElement(By.name("password")); weSubmit = driver.findElement(By.className("login_submit_button")); wait.until(ExpectedConditions.visibilityOf(weUsername)); actions.moveToElement(weUsername).sendKeys(weUsername, username).moveToElement(wePassword) .sendKeys(wePassword, password).click(weSubmit).build().perform(); weNewPassword = driver.findElement(By.name("newpassword")); weRePassword = driver.findElement(By.name("repassword")); final WebElement weOk = driver.findElement(By.linkText("OK")); wait.until(ExpectedConditions.visibilityOf(weNewPassword)); actions.moveToElement(weNewPassword).sendKeys(weNewPassword, newPassword).moveToElement(weRePassword) .sendKeys(weRePassword, newPassword).click(weOk).build().perform(); final WebElement weManageArea = driver.findElement(By.className("manage_area_2")); wait.until(ExpectedConditions.visibilityOf(weManageArea)); Assert.assertTrue(weManageArea.isDisplayed()); }
From source file:com.spambot.invisicow.SeleniumDriver.java
public void drive(int opt) throws InterruptedException { WebDriver driver = new FirefoxDriver(); driver.manage().window().maximize(); driver.get("http://findtheinvisiblecow.com"); WebElement body = driver.findElement(By.tagName("body")); new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOf(body)); //start game WebElement button = driver.findElement(By.xpath("//div[@id='loader']//button")); new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOf(button)); button.click();//from w ww .j a v a2 s.c o m for (int i = 0; i < opt - 1; i++) { //so the user sees something Thread.sleep(2500); //win game if (driver instanceof JavascriptExecutor) { ((JavascriptExecutor) driver).executeScript("find.gameStop(true);"); } //again? WebElement congrats = driver.findElement(By.id("modal-congratulations")); new WebDriverWait(driver, 5).until(ExpectedConditions.visibilityOf(congrats)); Thread.sleep(1500); WebElement again = driver.findElement(By.xpath("//div[@id='modal-congratulations']//button")); again.click(); } Thread.sleep(2500); //win game one last time if (driver instanceof JavascriptExecutor) { ((JavascriptExecutor) driver).executeScript("find.gameStop(true);"); } Thread.sleep(3000); JOptionPane.showMessageDialog(null, "Goodbye!"); driver.quit(); }
From source file:com.springer.omelet.common.ExpectedConditionExtended.java
License:Apache License
/*** * wait for the Element to be Disabled/*from ww w. j a v a 2 s . c om*/ * * @param element * @return */ public static ExpectedCondition<Boolean> elementToBeDisabled(final WebElement element) { return new ExpectedCondition<Boolean>() { public ExpectedCondition<WebElement> visibilityOfElement = ExpectedConditions.visibilityOf(element); public Boolean apply(WebDriver driver) { WebElement element = visibilityOfElement.apply(driver); try { if (element != null && !(element.isEnabled())) { return true; } else { return false; } } catch (StaleElementReferenceException e) { return false; } } @Override public String toString() { return "element to be clickable: " + element; } }; }