I currently have setup some tests using protractor. These tests are retrieving data from a WebApi. However, I want to point the WebApi calls to a real but mocked WebApi that just returns the objects I want to use as test data.
For example, the current request is:
http://localhost/myApp/api/profile/getUser/1
I want to manipulate this request so the test will use:
http://localhost/myApp/apiMock/profile/getUser/1
First I thought to write an interceptor that changes the request header but I don't have a clue how to make this work with Protractor. I can't use angular directly within my protractor tests, can I? If I can, writing the interceptor isn't a problem, I just don't know how to plug it in for my tests in protractor.
I've read the following post: E2E and Mocking but it doesn't fulfill my needs as I don't want to call the same url over and over again, I want to replace (part of) the dynamic url to point to the mocked api service.
Just to make myself more clear, I'm not looking for mocked data on the client side. I want to keep the API calls (in my opinion it's more E2E) but just point to another API url that returns mocked data.
angular.constant
then injected in your service. And your protractor test you replace the base address by the mock one ('apiMock'). – Allinclusiveptor.addMockModule
. eitanp461.blogspot.fr/2014/01/advanced-protractor-features.html – Allinclusive