Vaadin 8 + Selenium = Slow combination, why? - selenium

I've been using Vaadin 8 for years, but a few months ago it was decided to use "Selenium" instead of Vaadin "Testbench". I will list some problems I have, maybe someone has a solution. I found a good explanatory page https://alexsiminiuc.medium.com/your-selenium-tests-are-not-slow-because-of-the-selenium-framework-63f871e2d38f but maybe someone has other information about this issue.
Expenditure:
Loading the first page, for example login page, takes more than 15 seconds to load in the browser and "noHeadlessMode". I think it's because of the Sass compiler that generates new data every time the user calls.
Sometimes "Selenium" waits even though no waiting time is defined. The wait time for WebDriver to avoid "NotFoundException" is set to 60 seconds and pause is not set.
Maybe because "selenium" loads some code and does some checks that take some time?
Sometimes it just fails and can't find item even though it runs normally and there is item.
Maybe a bug or an internal delay in "Selenium"?
Thanks for the help!

Related

Cannot determine loading status in Google Maps

I had a test written in Java and Selenium that basically does a search for a provider. It then clicks on the provider's Map This Location link and opens a google map. I would wait for an xpath visibility for that map after switching to the new window.
The URL would be something like
https://www.google.com/maps/dir//945+N+12th+St,+Milwaukee,+WI+53233/#43.0426642,-87.9297109,17z/data=!4m8!4m7!1m0!1m5!1m1!1s0x88051979232b79cd:0x905e19b746c46eb3!2m2!1d-87.9275222!2d43.0426642
This has been working fine for a year. Today we got updated to Chrome version Version 74.0.3729.108 (Official Build) (64-bit) so we replaced our old Chromedriver (which was now giving us an error that the Chrome version had to be between 70 and 73) with 74.0.3729.6 which our head developer downloaded from the site.
The problem is, now, and only for certain addresses, I get that error
unknown error: cannot determine loading status from no such execution context
Some Stack Overflow items suggested
1. Updating the Chrome Driver
2. Using a longer timeout
as you can see from above we updated our chromedriver to be consistent with the version of Chrome. I also updated the timeout to 300 seconds (5 minutes), but all in vain.
I am out of ideas about what else could be causing the problem. The xpath I waited for was //div[#aria-label='Map'] but I have tried other xpaths now too, such as "//div[#id='streetviewcard']". I verified that the window I switched to was driver.getWindowHandles().get(1). I had saved the original handle so I could switch back. I looked at all the window handles, and there were only 2, the original one and the one I switched to.
No other searches come up with anything useful.
I had exactly the same error, moving to v74.
Something must have changed with chromedriver, or chrome - I assume that when a new tab is opened, execution continues sooner than it did before. It's hard to tell what's actually changed, but ultimately I fixed our issues with a sleep:
Also, it's worth noting that getWindowHandles() returns in an undefined order - so might need some extra handling depending on your use case.
https://github.com/dvsa/mot-automated-testsuite/compare/ops-OPSTEAM-2827-selenium#diff-1fa0893dd1ad67d9c1a4ee1e777c20cb

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

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.

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.

Conditional wait vs implicitlyWait -Selenium

please help me in understanding the following issue. please.
I have to get all links and check them later. I used the following code:
open(url);
List<String> links = new ArrayList<>();
for (SelenideElement link : $$("a"))
links.add(link.attr("href"));
when I used this with Linux with these api version:
Maven 3.1
Selenide v3.5
Selenium v2.53
Firefox v45.0.1
Then code can't take time enough to catch links from the page. Then I have to add driver wait before get links.
I Add the following (which is conditional wait):
WebDriverWait waitLog = new WebDriverWait(WebDriverRunner.getWebDriver(), 20);
waitLog.until(ExpectedConditions.visibilityOf($(By.tagName(Selector))));
And it worked fine and I run it more than one time.
I got surprised when running it yesterday, it didn't work and can't get time enough to get links!
So I replace the conditional wait with implicit wait, and add the following:
WebDriverRunner.getWebDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
Now it is working fine.
What happened?
What is this thing make it work sometimes and sometimes can't work?
How to return back to the conditional wait with keeping the code working well?
So how to recover this problem? and prevent this problem from happens in the future.
There might be some delay in loading the url for the second time. Please try increasing the delay time for conditional wait. The main difference between explicit and implicit wait is as follows.
Explicit or conditional wait stops the WebDriver for the specified amount of time, till the mentioned element is available. Whereas implicit wait will skip execution of WebDriver for specified amount of time, for every element which is not found on the page.
Hope this helps.

Selenium RC - t.replace is not a function

[edit for godman] I am working on a web based application, written in PHP. I am using Selenium RC to run tests on the webpages produced by this application, through a browser.
I just upgraded to Firefox 14, so I had to upgrade to Selenium RC 2.25.0.
Now I'm seeing this error when running a test with htmlSuite:
Command execution failure. Please search the user group at
https://groups.google.com/forum/#!forum/selenium-users for error
details from the log window. The error message is: t.replace is not a
function
The command executed is:
clickAndWait //a[text()='! selenium test customer']
As you can see, it's not doing anything too tricky - just clicking a link. The test runs fine in the IDE, it's just when run via RC that it's a problem.
Searching in the groups revealed only really old threads dating back to version 1 of selenium.
Any ideas anyone?
[edit] I've been running the test that has these problems several times a day for the last week - and it doesn't seem to fail like this every time. This looks like it's a random problem. Has anyone seen this happen before?
[edit after the bounty got me no answers] Another example of it failing is with:
clickAndWait css=a.edit_company
This same call works fine earlier in the same test, on the same page.
[edit] Now I'm seeing the same error with a completely separate command:
type id=Address1 Address1
Does anyone have any suggestions about this? Any way I can even debug what's going on (I don't see this in the IDE at all)
I am not terribly familiar with clickAndWait. I personally prefer clicking and then doing my own custom waiting.
Try just clicking and add a Thread.Sleep(5000), or something similar, and see if the error is a result of the click or the wait part.
If it is the wait part, then I have a different suggestion than if it is the click part.
I've seen similar issues across various platforms. It has always been somewhat random for me, so I don't use clickandWait. Generally is is much more reliable to do a plain click, and then wait for specific condition. You could do a waitforpageload, but that has also been unreliable for me so I prefer things like waitfortextpresent and waitforelementpresent.
Usually, this kind of error would occur if you are dealing with something that is not a string. Could you just make sure that you are dealing with strings only?
2 possibilities where it is arising from:-
When text() is executed -> it might be dealing with a non-string
a[expression] -> the expression(text() = '! selenium test customer') when evaluated to False/True might be the problem because if a is a Map/array, the corresponding key should be a string and not a bool, probably.
text()='! selenium test customer' -->> is it an assignment operation? if yes, make sure that text() returns a lvalue or a mutable object (based on the language you are using selenium rc with)