Angular e2e tests affecting database

Here is my problem, step by step :)) I thought it was better read this way, unlike a wall with text, plaintively trying to explain my specific problem for the domain.

1) We have a Angular.jsc PHPsupported application MongoDB.

2) Protractorfor end-to-end tests.

3) It is necessary to test pages that modify the database, i.e. registration script - I look through all the stages of registration in the test, so db gets a new user record.

4) As expected, the test will fail with its launch, since db has an entry for the test user, and registration is not required - instead, the user is redirected to the main page.

I was thinking of getting a package MongoDBfor node.jsand interacting with the database in tests.
But this just doesn't seem right: the configuration files for connecting to the database are in the files PHPon the backend, while I am trying to write tests for the purely input part of our application.

Any ideas?

+4
source share
2 answers

Is there an easy way to do this. If your application has an angular service that speaks to your content, you can call it from the protractor.

Here is an example:

https://github.com/andresdominguez/protractor-meetup/blob/master/test/e2e/api-helper.js

function createObject(data) {
  return browser.executeAsyncScript(function(data, callback) {
    var api = angular.injector(['ProtractorMeetupApp']).get('apiService');
    api.member.save(data, function(newItem) {
      callback(newItem._id);
    });
  }, data);
}

. apiService ProtractorMeetupApp. api , ..

:

https://github.com/andresdominguez/protractor-meetup/blob/master/test/e2e/member3-spec.js

it('should call api', function() {
  // Create a new member.
  createObject({name: 'test member'}).then(function(id) {
    console.log(id)
  });
});
+3
+1

All Articles