protractor icon indicating copy to clipboard operation
protractor copied to clipboard

Avoid waiting for $timeout()s

Open pidupuis opened this issue 10 years ago • 11 comments

The issue https://github.com/angular/protractor/issues/169 is closed but a lot of people would like a real solution for this so I (re)opened this issue.

pidupuis avatar Feb 17 '16 16:02 pidupuis

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?

heathkit avatar Feb 17 '16 20:02 heathkit

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

pidupuis avatar Feb 18 '16 13:02 pidupuis

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

heathkit avatar Feb 18 '16 20:02 heathkit

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

innanill avatar Feb 22 '16 22:02 innanill

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.

juliemr avatar Feb 23 '16 19:02 juliemr

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.

heathkit avatar Feb 23 '16 20:02 heathkit

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.

heathkit avatar Feb 24 '16 19:02 heathkit

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.

heathkit avatar Mar 18 '16 08:03 heathkit

The plugin is now available on NPM https://www.npmjs.com/package/protractor-xhr-only-plugin

heathkit avatar Mar 24 '16 21:03 heathkit

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

AlexandrosD avatar Nov 24 '16 18:11 AlexandrosD

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

yadimon avatar Sep 24 '20 13:09 yadimon