Is Phantomjs session isolation still not working? - selenium

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.

Related

Testcafe caught in page reload loop

I have a set of Testcafe tests for our application, which since recently fails to run in some of our environments. The test only opens the browser, loads the start page specified in the fixture (or navigated to in within the test) and then only appears to continuously reload the page without proceeding with the test. This happening across all browsers (Chrome, Firefox, Edge) and different versions of NodeJs and Testcafe on Windows 10.
After enabling debug logging I found this message repeatedly in the log:
{
cmd: 'wait-for-file-download',
sessionId: '0X_DqYtz0'
}
The browser console also showed two page resources/scripts that failed to load with net::ERR_FAILED errors due to violating the Content Security Policy, so I assume that these might cause the problems. However it does not seem to have any impact on manual page interaction or automated test using other frameworks like PyTest.
While we are investigating on the conflicting resources, is there anything I can do in Testcafe to bypass the issue and allow the tests to run? Or alternatively is there a way to fail a Testcafe test when encountering this issue instead of reloading and possibly eventually timing out?

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.

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.

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

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.

Nightwatch.js - Use the same browser session

We would love to adopt Nightwatch.js for testing on browsers, but we're stuck on one major caveat: at the time of this writing, Nightwatchjs does not support running different tests using the same browser session. In short, it means that:
Creating the browser session is handled by the Nightwatch module from lib/index.js, in the startSession function;
Killing the browser would correspond to the delete command place in the Selenium action queue in the terminate function of that module;
A new Nightwatch client is created at every test run, which happens every time we load a different test file;
According to this source, it is possible to reuse the current browser session in Selenium, instead of opening a new window.
Has anyone managed to fix this problem in Nightwatch?
Here's the feature request on Github, which was requested on Mar 31, 2014 and is still open.
Another approach would be to circumvent the problem altogether by getting Nightwatch to merge all different files into one Test Suite, but that seems to be harder to solve than the problem with sessions...
Nightwatch now has support for resuing browser sessions. You can simply use the flag --reuse-browser to reuse sessions while running your nightwatch tests.