How to clear session using selenium and phantomJS - selenium

I have a series of automated tests that use selenium, specifically Geb with Spock. When I run all my tests cases one after another using a chromedriver, my tests run fine. Each test method gets a new session and therefore start with a fresh browser each time. This is not the case when using phantomJS. If a test method happens to fail when using phantomJS, all following test cases will fail because the session was not reset. I can see this happening because the screenshots taken at the end of each test method.
I have tried researching this issue and have discovered it has been a known issue for a couple of years now. Some say it was fixed in phantomjs 2.1 but I'm currently using version 2.1.1, which is the most recent version.
I have also tried using driver.manage().deleteAllCookies(); with no luck, as other threads have mentioned.
Is there a workaround anyone is aware of?

have you tried webdriver's quit method?

Related

How does the elixir community recommend setting up integration tests with chromedriver?

I am using Hound (https://github.com/HashNuke/hound) for integration testing a Phoenix application. I have chrome and chrome headless working. To get it working I have another terminal window running chromedriver (installed via brew). This feels odd to me. Is there a library or test setup that would feel more "integrated" into the application? What's the Elixir way of doing this?
In the Ruby world there's the webdrivers gem (https://github.com/titusfortner/webdrivers). As far as I know it downloads a specified driver (lets say chromedriver) to $HOME. Then with every test run, the test uses the driver downloaded to that destination to execute the tests.
Before the webdrivers gem there was chromedriver-helper gem. Before that it was phantomjs. These implementations made it so running integration tests required 1: downloading the driver 2: running the test
In Elixir (with Hound) I have my tests working by first running chromedriver --verbose in a terminal split, and in the other screen I run mix test. This works fine but feels disjointed. This adds extra steps, 1: download the driver 2: start the driver 3: run the test 4: stop driver
I could write a script manually to run chromedriver in the background, and stop it after the tests are run.
I am new to the Elixir community and so I've researched a lot. It's still not clear to me if there is a "traveled path" I should go down vs just hooking everything up manually.
Have I missed a recommended abstraction? Is this intentional? Is this "just not created, yet"?
Thank you
Have you checked out wallaby? See https://github.com/keathley/wallaby

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

Slow running acceptance test with php + codeception + phantomjs

I am moving to codeception 2.0.3 for doing some tests in various web platforms I am developing. I started doing some acceptance testing. Mainly check for pages ok and doing some form completions (sign in, sign up, nothing fancy).
I have been monitoring tests with firefox browser and we are moving now tests to a dedicated server so I switched to phantomjs as my testing browser.
Configuration in acceptance.suite.yml
WebDriver:
url: 'localUrl'
browser: phantomjs
window_size: 'maximize'
capabilities:
phantomjs.cli.args: ['--ignore-ssl-errors=true']
The thing is that with this headless configuration, tests are running very slowly. I mean, the test I wrote is checking that four links are OK (no error or exception message) without any fancy assertions (something which I can check in less than 20 secs) and it is taking more than a minute a half.
Am I missing something in the configuration of the testing stack? I read that phantomjs testing in this way is supossed to be fast and reliable something that can be integrated while developing but I don't seem to get it working right. I have been doing TDD in Smalltalk and maybe I am a little biased with the way that things work in that environment so maybe my expectations are too high but I had hopes that this could be a little more responsive and easy going.
I am using codeception 2.0.3 with phantomjs 1.9.7 on a linux box with php 5.5.
Any suggestion is welcomed. Thanks!!!
I had very slow running tests and started using strict locators. That sped up things a lot.
Instead of writing:
$I->fillField('username, 'john');
which will try and fail many locator types before actually working, specify the locator you are using and write:
$I->fillField(['id' => 'username'], 'john');
or
$I->fillField(['class' => 'username'], 'john');
or
$I->fillField(['css' => 'input .username'], 'john');
Read here: http://codeception.com/docs/04-AcceptanceTests#Click
Could be problem with phantomjs, usually headless with Codeception PhpBrowser goes very fast, try to switch to it.
For in-browser try to use Codeception WebDriver + latest selenium 2 standalone.
Also if you are developing with some framework, you can check if it is present in Codeception modules list. If so you can use it, it runs much faster than PhpBrowser since it does not need any server and works with symfony dom - crawler and browser - kit.
The size of the database sql file also matters. In my case import of some big tables caused more than minute of additional time.

Starting and stopping Selenium as a Grunt task

I'd like to start Selenium as a Grunt task, run Cucumber, then stop Selenium after Cucumber exits.
I tried using grunt-shell to start Selenium. While this works, Selenium continues to run (as expected) and so Grunt hangs waiting for it to exit.
I also tried grunt-bgshell. This starts Selenium, but Grunt immediately starts Cucumber before Selenium is ready, and then Selenium continues to run after Grunt exits.
As a workaround for stopping Selenium I could probably use shell and curl to send the shutdown request to Selenium. But if there's a way to accomplish this without a workaround that would be even better.
Update
See my answer below:
David Souther has written the grunt-selenium-launcher plugin which does exactly what I needed.
However, even after using the grunt-selenium-launcher plugin, Julien Biezeman helped me discover the best way to solve my problem was to launch selenium directly from my end to end tests in Cucumber using selenium-launcher.
I hope this helps someone!

Selenium & C# - run test cases sequentially for all browsers

I am using Selenium (WebDriver) and C# and have a question regarding running tests.
I have developed a number of tests and they are all working as I expect. I am able to execute them in FireFox, IE and Chrome but I have to manually alter the definition of my driver initialization between runs.
What I want is to run all tests in IE, then re-execute in Chrome then once more in FireFox and I have not figured out how I could do that.
Anyone done something similar?
Any thoughts are appreciated.
Thanks
Sean