List of usage examples for org.openqa.selenium.support.ui WebDriverWait WebDriverWait
public WebDriverWait(WebDriver driver, Duration timeout)
From source file:TestWriteanArticle.java
@org.junit.Test public void negative() throws InterruptedException { System.setProperty("webdriver.gecko.driver", "C://Users/Mari/Downloads/geckodriver.exe"); WebDriver webDriver = new FirefoxDriver(); String page = "http://www.wikihow.com/Special:CreatePage"; webDriver.get(page);//ww w .j a va 2s . c o m WebElement title = webDriver.findElement(By.id("cp_title_input")); title.sendKeys("how to use wikiHow"); webDriver.findElement(By.id("cp_title_btn")).click(); Thread.sleep(10); WebDriverWait wait = new WebDriverWait(webDriver, 50); wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("cpr_title_hdr"))); assertTrue(webDriver.getPageSource().contains("That article already exists!")); webDriver.close(); }
From source file:NewSeleneseIT.java
@Test public void testSimple() throws Exception { // Create a new instance of the Firefox driver // Notice that the remainder of the code relies on the interface, // not the implementation. System.setProperty("webdriver.gecko.driver", "/home/klaudia/geckodriver"); WebDriver driver = new FirefoxDriver(); // And now use this to visit NetBeans driver.get("http://www.netbeans.org"); // Alternatively the same thing can be done like this // driver.navigate().to("http://www.netbeans.org"); // Check the title of the page // Wait for the page to load, timeout after 10 seconds (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() { @Override//from w w w. j av a 2s . c o m public Boolean apply(WebDriver d) { return d.getTitle().contains("NetBeans"); } }); //Close the browser driver.quit(); }
From source file:LoginWHTest.java
@Before public void setup() throws MalformedURLException, UnknownHostException { ProfilesIni allProfiles = new ProfilesIni(); FirefoxProfile myProfile = allProfiles.getProfile("SimBin"); myProfile.setAcceptUntrustedCertificates(true); myProfile.setAssumeUntrustedCertificateIssuer(false); driver2 = new FirefoxDriver(myProfile); WebDriverWait wait = new WebDriverWait(driver2, 15); driver2.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); driver2.navigate().to(urlWHGames);/*from w ww . ja va 2s . c o m*/ driver2.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); }
From source file:LoginWHTest.java
@Test public void testAuthenticationFailureWhenProvidingBadCredentials() { WebDriverWait wait;/*w w w . j ava 2 s. co m*/ WebElement username; // Click on 'Login' button driver2.findElement( By.xpath("html/body/div[2]/div/div/div[2]/wf-header/header/div/div[2]/wf-user-button/div/a/span")) .click(); // Enter UserName driver2.findElement(By.xpath("//*[@id='loginForm']/div[1]/input")).click(); driver2.findElement(By.xpath("//*[@id='loginForm']/div[1]/input")).sendKeys(""); driver2.findElement(By.xpath("//*[@id='loginForm']/div[1]/input")).sendKeys("simeonbin"); wait = new WebDriverWait(driver2, 60); wait.until(ExpectedConditions.textToBePresentInElementValue(By.xpath("//*[@id='loginForm']/div[1]/input"), "simeonbin")); // Enter Password driver2.findElement(By.xpath("//*[@id='loginForm']/div[4]/input")).sendKeys(""); driver2.findElement(By.xpath("//*[@id='loginForm']/div[4]/input")).sendKeys("password"); wait = new WebDriverWait(driver2, 60); wait.until(ExpectedConditions.textToBePresentInElementValue(By.xpath("//*[@id='loginForm']/div[4]/input"), "password")); // Click on 'Login' button WebElement login = driver2.findElement(By.xpath("//*[@id='loginForm']/button")); wait = new WebDriverWait(driver2, 15); login.click(); wait = new WebDriverWait(driver2, 15); String errorMsg = driver2.findElement(By.xpath(" //*[@id='loginForm']/div[7]")).getText(); System.out.println(errorMsg); assertTrue(errorMsg.startsWith("Sorry")); driver2.close(); }
From source file:ChosenIT.java
License:Apache License
/** * This test asserts that a {@link com.arcbees.chosen.client.gwt.ChosenValueListBox} can be enabled/disabled * successfully./*from w w w . j a va2 s.c o m*/ */ @Test public void enabledDisabled() { // Given loadTestCase(new EnabledDisabled()); String disabledClassName = "com-arcbees-chosen-client-resources-ChosenCss-chzn-disabled"; // When WebElement disableButton = webDriverWait() .until(presenceOfElementLocated(ByDebugId.id(EnabledDisabled.DISABLE_DEBUG_ID))); disableButton.click(); // Then webDriverWait().until(presenceOfElementLocated(By.className(disabledClassName))); // When WebElement enableButton = webDriverWait() .until(presenceOfElementLocated(ByDebugId.id(EnabledDisabled.ENABLE_DEBUG_ID))); enableButton.click(); // Then try { int quickTimeout = 1; // we don't want this test to wait for too long new WebDriverWait(webDriver, quickTimeout) .until(presenceOfElementLocated(By.className(disabledClassName))); fail("The ChosenValueListBox shouldn't be enabled at this point"); } catch (TimeoutException e) { // success, element should be absent from DOM } }
From source file:ChosenIT.java
License:Apache License
protected WebDriverWait webDriverWait() { return new WebDriverWait(webDriver, TIME_OUT_IN_SECONDS); }
From source file:TestWithSelenium.java
@Test public void tDomConstructedTableReady() { //searching for tbody WebElement table = (new WebDriverWait(driver, MAX)).until((ExpectedCondition<WebElement>) (WebDriver d) -> { return d.findElement(By.tagName("tbody")); });/*from ww w .ja v a 2 s .c om*/ Assert.assertThat(table.findElements(By.tagName("tr")).size(), is(5)); }
From source file:TestWithSelenium.java
@Test public void uTest2002Filter() { //searching for filter & sending key WebElement filter = (new WebDriverWait(driver, MAX)) .until((ExpectedCondition<WebElement>) (WebDriver d) -> { return d.findElement(By.id("filter")); });//from w ww . ja va 2s .c o m filter.sendKeys("2002"); //searching for tbody WebElement table = (new WebDriverWait(driver, MAX)).until((ExpectedCondition<WebElement>) (WebDriver d) -> { return d.findElement(By.tagName("tbody")); }); //checking whether number of rows is 2 Assert.assertThat(table.findElements(By.tagName("tr")).size(), is(2)); }
From source file:TestWithSelenium.java
@Test public void vTestClearFilter() { //searching for filter & sending key WebElement filter = (new WebDriverWait(driver, MAX)) .until((ExpectedCondition<WebElement>) (WebDriver d) -> { return d.findElement(By.id("filter")); });/*ww w . j av a2s. c o m*/ filter.sendKeys(Keys.BACK_SPACE); //searching for tbody WebElement table = (new WebDriverWait(driver, MAX)).until((ExpectedCondition<WebElement>) (WebDriver d) -> { return d.findElement(By.tagName("tbody")); }); //checking whether number of rows is 5 Assert.assertThat(table.findElements(By.tagName("tr")).size(), is(5)); }
From source file:TestWithSelenium.java
@Test public void wTestSorting() { //searching for sort button WebElement sortButton = (new WebDriverWait(driver, MAX)) .until((ExpectedCondition<WebElement>) (WebDriver d) -> { return d.findElement(By.id("h_year")); });//from w ww . j a v a 2s . c o m sortButton.click(); //searching for tbody WebElement table = (new WebDriverWait(driver, MAX)).until((ExpectedCondition<WebElement>) (WebDriver d) -> { return d.findElement(By.tagName("tbody")); }); //listing all tr List<WebElement> tableSorted = table.findElements(By.tagName("tr")); Assert.assertThat(tableSorted.get(0).findElements(By.tagName("td")).get(0).getText(), is("938")); Assert.assertThat(tableSorted.get(4).findElements(By.tagName("td")).get(0).getText(), is("940")); }