Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

browser.ignoreSynchronization #973

Closed
Ronsku opened this issue Jun 25, 2014 · 14 comments
Closed

browser.ignoreSynchronization #973

Ronsku opened this issue Jun 25, 2014 · 14 comments

Comments

@Ronsku
Copy link

Ronsku commented Jun 25, 2014

Hi,

I have been trying to search for answers for a day now. My simple protractor test doesn't work unless i have set:
browser.ignoreSynchronization = true

If i have browser.ignoreSynchronization = false (as it is by default) it gets stuck in the first thing that should be synchronous, expect browser.get('') works!

I have a login script in my onPrepare on my config, works fine:
enviroinment.js: http://jsfiddle.net/LrgDz/
config.js: http://jsfiddle.net/PEJj3/

I have ng-app tag in 'html' tag.

login.spec.js: http://jsfiddle.net/8rQ3n/

This makes no sense. I've tried everything it feels like.

  • I have the newest version of protractor and angularjs.
  • Login works without any problems, but after that I cannot get anything to work without 'browser.ignoreSynchronization = true'.

appConfig.js: http://jsfiddle.net/rn37U/

Please help me!

Best regards,
Ron

@juliemr
Copy link
Member

juliemr commented Jun 25, 2014

Are you sure that there are no long $timeout requests or polling $timeout requests on the page? See https://github.com/angular/protractor/blob/master/docs/faq.md#my-tests-time-out-in-protractor-but-everythings-working-fine-when-running-manually-whats-up

@Ronsku
Copy link
Author

Ronsku commented Jun 25, 2014

Wow, you're good! Thank you so much, it all makes sense now! :) Going to try to get it working now!

@juliemr
Copy link
Member

juliemr commented Jun 25, 2014

Hm - you can use the $interval service, which protractor does not wait for. I wonder if either of these is the best thing to do for an automatic logout though - generally that would be something that the server would initiate?

@Ronsku
Copy link
Author

Ronsku commented Jun 25, 2014

Good point! Going to type my solution here when I find a good one! You're the best, thanks again! :)

@Ronsku
Copy link
Author

Ronsku commented Jun 30, 2014

I fixed this by changing $timeout to $interval like you said. Works perfectly!

@ghost
Copy link

ghost commented Jul 1, 2014

Julie,

What needs to be done when we are using some third-party service (such as pubnub) and this third party service is constantly polling the server ?

Is there a workaround ?

@hankduan
Copy link
Contributor

hankduan commented Jul 1, 2014

I think you just have to set ignoreSynchronization to true or change that service to angular's $interval service (https://docs.angularjs.org/api/ng/service/$interval)

@enricorotundo
Copy link

In the previous days i fought with the same protractor timeout issue and replacing $timeout with $interval seems working but considering that:

  • i'm new with angular and protractor
  • i'm working on a web app written by other guys, not me: i don't know why they used $timeout instead of $interval
  • i struggled more than one day to figure out a solution
  • out there're lot of posts saying to just set the browser.ignoreSynchronization = true property

@juliemr, i think that angular documentation should notice developers that using $timeout could leads to testing issues, what do you think about it? Furthermore, according to the $interval API, all intervals created must be manually destroyed meanwhile $timeout not: a simple batch replace couldn't be appropriate, forcing me to return back in the code to destroy the intervals.

@stramel
Copy link

stramel commented Dec 16, 2014

What is the update? It doesn't make sense to me that either of these could be the "accepted solution". I have an application that doesn't poll at all and loads within 5.46s but even setting timeouts to 60s it still doesn't synchronize.

  • browser.ignoreSynchronization = true - seems hacky
  • replacing $timeout with $interval - Testing code should not affect how you structure your application

@juliemr
Copy link
Member

juliemr commented Dec 16, 2014

@stramel I'm happy to hear other ideas. We're constrained by the basic fact that we're trying to figure out when the webpage is stable (done with anything asynchronous that would cause race conditions).

The way we do that is having angular keep track of http requests, promises that are pending, and pending timeouts. So, if you always have a pending timeout, you page will never be marked as stable.

@stramel
Copy link

stramel commented Dec 18, 2014

@juliemr Is there a reason promises are part of marking it as stable?

@stramel
Copy link

stramel commented Dec 18, 2014

I can find elements but performing actions is causing timeouts with ignoreSynchronization = false;

describe('New Retail Web homepage', function() {
  it('should log in', function() {
      var orderType, elem;

      browser.get('/');
      orderType = element(by.repeater('orderType in orderTypes').row(0));
      expect(orderType).toBeDefined();
      orderType.click(); // Works with this line commented out

     // ... more code here
  });
});

@juliemr
Copy link
Member

juliemr commented Dec 18, 2014

Here's the things that we test against, including stuff like "http request then promise": https://github.com/angular/protractor/blob/master/testapp/async/async.js

The philosophy is that we want to make sure you don't get race conditions, so asynchronous actions on your page should be completed before you do the next action.

It's impossible to debug your specific case without knowing what the application is doing when you click.

@shendrix
Copy link

shendrix commented Oct 9, 2015

Is there any way to have ignoreSynchronization = false; and have Protractor ignore $timeout requests?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants