I'm trying to write some end to end tests for our application's login process, but am having trouble getting my head around the best way to set up the scenario where the user needs to change his password.
When our server responds to a successful login, a user object is returned with a changePassword
field. The client then inspects the response and redirects accordingly.
My problem is getting the test set up so that the changePassword
field is set - what is the best approach to use?
I see my options as:
Have a test set up and tear-down script for the server that creates a brand new user specifically for the test run with
changePassword
flag set in the database.This seems like the most end to end approach, but is probably also the most effort & code.
Somehow intercept the http response in the test and modify the
changePassword
flag to be set for this test only.Mock the http response completely. Using this approach is the most removed from an end to end test, but is perhaps the simplest?
Which is the best or most common approach? Also any general pointers on how to actually implement the above (particularly 1 and 2) with protractor would be great - I'm finding it hard to conceptually get straight in my head, and hence hard to know what to search for.
I'm using protractor as the test framework, with angular.js powering the client side, and a node server running utilising (among other things) express.js and mongoDB.
I think your first approach is the most appropriate.
It would be useful anyway to test the new user creation, so it is not a waste. And for example this example seems to be something similar: http://product.moveline.com/testing-angular-apps-end-to-end-with-protractor.html
Having thought about this further, option 1 is the best solution, but is not always possible.
Option 2 is also possible, and option 3 should be avoided.
For option two, a mock module can be created like so: (coffeescript)
You can then inject this module into your tests using
If you want to do this globally, you can put this in the
onPrepare
function in your protractor file, otherwise just call it when needed in tests.