2

My angularJS application using event-steaming and it keeps open the http event-steam request and listening server events. So my problem is when protractor start testing of my angularJS application, it keeps wait to complete event-stream request as i am using ignoreSynchronization=false so protractor waits until it gets timeout as event-stream http request never going to finish. So i would like to teach my protractor to ignore such event-stream $http tasks and proceed testing of my application. These event-stream is implemented throughout of my application so every time there is event-stream request then protractor getting timeout.

The following error i am getting when its timeout: Failed: Timed out waiting for asynchronous Angular tasks to finish after 300 seconds. This may be because the current page is not an Angular application. Please see the FAQ for more details: https://github.com/angular/protractor/blob/master/docs/timeouts.md#waiting-for-angular. The following tasks were pending: - $http: https://example.com/custom/xxx/sse

Can anyone please help me to get rid of this issue?

2 Answers2

3

In protractor you can add mocks. So actually what you could do is to add few mock modules to mock whatever you need.

If the issue is just related with the timeout of asynchronous requests timing, you can also change that timeout value from the protractor.config.js, increasing it.

By the way, coming back to the mocks, you define mocks and add them in protractor through the browser.addMockModule method.

Here a good article about mocks in protractor:

http://eitanp461.blogspot.ie/2014/01/advanced-protractor-features.html

And here a good npm module in order to facilitate you mocking angularjs $http requests:

https://github.com/atecarlos/protractor-http-mock

This could be a little example of the mock module directly without using the node module above:

browser.addMockModule('httpMocker', function() {
  angular.module('httpMocker', ['ngMockE2E'])
  .run(function($httpBackend) {
    $httpBackend.whenGET('MYURL')
    .respond("MOCKED RESPONSE!");
  })
})

You can define mocks directly inside the tests too, but if you want that globally in your tests, I suggest you to directly define your mocks inside the onPrepare method inside the protractor.config.js.

I hope it helps

quirimmo
  • 9,800
  • 3
  • 30
  • 45
0

Thanks @quirimmo for your valuable response.

We can achieve timeout issue without using mocked backend calls by simply modifying http request and setting timeout to http request so that protractor waits till the request get timeout which we already set(Timeout will close the long running http requests) and executes further statements.