TESTEVERYTHING

Wednesday, 16 November 2016

Actual differences between Explicit and Implicit Waits

Hi All,

As i have already mentioned the differences Explicit and Implicit Waits in my earlier post but now we will see the actual results. there will be two conditions we can think of it what will happen if implicit wait is greater than explicit wait OR  implicit wait is lower than explicit wait

lets see what will happen


Condition 1: implicit wait is greater than explicit wait

           implicitlyWait = 10 seconds
            explicitWait = 2 seconds
            ///////////////////////////////////////
            public static void main(String[]args) {
            FirefoxDriver driver = new FirefoxDriver();
            driver.manage().window().maximize();
            driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
            driver.get("https://www.google.com");
            try {
                        Date date = new Date();
                        System.out.println(" before " + new Timestamp(date.getTime()));
                        WebDriverWait wait = new WebDriverWait(driver, 2);
                        wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[contains(text(),'NOT FOUND ELEMENT')]")));
            } catch (Exception e) {
                        // TODO Auto-generated catch block
                        Date date = new Date();
                        System.out.println(" after " + new Timestamp(date.getTime()));
                        e.printStackTrace();
            }


/////////////////////////////////

let see the output in console:   taking 10 seconds

before 2016-11-16 16:24:33.128
after 2016-11-16 16:24:43.321

Condition 2: implicit wait is lower than explicit wait
           implicitlyWait = 2 seconds
            explicitWait = 10 seconds
            ///////////////////////////////////////
            public static void main(String[]args) {
            FirefoxDriver driver = new FirefoxDriver();
            driver.manage().window().maximize();
            driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
            driver.get("https://www.google.com");
            try {
                        Date date = new Date();
                        System.out.println(" before " + new Timestamp(date.getTime()));
                        WebDriverWait wait = new WebDriverWait(driver, 10);
                        wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[contains(text(),'NOT FOUND ELEMENT')]")));
            } catch (Exception e) {
                        // TODO Auto-generated catch block
                        Date date = new Date();
                        System.out.println(" after " + new Timestamp(date.getTime()));
                        e.printStackTrace();
            }


/////////////////////////////////

let see the output in console:   taking 10 seconds

before 2016-11-16 16:26:53.355
 after 2016-11-16 16:27:03.53






Tweet