Restarting browser after every feature file cucumberjs - selenium-webdriver

Currently we have an automation framework built using cucumberjs/protractor. As is now, all of our tests run in one browser instance.. this causes issues with our mocking system as it causes instabilities as more and more tests run. What is the easiest solution to make cucumberjs tests kick off a fresh browser instance at every new feature file? Would it include configuring the hooks.js?

Create a before hook in your hooks.js:
this.Before(()=> {
this.browser.restart();
})
http://www.protractortest.org/#/api?view=ProtractorBrowser.prototype.restart

Related

What can I use for mock fetch-requests while e2e testing in protractor similar to addMockModule without Angular

I am writing e2e test with protractor for a typescript module. I want to use protractor for the additional features in comparison to selenium webdriver. I am using typescript standalone so I am building a non-angular application.
I searched a lot for mocking services or fetchmock etc. But I think I am searching at the wrong place. Maybe I just didn't understood what do I really need for my problem.
At the moment I have an application where I want to test the frontend. My problem is, that the application only works with a server which is setting up many data and make it available for rest. Without this server my javascript file wont work and I wont start the server for my tests, it must be server independent.
For example: my server provide the data on a specific address 192.168.1.230 and I can fetch the data with fetch api over: 192.168.1.230/users/1.
In unit tests I have mocked my fetches, but in e2e tests I need to mock the address (maybe with selenium webdriver) and want to get a dummy response if my api is fetching this data.
How can I realise that? I use protractor with npm (nodejs) and could need a npm plugin for this.
I saw another post here with the addMockModule, but this is only for angular modules and I don't use angular.

Reuse Browserstack session in Junit tests

I have been developing JUnit tests using Selenium webdriver and I test them on BrowserStack.
It works when:
I keep all my selenium scripts in one test method.
I keep my scripts in different JUnit test methods, as they open their own sessions and run smoothly.
I now want each of my Test methods to use the same BrowserStack session (to reduce total run time). Is this possible? I have read somewhere about intern framework a little, but do we have any other simple way to achieve this?

Export selenium IDE test scripts to Protractor

I have automated some flows om my Web Application (on Angular JS) with Selenium IDE. Now after a new deployment my current test scripts have gone outdated since all the xpaths have been changed. Is there a way to Export my test cases to protractor, or any easy way to update my test cases using Selenium IDE without investing same effort and time again?

Detect if the environment is Protractor

In an AngularJS application is it possible to detect if the environment is Protractor?
I would like to disable certain functionality such as Geolocation when running my tests. It's not something I want to test at the moment and I am pretty sure it is what is causing my tests to fail to run.
In my App I use window.jasmine to disable certain polling actions when running Jasmine tests so something similar would be good.
i.e.
if(!window.protractor) {
geoLocationRun()
}
This doesn't work and there doesn't appear to be anything I can use on Window.
Note: I know I can mock out the geolocation which I can do if this isn't possible. Perhaps this is the best approach in any case however it would be good to know if there is a suitable solution. How do I enable geolocation support in chromedriver for Selenium?
I would recommend you to move your geo location code into an angular module. Then you can mock the module in your protractor tests using browser.addMockModule
http://angular.github.io/protractor/#/api?view=Protractor.prototype.addMockModule

With Travis-CI, how do I test chrome packaged apps?

I am writing a chrome packaged app, using angular JS.
My setup uses grunt/karma/jasmine for building/unit testing, and everything was fine until I started using the chrome.* API. This of course was an issue as I had Travis-CI set up to use PhantomJS, but Phantom doesn't know about the chrome global var.
Is there a way to run unit tests with karma that will not throw ReferenceError: Can't find variable: chrome for testing packaged apps, and so pass Travis-CI testing
Is there a way to suppress the errors that PhantomJS is throwing (this sounds bad already)
Few thoughts:
You could polyfill/stub the chrome.* apis before running your tests, to simulate the chrome app environment. Not sure if anyone has already done this already (i.e. here is one quick example for node-webkit I found). It sounds like a useful library someone should write ;)
Just skip those tests that you know will always fail on PhantomJS, by wrapping jasmine test definitions with a guard like if (!is_chrome_app) return;. One clean way to do this in jasmine is to create a defineChromeAppOnly helper that skips the define call if its not a chome app.
You probably want an alternative system for actually running tests inside a real chrome app. I've always just built my own crude CI for this (or done it manually), but since this would be cool to make easier for CI, I've filed a request with Travis CI Team to support Chrome Packaged Apps. Star that issue if you are interested in what they reply.

Resources