Reputation: 3797
I am running multiple specs using a Protractor configuration file as follows:
...
specs: [abc.js , xyz.js]
...
After abc.js
is finished I want to reset my App to an initial state from where the next spec xyz.js
can kick off.
Is there a well defined way of doing so in Protractor? I'm using Jasmine as a test framework.
Upvotes: 1
Views: 3212
Reputation: 3025
You can use something like this:
specs: ['*.js']
But I recommend you to separate the specs with a suffix, such as abc-spec.js
and xyz-spec.js
. Thus your specs will be like this:
specs: ['*-spec.js']
This is done to avoiding the config file to be 'run'/tested if you put the config file in the same folder as your tests/spec files.
Also there is downside that the test will be run in 0 -> 9
and A -> Z
order. E.g. abc-spec.js
will run first then xyz-spec.js
. If you want to define your custom execution order, you may prefix your spec files' names, for instance: 00-xyz-spec.js
and 01-abc-spec.js
.
To restart the app, sadly there is no common way (source) but you need to work around to achieve it. Use something like
browser.get('http://localhost:3030/');
browser.waitForAngular();
whenever you need to reload your app. It will force the page to be reloaded. But if your app uses cookie
, you will also need to clean it out in order to make it completely reset.
Upvotes: 3
Reputation: 2910
The flag named restartBrowserBetweenTests
can also be specified in a configuration file. However, this comes with a valid warning from the Protractor team:
// If [set to] true, protractor will restart the browser between each test.
// CAUTION: This will cause your tests to slow down drastically.
If the speed penalty is of no concern, this could help.
If the above doesn't help and you absolutely want to be sure that the state of the app (and browser!) is clean between specs, you need to roll out your own shellscript which gathers all your *_spec.js
files and calls protractor --specs [currentSpec from a spec list/test suite]
.
Upvotes: 0
Reputation: 3797
I used a different approach and it worked for me. Inside my first spec I am adding Logout testcase which logouts from the app and on reaching the log in page, just clear the cookie before login again using following:
browser.driver.manage().deleteAllCookies();
Upvotes: 1