angular/protractor

Avoid waiting for $timeout()s

pidupuis opened this issue · 11 comments

The issue #169 is closed but a lot of people would like a real solution for this so I (re)opened this issue.

There was a feature added yesterday that allows plugins to skip waiting for $timeout and $http, but leaves custom plugin synchronization intact. Does this address the issue?

Not really, I would like something easier (like a protractor option).
And I would like to be able to avoid $timeout but not $http for instance

We'll look into this as a feature request and see what we can do about addressing it.

+1. We've run across this problem too and would like to see it fixed.

This is a difficult feature request because we'd like Protractor to work well by default, and waiting for anything deferred is deeply baked in to how we interface with Angular. Right now, waiting for any deferred behavior is all-or-nothing (note that you can turn off all waiting with browser.ignoreSynchronization = true. Also, you probably don't want to avoid waiting for all timeouts, just particular ones.

We could potentially do this with a change to Angular which would add a third parameter to $timeout - so if you wanted to ignore a particular call, you could do

$timeout(fn /* function */, timeout /* number */, ignoreMe /* boolean */)

Note that this is just a design idea now (not approved). Note also that this would require changes to the application code - there's not a clean way to say what you'd like to ignore from your test code.

Also, as mentioned in #169, you can accomplish this today by using $interval instead of $timeout for those callbacks you'd prefer protractor to not wait for.

We could also probably make a plugin that allows users to wait for outstanding $http requests but not for $timeout. It would require wrapping $http or $httpBackend and building a way of waiting on outstanding requests, instead of relying on $browser. There might be subtle edge-cases around doing that, but implementing it as a plugin in allows people to opt-in to that functionality if they need it.

Actually, on second thought, this could be done quite readily using interceptors instead of wrapping $http, I think. I'm traveling now, but I'll try to put something together next week.

If this feature interests you, please try this plugin: https://github.com/mgiambalvo/protractor-xhr-only-plugin. It adds the ability to switch protractor between waiting for all Angular operations (ie, $http and $timeout calls) and waiting for only outstanding $http requests.

Note that this plugin requires a feature added to Protractor 3.2.0, so you'll need to update before you can try it.

The plugin cannot be used with Angular 2.0 and Protractor 4.x.x though.. Issue remains..

for angular 2+ and protractor at least 5.x, i am developing this one:
https://www.npmjs.com/package/protractor-sync-options-plugin