Issue
[Testing angular 2 web app]
This error occurs with browser.ignoreSynchronization = false
when set to true, this error does not occur, why is this ?
I also have useAllAngular2AppRoots: true
set in my protractor config.
Solution
Protractor runs on top of WebDriverJS. WebDriverJS is a Javascript interface equivalent to Java's Webdriver that let's you control browsers programmatically, which in turn helps to write automated test cases
The problem in testing Angular apps using WebDriverJS is that Angular has its own event loop separate from the browser's. This means that when you execute WebDriverJS commands, Angular might still be doing its thing.
One work around for this is by telling WebDriverJS to wait for an arbitrary amount of time (i.e. 3000ms) so that Angular finishes its work of rendering but this was not the right way of doing things.Therefore Protractor was created to synchronize your tests with Angular's event loop, by deferring running your next command until after Angular has finished processing the previous one.
But again there is a catch here, this becomes problematic when you are testing Non-Angular Applications, Protractor keeps on waiting for angular to synchronise even though there is no Angular to complete its cycle and will throw an error which you are observing!
Thus, for non-Angular pages, you can tell Protractor not to look for Angular by setting browser.ignoreSynchronization = true
-- which in practical terms will mean that you're just using WebDriverJS.
So by adding that to your configuration when Protractor cannot find Angular on your page, you're giving up on all that makes testing Angular apps easier than plain WebDriverJS. And yes, adding browser.sleep after all your commands will likely work, but it's cumbersome, will break as soon as Angular takes longer than the pause you set, and makes your tests take excessively long.
Conclusion : Only use browser.ignoreSynchronization = true
when testing a page that does not use Angular.
Reference: https://vincenttunru.com/Error-Error-while-waiting-for-Protractor-to-sync-with-the-page/
Answered By - Ram Pasala
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.