Running Karma with Coverage is failing to shut down Firefox - karma-jasmine

I am running Karma, Jasmin and Instanbul on Windows 10 and test against ChromeHeadless, FireFoxHeadless and MS-Edge.
The tests all run just fine and the coverage output is written. BUT... Firefox never closes. I get this error:
WARN [launcher]: Firefox was not killed in 2000 ms, sending SIGKILL.
If I don't test with Firefox, everything works fine.
If I don't use coverage, everything works fine.
If I make Firefox non-headless then it still fails in the same way
If I use JUST Firefox then it still fails in the same way
I have spent over 2 weeks trying to find an answer here on StackOverflow and all over the internet. There were similar problems reported but no one ever had a definitive answer related to Firefox and Coverage.

AWESOME!!!!!!! I figured it out.
I asked someone a question and their answer got me thinking about timeouts and I changed the following values in my karma.conf.js file and now it is working:
browserDisconnectTimeout: 10000,
browserDisconnectTolerance: 1,
processKillTimeout: 100000,
It seems that the coverage reporting was taking too long and just extending the timeout makes it work fine. The default timeout is 2000ms.
It seems that something related to Firefox takes longer to write out the Firefox coverage files and that was taking longer than 2000ms. This was leading to the error I was seeing.
Increasing the timeout allows everything to be written and Firefox to shut down correctly.

Related

Setting up selenium, chromedriver, and wdio mixed with vagrant or docker

I started out trying to learn how to write automated tests for a small project but nothing was working right out of the box. After a couple hours of searching & experimenting I found the right configuration for my project & figured sharing it might help folks in the future.
Here's a small summary of the errors I encountered on this debugging journey:
Using Jasmine & WDIO, send_keys was crashing
It was a Firefox/geckodriver bug, or something like that
WDIO appeared to hang after switching from Firefox to Chrome
Chrome needed to be run in --no-sandbox mode, essentially
I figured my problem was probably stemming from having WDIO execute my tests on my local machine while Selenium was hammering on the browser in a Vagrant VM. So this will mainly be applicable for people using separate environments (vagrant->local, vagrant->vagrant, docker->local, etc) for WDIO & Selenium/Chromedriver. Here is a gist of the configuration file I ended up with.
I started with fanatique/vagrant-selenium-vm and modified it to use Chrome instead of Firefox because send_keys was broken with Firefox/geckodriver at the time of writing. After swapping out the packages, I'd start the tests with wdio but it would appear to hang. Turning on verbose logging showed it trying to start but failing with no explanation why.
[00:06:39] COMMAND POST "/wd/hub/session"
[00:06:39] DATA {"desiredCapabilities":{"javascriptEnabled":true,"locationContextEnabled":true,"handlesAlerts":true,"rotatable":true,"browserName":"chrome","loggingPrefs":{"browser":"ALL","driver":"ALL"},"requestOrigins":{"url":"http://webdriver.io","version":"4.6.2","name":"webdriverio"}}}
It took removing the & from the nohup java ... command in fanatique/vagrant-selenium-vm's setup.sh to see the logs from Selenium in real time, then I was able to see a "only local connections are allowed" message from chromedriver. That led me to a SO post that said to add --whitelisted-ips="" as an arg to chromedriver - but I was still getting the local connections error message. Chrome itself ended up needing a --no-sandbox flag - that allowed WDIO to connect to the chromedriver in Selenium and my tests ran from there.

BrowserStackLocal.exe suddenly stops. Windows 10

While running some UI tests with selenium, I am running BrowserStackLocal.exe and I use this command:
BrowserStackLocal.exe --key browser stack license
And everything seems to run pretty good but after around half an hour, the process suddenly stops making my selenium tests fail because they can't reach the target URL.
I am running a windows 10 machine.
Has anyone experienced this before?
Thanks in advance.

Protractor internet explorer tests unstable

I have a angular web application that I want to make protractor tests for the page, And I must run the tests with Internet explorer browser.
However, the tests are not stable, sometimes they all work, sometimes few tests fail randomly.
I am having this issue from 1 month now and I still cannot find solution, here what I tried so far:
Running IEwebdriver explicitly in 32bit or 64bit.
Deleting cache and session after every test.
Increased timeouts in conf.js to 200000.
Adding protractor expected conditions(http://www.protractortest.org/#/api?view=ProtractorExpectedConditions)
Making sure using .then after every function that returns promise.
The reasons of tests failing is slowness of internet explorer, and that it waits for element to be clickable(using protractor expectedconditions) but the element is never clickable, and when I look at the webdriver-manager I see that it trying to do the same lines over and over again.
I am sure that my tests are correct and working fine and I am sure that the browser is the problem.
Can you help? Thanks

FireFox still not working for Protractor/Selenium tests?

I have a project suite of automation tests that uses Protractor and Jasmine. As of a couple months ago, my tests stopped working in FireFox. Everything works perfectly in Chrome, and almost perfectly in IE.. because why would IE work ya know.
There have been multiple posts about this and I've read through all of them, but I haven't been able to determine if there's a workaround/solution to this. It's not entirely a HUGE deal if my tests run in FireFox, but with a web application it's mighty nice to be able to test all instances.
Basically what happens when I run a test in FireFox:
Command prompt acts like everything is about to run properly (FireFox driver starts up.. server remains running etc etc)
Firefox opens for a split second (icon appears on the task bar, browser flashes on the screen and closes)
After a good minute or so protractor gives me the following message:
[firefox #01-0] WebDriverError: Unable to connect to host XXX on port XXX
after 45000 ms.
With a ton of DEBUG lines referring to JSON files and Firefox addons.
Any thoughts or other sources I could check out would be sweet. Many thanks in advance.
Problem is with latest Firefox support from latest selenium-server. Use geckoDriver and it will work.
Follow this URL

PhantomJS: Slow from CI(Jenkins) server, but faster when executed from developers machine(Windows)

I am having a really hard time figuring out as to why the selenium test cases are running slowly with phantomjs ghostdriver. When the developers run the test cases against the dev environment it runs faster(takes 1 hour to complete 5 test cases), but when ran from jenkins, it takes 4 hours.
I turned off the IPV6 on the dev machine, also tried switching to version 1.9.1, but still no improvement on the time taken.
Jenkins Machine
phantomJS: 1.9.2
Jenkins Server: RHEL 5.6 64 bit
JDK: 1.7
Developer Machine
OS: Windows 7 64 bit
JDK: 1.7
phantomJS: 1.9.2
Can someone please help?
Thanks in advance
Are you using driver.quit() or phantom.exit() after each test case as phantomJS process not get killed automatically. If no then it could be the reason of slowing down your test cases.
If your tests do not quit the drivers, your jenkins box will have a lot of open browsers in memory after a while.
For instance, every test that starts, then asserts false somewhere and dies, leaves an unclosed driver. These tend to build up after a while.
Depending on your testing framework.. there may be good solutions around it other than wrapping each test in their own try/catch blocks.
py.test has great fixture functionality. You can have a phantomjsdriver() fixture that opend the browser for each test, then after the test is done (safely, or aborting from a False assertion) it can finalize and close up the driver.
psudocode example: (py.test, python, selenium)
#pytest.fixture
def phantomdriver(request):
driver = webdriver.phantomJS()
def fin():
driver.close()
request.addfinalizer(fin)
In this situation, every test that uses this fixture, no mater how it exits, will end up calling the finilizer fin() to close it.