Slow/incomplete page load in the browser launched by selenium webdriver - selenium

I am using selenium WebDriver using RobotFramework. The major problem we are facing is, my tests are timing out even after setting timeout as high as 10 minutes. It happen with any browser I use. These thing works much faster If I run test manually (with all browser cache/data/cookie cleared). These are the other things I have observing for few months.
Some component are never loaded (I check the call trace using BrowserMob Proxy and we found nothing unusual)
"Click Element" does not work in many cases. Clicking on element triggers some action but that action is not always trigerred in automation. Manually it works all the time.
Notes:
This is happening on FF and Chrome. (IE is not working for me at all)
App server and automation suite is in LAN so latency is not an issue
No other heavy process is running at this time
Issue persist even if with firefox default profile
I tried it with different selenium versions. (2.45 - 2.52)
I took latest driver for chrome. Broweser: FF 40+ and GC 48
This does not look application issue as we spent 2 month confirming that. Let me know if you need any other detail.

Related

Chrome Headless - Firefox

I'm working on a monitoring tool for my website to log data. The actual logging is made on server. My goal is to calculate stats based on how long the user stays on the website.
Main question: I used chrome headless command --remote-debugging-port=80. I got logs for up to 10 minutes. Works perfectly. But how long will it work if left working? Is there a default timeout? If yes, how can I change it? If I want to run it exactly 30 minutes after page finished loading?
I'm trying to do the same on firefox (tried using PhantomJS but it wasn't loading the page correctly even though useragent was set to firefox) but firefox just throws an bank page when I'm trying to start a headless mode. I used "firefox -headless" and tried capturing an screenshot. It was just exiting my currently open firefox tabs without capturing any image. Any idea?
Using firefox quantum 59.0. I don't want to use selenium.
Also PhantomJS solution would be great. Currently I just want to collect logs. So, it only have to run all javascript (an jquery) code on the page which then sends the data using ajax. I tried page.onLoadFinished and then a wait function to make it stay on the page for the exact time after page loading.
Since no one answered, I will try to answer my own question after even more research and logical thinking.
Main question: Seems that there is no timeout but if need can be used --timeout X. Even though it's not perfect because it runs independently if the page if fully loaded or not.
As for the firefox, it's buggy. -new-instance (make headless run while you are already on firefox) is not working and -no-remote didn't help. Firefox is only working if running only one instance. So, if it's the PC you are working on and you want to run tests too, firefox is not for you. Headless runs only when no other instances of firefox are running, while chrome runs fine.
PhantomJS didn't work even though tried multiple solutions.
Best solution? Use chrome. Need portable? Use chromium and use headless. Or write your soft to use cefsharp which is based on chromium. Your browser with all libs will be around 120-200MB. Pretty big for portable but do it's work. Same as portable chrome or chromium. CefSharp have a privilege of integrating whatever you like into the browser since it's a... browser.

Tests timeouts (Selenium+Jenkins+Grid)

We've started getting random timeouts, but can not get reasons of that. The tests run on remote machines on amazon using selenium grid. Here is how it is going on:
browser is opened,
then a page is loading, but can not load fully within 120 seconds,
then timeout exeption is thrown.
If I run the same tests localy then everything is ok.
The Error is ordinary timeout exception that is thrown if a page is not loaded completely during the period of time that is set in driver.manage().timeouts().pageLoadTimeout(). The problem is that a page of the site can not be loaded completely within that time. But, When period of time that is set in driver.manage().timeouts().pageLoadTimeout() is finished and, consequently, Selenium possession of a browser is finished, the page is loaded at once. The issue can not be reproduced manually on the same remote machines. We've tried different versions of Selenium standalone, Chromedriver, Selenium driver. Browser is Google Chrome 63. Would be happy to hear any suggestions about reasons.
When Selenium loads a webpage/url by default it follows a default configuration of pageLoadStrategy set to normal. To make Selenium not to wait for full page load we can configure the pageLoadStrategy. pageLoadStrategy supports 3 different values as follows:
normal (full page load)
eager (interactive)
none
Code Sample :
Java
capabilities.setCapability("pageLoadStrategy", "none");
Python
caps["pageLoadStrategy"] = "none"
Here you can find the detailed discussions through Java and Python clients.

Serenity how to keep browser only one instance through the test

I'm using Serenity jbehave to automate my webapp, and I got trouble in keeping one browser instance through the test.
My app need to login to perform any test, so I don't want to start new browser and login again and again every story.
I tried the setting below but it seem not work as expected. I am using Serenity 1.5.rc-1 with latest Firefox and Chrome, my test always open new browser every story run, if I run 5 stores, then there are 5 instance of Firefox open.
I googled for 2 weeks, but I'm still stuck.
Please help!
serenity.properties
serenity.use.unique.browser=true
serenity.restart.browser.for.each=NEVER
restart.browser.each.scenario=false
JBehave doesn't support using a single browser across all stories (there is no way of knowing when the suite has finished running, so no way of knowing when to shut down the browser cleanly), so the optimal setting is
serenity.restart.browser.for.each = story
This is actually a good compromise, as some WebDriver instances can become flaky when run for too long with the same browser.

Is Phantomjs session isolation still not working?

When I run my selenium tests using a chrome browser all my tests cases run fine. When using the phantomjs browser it would appear that the browser session does not get reset after each test case. In my tests cases, I log in as a user to then navigate to certain pages and then logout. A problem occurs when a test case happens to fail. The browser session is not reset so when the next test case begins, the test that failed was unable to logout. This causes all test cases after a single failure to fail.
When searching the internet for a solution to this issue it been known sine 2013. I can't seem to find anything regarding this issue that's recent. Is there any up to date workarounds?
Manually trying to delete the cookies before or after each test case does not appear to work. webDriver.manage().deleteAllCookies();
I'm using phantomjs ver 2.1.1.
First of all PhantomJS is dead, you are better off switching to Headless Chrome or Headless Firefox.
Secondly PhantomJS is a port of Webkit which is not thread safe. This means that if you try and run more than one test in parallel you will see threading issues, to fix this you would need to start multiple instances of PhantomJS and have each GhostDriver instance connect to a different instance of PhantomJS.
The particular problem that you are seeing is that PhantomJS doesn't clear itself down properly, again the only solution would be to kill the initial PhantomJS instance you are running after your test finished and then start up a clean new one, unfortunately that is not supported by GhostDriver.
The final problem is that GhostDriver is dead as well, there was no point in continuing development when PhantomJS died.
TLDR; Use Chrome/Firefox Headless mode instead.

Running Selenium with IE11 for several minutes results in the browser freezing

When running several tests synchronously using Selenium with IE, after about 10 minutes the browser starts to freeze. The browser will not render pages properly or respond at all. I can only diagnose that when these symptoms occur, the Memory reaches about 1.7G and hovers around there. I use Capybara so after every test, on average about every 30 seconds, it will reset the session. This issue does not occur when I use Firefox or Chrome.
Does anyone have any thoughts? I could try figuring out why it stops at 1.6G, but I imagine I'd hit the same issue once hit what ever new cap is set. I could also restart the process every few tests, but that would slow the test run down dramatically.
Configuration:
OS: Windows 7 64-bit
Selenium grid: v2.46.0
IEDriver: 32-bit
v2.46.0.0 (Tried using 64 bit but sending keys went very slow)
Browser: IE11
Thanks in advance for thoughts you might have.
We ran into the same problem and noticed that every character typed using sendKeys() consumes around 2 MB (!) in IE. We now restart the driver every 10 tests, which works for us.
Note: you could try replacing webElement.sendKeys with a Windows API call like SendInput and see if the problem in IE still remains.