Re: Why can't I Bypass WebDriver implicitlyWait once implicitlyWait is set?

2,009 views
Skip to first unread message

Tarun Kumar

unread,
Aug 9, 2012, 1:16:06 AM8/9/12
to seleniu...@googlegroups.com
On Thursday, August 9, 2012 3:35:05 AM UTC+5:30, andre wrote:

So, I ask again... Why, oh why, oh why why, oh why why why? 



Coming to implicit wait, If you have set it once then you would have to explicitly set it to zero to nullify it -

public void nullifyImplicitWait() {
  driver.manage.timeouts.implicitlyWait(0, TimeUnit.SECONDS)

Invoke this method when you want to get rid of implicit wait.
And to introduce implicit wait again - 

public void introduceImplicitWaitPeriod() {
        driver.manage().timeouts().implicitlyWait(IMPLICIT_WAIT_TIME, TimeUnit.SECONDS);
}

These methods could reside some where in your framework to be easily accessible by test, page objects etc classes


But then this solution looks dirty, is not it? Ideally you should not use implicit wait and prefer explicit wait when ever required. Some thing like - 

WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("someid")));
reference - http://seleniumhq.org/docs/04_webdriver_advanced.html
 

Mike Riley

unread,
Aug 12, 2012, 1:20:48 PM8/12/12
to seleniu...@googlegroups.com
I have wrapper routines that take timeout arguments and do my own timing out check for that reason.  I created it before implicit and explicit waits were available and I don't see any reason to change from it at this time, because you do have some instances where you need a longer timeout that other times.

Mike

On Thursday, August 9, 2012 12:43:52 PM UTC-7, andre wrote:
You see, Tarun, this is part of my rant. This would not work:

driver.manage.timeouts.implicitlyWait(10, TimeUnit.SECONDS) 

...and at some point afterwards...

driver.manage.timeouts.implicitlyWait(0, TimeUnit.SECONDS) 

Because once you set implicitlyWait for a WebDriver is does not change for the life of that driver.

I am making the choice you mentioned: To not use implicit waits and to always rely on explicit waits for synchonization. This makes my suite less reliable, especially as many people write scripts and may or may not make the appropriate explicit wait calls.

I am, however, using RemoteWebDriver.manage().timeouts().pageLoadTimeout(15, TimeUnit.SECONDS), this brings a little more reliability as in providing a minimum waiting time when we move to an entire new page.

But I still wish I could set a "default" for the whole suite, and at the same time, when I need, explicitly wait for 5 seconds, 1 second, 0 seconds, etc. as I please. This I think is not possible and I am sorry that it is.

Mike Riley

unread,
Aug 16, 2012, 5:31:27 PM8/16/12
to seleniu...@googlegroups.com
I see your point.  I came at it from using the 1.0 API and migrating into WebDriver with WebDriverBackedSelenium, so I was used to doing the wait for page to load in my code.

Thanks for the suggestion.

Mike

On Monday, August 13, 2012 10:18:12 AM UTC-7, andre wrote:
Yes Mike, but a default is (would be) useful for reliability across a whole suite of tests. You may be carefull to insert an explicit wait (or a call for a waiting routine) every time that one is needed or you may not. Also, implicitly waiting extracts from the scripts and to me that means more maintainability and less test code. Test code is a lousy place for an error to be. So I implicitly wait for page loads and re-loads. Tester need not worry (too much) about "hm, is this call to this component going to reload the page?". Also, how about when the GUI may change behaviour and your script may break unnecessarily. 
Of course there are many many moments when a call for a routine with an explicit value for timeout is in place, but I just can't do that in conjunction with having set a default... because it will always wait at least for the value set on implicitlyWait()... still don't see why it should be this way.
In short, when I "tell" the driver how long it should wait, it should wait for that amount. When I do not "tell" it, because I forgot, because the application behave unexpectedly, or because I plain don't need to, it should DE-FAULT by itself and wait at least the default value before it goes ahead and "breaks all the dishes". 
Well... my point of view so far.

Mike Riley

unread,
Aug 22, 2012, 4:14:47 PM8/22/12
to seleniu...@googlegroups.com
I never thought that.  It gave me another thing to think about.

I wrote my routines before we had implicit waits, so I never started using them with my library.  But now that I no longer work for that company I may be re-writing my library to allow for them.

Mike

On Tuesday, August 21, 2012 11:17:53 AM UTC-7, andre wrote:
Hey Mike. Thank you, for the consideration. And just for the record, please do not interpret my comments as malicious, as they were all made in good spirit.

Mark Collin

unread,
Sep 29, 2012, 8:33:46 AM9/29/12
to seleniu...@googlegroups.com

Your presentation is wrong, best practice is to not set implicitlyWait() at all because once it is set it can’t be overridden. 

 

It can also cause explicit waits to not work as intended because the implicit wait overrides the settings of the explicit wait.

 

Generally if you know you need to wait for something do it explicitly, don’t ever set implicitlyWait()!

 

