9 Understanding timeouts

 

This chapter covers

  • Understanding and avoiding the causes of timeout errors in Protractor
  • Waiting for specific changes in your application, rather than relying on browser.sleep()
  • Understanding flakiness and eliminating it with Protractor

Now that you know how to make basic end-to-end tests for Angular apps, let’s talk about one of the most frequent issues you might run into. Timeout errors are the most common problems people encounter when using Protractor for the first time. Understanding what causes them and how to fix them requires a clear understanding of how browser tests run. You’ll also need to know what Protractor is doing behind the scenes to make tests more reliable by waiting for Angular to be stable while running a test.

In this chapter, we’ll explore how to avoid the common timeout-related pitfalls that new Protractor users stumble into. On the way, you’ll learn how Angular’s change detection works and how Protractor integrates with it. You’ll also learn some advanced techniques for making your own waiting logic. You can find the example code from this chapter at https://www.manning.com/books/testing-angular-applications and http://mng.bz/6k1S.

9.1 Kinds of timeouts

9.2 Testing pages without Angular

9.2.1 Disabling waitForAngular

9.2.2 Automatically waiting for Angular

9.2.3 When to use browser.waitForAngularEnabled()

9.3 Waiting with ExpectedConditions

9.3.1 Waiting for the contact list to load

9.3.2 Testing a dialog

9.3.3 Waiting for elements to become stale

9.4 Creating custom conditions

9.4.1 Using browser.wait

9.4.2 Getting elements from the browser

9.5 Handling long-running tasks

9.5.1 Using expected conditions

9.5.2 The browser event loop

9.5.3 What happened to $timeout?

9.5.4 Highway to the Angular zone

9.5.5 Fixing the test

Summary

sitemap