It can slow my tests down?

This is something that seems very obvious when you stop and think about it, but it is surprising how many people don't.

Something that we all do from time to time in our tests is check that something doesn't exist. For example, you may have a phone book application, and you want to check that clicking on the delete link removes a contact from your phone book and no longer displays that contact on the screen.

The obvious thing to do is delete the contact and then try to find the elements on the screen that were used to display the contact. Let's say that, in our example, we have four elements that we display for a contact:

  • Name
  • Number
  • Type of number
  • Address

When we delete a contact, we want to make sure that all four elements are removed from the screen, so we check them one after the other. The problem is that we have set an implicit wait of 15 seconds. This means that each time we try to find an element, Selenium waits for 15 seconds to allow the element to appear, before reporting back that it cannot be found. We have inadvertently added a minute to our test's run time, when these checks could have been performed in under a second.

As you can see, the more times we check that something is not there, the slower our tests get, until, before you know it, we have a 2-hour-long test run that nobody bothers to run anymore because it takes so long and it's just quicker to check it manually.

Now, there are ways around this: we could change the implicit wait timeout before each test that checks for the non-existence of an element, and then change it back again afterward. The problem is that it doesn't take long for somebody to slip up and forget to do this. Before you know it, your test execution time has started increasing, and you have to go hunting through the code to find out what is wrong. The worst-case scenario is that it happens slowly over a period of time, so you don't notice the odd 15-second increase in the time it takes to run your tests. By the time you do realize, the code is riddled with excessive waits.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.202.45