From: seleniu...@googlegroups.com [mailto:seleniu...@googlegroups.com] On Behalf Of Chon Chung
Sent: 29 September 2012 03:24
To: seleniu...@googlegroups.com
Subject: [selenium-users] Re: Why can't I Bypass WebDriver implicitlyWait once implicitlyWait is set?

 

Andre and Tarun:

I create WaitTool class to use implicitlyWait() and webDriver at the same test. 

Here is Presentation http://chon.techliminal.com/ajax_wait/

source code is in github https://github.com/ChonC/wtbox/blob/master/src/wtbox/util/WaitTool.java

How do you think?  Is it work?

 

 

Chon Chung 


On Wednesday, August 8, 2012 3:05:05 PM UTC-7, andre wrote:

In short:

Why, oh why, oh why why, oh why why why, can't we alter the default timeout by calling WebDriver.manage().timeouts().implicitlyWait() a second time? Or have some other form of overriding the default?

 

Per documentation:

The default setting is 0. Once set, the implicit wait is set for the life of the WebDriver object instance. 

 

So, I ask again... Why, oh why, oh why why, oh why why why?

 

After I set implicitlyWait to say, 10 seconds, when I want to check for elements not present on the screen, I can't use WebDriver.findElements, because it will wait 10 seconds to throw an Exception before it does. If I do this for 6 elements, there goes a minute. 

 

On another situation, I can't use even a EXPLICIT wait in the form of:

 

            (new WebDriverWait(myDriver, 2)).until(new ExpectedCondition<Boolean>() {

                                    //@Override

                                    public Boolean apply(WebDriver d) {

                               try{

                                                            return d.findElement(by).isEnabled();

                                                }catch(NoSuchElementException e){

                                                            return false;

                                                }catch(StaleElementReferenceException ex){

                                                            return false;

                                                }

                                    })

                        });

...

 

because the driver I am passing by reference has already set the implicitlyWait(10),in the past, so even if I am passing 2 as timeout for this WebDriverWait, it will wait 10 seconds for the element when it reaches the return statement ( return d.findElement(by).isEnabled(); )

 

Now,

 

It should be plain and simple, in my project, to be able to have a DEFAULT timeout value for findElement so that scripts are reliable across the entire suite against elements that just didn't show up yet.

 

DEFAULT means, a value that you go back to, when you don't inform it explicitly!

 

So when I do inform a value EXPLICITLY, I DON'T WANT TO USE the default. See, that is what "default" means.

 

If I could do this, I'd have scripts that are both "reliable", and "fast". What a good thing hu? :)

 

So, why? :)

 

And, is there a way to bypass it that I am unaware?

 

 

 

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/KOgT2nQO52MJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Mark Collin

unread,
Oct 2, 2012, 1:22:05 AM10/2/12
to seleniu...@googlegroups.com

Interesting, that implies implicitly wait is no longer set for the life of the object but can now be tweaked on the fly.

 

I'll have to investigate at some point :)

 

 

From: seleniu...@googlegroups.com [mailto:seleniu...@googlegroups.com] On Behalf Of Chon Chung
Sent: 02 October 2012 00:51
To: seleniu...@googlegroups.com
Subject: Re: [selenium-users] Re: Why can't I Bypass WebDriver implicitlyWait once implicitlyWait is set?

 

Hi Mark: 

 

Thank you for your comment.  I believe it is important to test WaitTool, to find out it really works or not.  

So, I just add: testWaitTool_class() method in AJAX_wait class ( https://github.com/ChonC/wtbox/tree/master/src/test/wait_example)

 

testWaitTool_class() method checks the following: 

 

This test verify 3 things: 

  1. Test if the WaitTool method only wait for the given wait time.  

        and implicitlyWait setting does not effect on WaitTool's wait time. 

    

   2. Test performance: how long does it takes calling driver-implicitlyWait 100 times.

  

  3.   Verify reset implicitlyWait() do actually work:

 

 

 

 

And here are the test result of testWaitTool_class() method 

 

test WaitTool_class-----------------------------------------

Test WaitTool.waitForElement: 3 seconds wait time =========

time before WaitTool.waitForElement: Oct 01,2012 14:11:05

time  after WaitTool.waitForElement: Oct 01,2012 14:11:09

 

Test performance: calling driver-implicitlyWait 100 times=========

time before calling: Oct 01,2012 14:11:09

time  after calling: Oct 01,2012 14:11:10

 

Test resetImplicitWait (given wait time = 2 seconds) =========

time before: Oct 01,2012 14:11:10

time  after: Oct 01,2012 14:11:12

 

test WaitTool_class-----------------------------------------

 

Seems Tarun's nullifyImplicitWait() works beautifully.  Could you verify my testing result?  You can download the latest code and check it.  

Also, thank you for pointing out isTextPresent bug.  I updated the code based on your suggestions.  

 

It is hard to test my own code. :-)  Thank you.  

 

Sincerely, 

 

Chon

To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/djYeGfqftpEJ.

Reply all
Reply to author
Forward
0 new messages