Pramod
Pramod

Reputation: 41

Need to access my angular service in protractor test cases

I am writing e2e test cases using protractor for my angular application. I have a service in my application called UserService which holds user information. I have an API getUser in this service to get the user data. I need to access UserService in my protractor test cases.

I looked at some of the articles and found that I could use browser.executeAsyncScript to access my services. But If I use this method , I am gettiing the injection issue.

In my application, the module is defined as:

var angApp = angular.module('myApp', ['ngCookies','ngResource']); 

and all directives, services and controllers are created using angApp module.

Now I need to access my UserService so that I can call getUser API in my protractor testcases.

Could someone help me in accessing userService in my protractor testcases?

Upvotes: 2

Views: 1964

Answers (1)

Andrew Eisenberg
Andrew Eisenberg

Reputation: 28757

The problem that you are facing is that protractor tests are run in a separate process from the browser. Any script that runs in the browser is not directly accessible to your protractor tests. There is no way to directly transfer data between the two (the best you can do is interact through the DOM).

I'm guessing that your UserService is some kind of CRUD API for manipulating Users on the server. My recommendation would be to make REST requests directly from the protractor tests to the server in order to get the users. It will not be easy to share code between the tests and the app.

Upvotes: 3

Related Questions