WebDriver how to human face for warning inwards selenium 2

As nosotros accept seen inwards my previous posts, nosotros tin use textToBePresentInElementLocated(By, String) WebDriver status to wait for text present on page in addition to nosotros tin use elementToBeClickable(By locator) to wait for chemical part clickable/present on page. If y'all read both those posts, We had used explicit waits in both the cases in addition to both are canned expected weather condition of webdriver so nosotros tin role them straight inwards our testify instance without whatsoever modifications.

Sometimes y'all volition aspect upwards wait for alert scenario where y'all accept to wait for alert earlier performing whatsoever activity on your software application spider web page. If y'all know, nosotros tin role "waitForAlert" ascendence inwards selenium IDE to handgrip alerts. In WebDriver/Selenium 2, You tin role WebDriver's built inwards canned status alertIsPresent() amongst hold off ascendence every bit bellow.

WebDriverWait hold off = novel WebDriverWait(driver, 15); wait.until(ExpectedConditions.alertIsPresent());

Look inwards to higher upwards syntax. 1st syntax described how much fourth dimension it has to hold off in addition to sec syntax describes the waiting condition. Here nosotros accept used alertIsPresent() status thence it volition hold off for the warning on page. Let me give y'all sum practical illustration to depict scenario perfectly.

Copy glue bellow given testify instance inwards your eclipse amongst JUnit in addition to thence run it. You tin View how to configure eclipse amongst JUnit if y'all accept no idea.

package junitreportpackage;  import java.util.concurrent.TimeUnit;  import org.junit.After; import org.junit.Before; import org.junit.Test; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait;   populace shape Mytest1 {  WebDriver driver = novel FirefoxDriver();    @Before  populace void beforetest() {   driver.manage().window().maximize();   driver.get(" ");  }    @After  populace void aftertest() {   driver.quit();     }    @Test  populace void testify ()    {     driver.findElement(By.xpath("//input[@name='fname']")).sendKeys("My Name");   WebDriverWait hold off = novel WebDriverWait(driver, 15);   wait.until(ExpectedConditions.alertIsPresent());   String alrt = driver.switchTo().alert().getText();   System.out.print(alrt);   }        }

Above illustration volition hold off for the warning on page in addition to every bit before long every bit warning appears on page, it volition shop warning text inwards variable 'alrt' in addition to thence volition impress to it inwards console.


More interesting articles here :Generation Enggelmundus Internet Marketing Tool here :Zeageat IM http://www.software-testing-tutorials-automation.com/
Post a Comment (0)
Previous Post Next Post