Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • WebDriver Synchronization

    • 0
    • 2
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 497
    Comment on it

    WebDriver Synchronization

    The process of matching speed of automation with the speed of application is called as Synchronization.

    In Web Driver we can Synchronize in different ways, one way of synchronizing the Web Driver is by using sleep() of thread.

    Example:

    WebDriver driver = new FireFoxDriver();
    driver.get("https://mail.google.com/");
    driver.findelement(By.name("Email")).sendkeys("admin@gmail.com");
    driver.findelement(By.name("Passwd")).sendkeys("Testing");
    driver.findelement(By.id("signIn")).click();
    Thread.sleep(3000);
    driver.findelement(By.id("signout")).click();
    driver.close();
    

    In the above example application will be slow in two locations:

    1. While displaying the Login page: Here we need not to Synchronize the script because the get() will make the Web Driver to wait till the page is completely loaded. The user-name field will be searched by findelement() only after the page is completely loaded.

    2. While displaying Homepage: When the Web Driver clicks on login button it will immediately tries to click on logout button but application is still loading the web page. Here we should Synchronize the web driver using Thread.sleep();.

    In the above example it waits for 3 seconds.

    Thread.sleep() has its limitation i.e, it will throw interrupted exception which we need to handle it. Even though a page is loaded in a second the above Thread.sleep() code will always make the Web Driver to wait for 3 seconds.

    To overcome the above limitation[dead-wait] we use "implicitly wait" (only for findelement()):

    Example:

    WebDriver driver = new FireFoxDriver();
    driver.manage().timeouts().implicitly wait(20,timeunit.SECONDS);
    

    The implicitly wait makes the find-element to search for the specified element continuously till it is found within the specified timeout i.e, if the element is found at 5th second it will immediately perform the operation and it goes to next statement.

    Even after the specified timeout is over if the element is not found then it will throw the exception.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: