a wait that stops the test till nothing is happening in the web page anymore - selenium

I am using Java and Selenium to write a test. Many times in my test i have to wait till the page or some part of it loads something. I want to wait till the load is finished. I found these two:
1) pageLoadTimeout
2) setScriptTimeout
But I don't know the exact difference between them or even if they are what I need.
The document says:
setScriptTimeout: Sets the amount of time to wait for an asynchronous script to finish execution before throwing an error. If the timeout is negative, then the script will be allowed to run indefinitely.
and
pageLoadTimeout: Sets the amount of time to wait for a page load to complete before throwing an error. If the timeout is negative, page loads can be indefinite.
but I don't really get it.
what I need is a wait that stops the test till nothing is happening in the web page anymore.

Define "nothing is happening in the web page." Now define it in such a way that will satisfy every web page ever created, or that ever will be created. Did your definition include that no more network traffic is coming over the wire? Did your definition include that the onload event has fired? How about document.readyState returning a value meaning "complete?" Did you take JavaScript execution into account? How about JavaScript scheduled using window.setTimeout()? WebSockets? Service Workers? What about <frame> or <iframe> elements?
Now you know why WebDriver doesn't have a "wait for page complete" type of wait. The items mentioned above don't even begin to scratch the surface of the list of things a user could legitimately use in a definition of "nothing is happening on the page anymore." The correct approach would be to wait for the element you want to interact with on the next page to be available in the DOM. The WebDriverWait class is ideally suited for exactly this.

Related

How to wait until an object has been removed/deleted from a webpage in UFT?

In our web application there are tables where users can enter/delete data.
Checking once something has been added, I'd like UFT to wait until the element is no longer on the page before continuing. Each time a row, or element is deleted from the webpage the page refreshes, often UFT will try to continue thus causing the test to fail.
It seems .WaitProperty "visible", false, 3000 waits for the timeout to complete and then continues.
I'm looking for something similar to .StalenessOf in Selenium.
Looking to have the wait be more dynamic to make these tests run as fast as possible. If we end up using UFT I'll have a very large test suite and would like to reduce the amount of hard-coded waits, and avoid them if I could.
UFT supports Exist to check if an object exists.
You can pass a zero timeout and wait until the object doesn't exist.
While Obj.Exist(0)
Wait 1
WEnd

Issue with page load timeout and next task is directly sent to except

I was running a python script responsible for web scraping some pages using multiprocessing techniques.
In order to wait for a page to get fully loaded, I used the method set_page_load_timeout() set to 30s.
I put a driver.get() inside a try-except structure.
However, I observed that in my case, when all the 5 Chrome instances are busy with 5 different pages, the next page pulled from the task queue goes to my exception and stored in my error file. I presume this occurs since the Chrome instances are still trying to load the 5 previous pages and not able to redirect to this new page.
How could I get over this issue?

Best way to automate a page and check if it is loaded correctly

I am looking to verify if this page loads correctly - http://www2.hm.com/en_ca/women.html
These are the things I think it would be best to verify if the page is loaded correctly, please let me know if I am missing anything
1) Verify all the links on this page works?
2) Verify if the menu on the top is loaded correctly, Do I need to verify the menu names?
3) Check if the classes are loaded properly?
4) get/post request status 200 and other ajax calls?
As per your question a seperate test to check if the page is loaded correctly will be a complete overhead because the Client (i.e. the Web Browser) will never return the Execution Control back to the WebDriver instance until and unless 'document.readyState' is equal to "complete". Once this condition is fulfilled Selenium performs the next line of code.
You can find a detailed discussion on this topic in Selenium IE WebDriver only works while debugging
Next as you want to Verify if all the links on this page works or not , you can write a function() and invoke the function() whereever required.
Moving on to next question, there is no necessity to Verify if the menu on the top is loaded correctly or not as you can't test each and every aspect of each and every WebElement present on a WebPage. The best approach would be to verify and validate the attributes of only those elements with whom we need to interact.
Again Checking if the classes are loaded properly will be a overhead as JVM takes care of it in the best possible way.
Finally, to validate get/post request status 200 you have to write Tests as per your requirement.

How to continue test when the page still not completely loaded in selenium

