I have a RESTful API, and now I am developing an angular2 application that uses data services to call the API. Then I wanted to implement end-to-end tests using a protractor. I wanted to start at a very low level, so I ran tests to check if my components are present when I click on the link. The test is as follows:
describe('my-webclient', () => { it('app should load', () => { browser.get('/'); expect(element(by.css('my-app')).isPresent()).toBe(true); }); it('app should have a top navigation', () => { expect(element(by.css('my-nav-top')).isPresent()).toBe(true); }); it('app should have a side navigation', () => { expect(element(by.css('my-nav-side')).isPresent()).toBe(true); }); it('app should have a content', () => { expect(element(by.css('my-content')).isPresent()).toBe(true); }); it('app should load the overview for route "/"', () => { expect(element(by.css('my-overview')).isPresent()).toBe(true); }); });
The problem is that the browse component performs HTTP requests in the ngOnInit function using some data service. The protractor will simply be blocked forever, although HTTP requests have long been completed.
When I control the test, I see how the application loads, including all the data received from my API. Then nothing happens, and the protractor ultimately fails, saying that a timeout has been reached.
The exact error message is:
Failed: Timed out waiting for Protractor to synchronize with the page after 11 seconds. Please see https://github.com/angular/protractor/blob/master/docs/faq.md While waiting for element with locator - Locator: By(css selector, my-app)
When searching for help on google, I came across a few tips that the protractor will wait for angular to finish everything. Well, thatโs exactly what I want. When I track the network tab in the developer chrome tools ( F12 ), nothing appears shortly after downloading the application. Thus, there are no more pending requests or anything else for the protractor. However, this is so, and I just donโt know why.
So here is my question . Do I have to consider something special when working with data services that handle HTTP requests? Or: what can I do for debugging, why the protractor is still waiting until the timeout expires.
By the way, this is definitely a data service. If I comment on everything inside the OverviewComponent::ngOnInit , then the tests will go exactly as expected.