Actually, I am creating automation testing for an e-commerce website. Actually, the website have function lazy load or something. I am testing it on UAT server. So, it will load the page slowly because the specification of the server. It takes more than 60 sec or more to load all the resources from the webpage. So, when I am trying to create selenium automation, it always waiting more than 60 sec to continue the next step (because waiting the page fully loaded). Please, someone give me tips how to continue run the test step after 10 seconds wait the page to load. It won't throw an exception, just continue the test step.
Not possible.
If you find some element and try execute some action while loading you will get stale element error + due loading issue you will have a lot of failed tests and it will take a lot more time to debug.
Automation means to execute fast and have reliable results.
It seems that this environment is not built for automation, you should request more resources.
As an alternative maybe you can use a headless driver or see if you can put the same build on a VM.
Why this is an issue: Selenium needs to wait for each request to be complete.For example when you request a page, if the page is not received entirely and the server still sending info then the request is not done, it is logical that you need a complete request in order to continue.
You should address this to your Project Manager/QA Lead and ask for advice/option on how to handle this.
Please note that these costs should be included/added in the automation price.You need to address this in a simple way:
good server -> automation runs smoothly and fast and the testing is
done faster
bad server -> unable to run automation since is not reliable and each
test has a high rate of failure => alternative X day(s) of
manual testing for each build
If this would be a coding issue like some delayed ajax request then you would have some solutions, devs could help, but if is an infrastructure/resources issue then if not depending on you, and you cannot solve it.
You could use try any type of wait implicit/explicit, explicit would throw some exception, but this is not a solution for poor resources.

The default value of timeouts on selenium webdriver

I am interested in the default value of timeouts on selenium webdriver.
ImplicitlyWait, SetPageLoadTimeout and SetScriptTimeout.
Because I want to know, Do I need to set a values for those timeouts? or the default value is good for selenium webdriver working.
But I cannot find a correct answer, someone say the default value is 0, and other one say it is 30 sec.
These three timeouts are managed by the server-side of the Selenium equation. Your script, be it in Java, Python, Ruby, C#, or whatever, is a client that sends commands to a server that lives in the browser. (There may be an intermediary that relays commands to the browser, like Selenium grid. Unfortunately, it is also sometimes called a "server".)
The WebDriver specification, which was derived from Selenium has settled on the following values:
For implicit waits: 0 seconds. This means that if a selenium command does not find an element immediately, it reports immediately, rather than wait until an element is found.
For page loads: 300 seconds.
For script timeouts: 30 seconds.
(The specification gives the values in milliseconds. I've converted them to seconds for ease of reading.)
Selenium now follows the WebDriver specification.
In the past Selenium has used other values for these, however. For instance, the Firefox driver used to define its timeouts like this:
The implicit wait timeout is set to 0 by default. This means that if a command that finds elements does not find anything, it won't wait.
The page load timeout is set to -1 by default. This means that Selenium will wait indefinitely for the page to load.
What Saifur found is not the same as the page load timeout. That's a timeout between the Selenium client and the Selenium server, which is not particularly well explained on the page Saifur found.
The script timeout is set to 0 by default. A comment in the source code explains:
The amount of time, in milliseconds, this session should wait for asynchronous scripts to finish executing. If set to 0, then the timeout will not fire until the next event loop after the script is executed. This will give scripts that employ a 0-based setTimeout to finish.
So even if it set to zero, an asynchronous script can still execute but it has to complete before Selenium's timeout gets a chance to run again.
This is from the code that Selenium uses for Firefox. The other browsers use different code bases but they are supposed to behave consistently, at least with regards to things that are proper to Selenium itself, like these timeouts. So the values and their interpretations should be the same for other browsers too.
For implicit wait always default wait it ZERO. , you can check it here :
Selenium Webdriver diff. waits
And if you set custom time then web driver will wait to get element till that time and if element does not found till that time then only web driver will throw exception.
The Selenium documentation is very much unclear on these timeouts.
According to
this
the default timeout of the implicit-wait is 0
According to
this
any page that does not load in 60s will return http communication
timeout unless you explicitly overwrite the timeout.
Unfortunately, I did not find any reference to provide on
ScriptTimeout. But, it's defaults to 0 according to my knowledge
and experience. Will update you with any reference later