The last step requires us to wait for the API server to respond to our request, after which we should display a success message.
A naive, but very common, approach would be to wait a few seconds before making an assertion. However, this has two disadvantages:
- If the time set is too short, it can lead to flaky tests where the tests would pass on some instances, and fail on others.
- If the time set is too long, it'll lengthen the test duration. In practice, lengthy tests means the tests are ran less often, and less useful in providing feedback to the developer.
Luckily, Selenium provides the driver.wait method, which has the following signature:
driver.wait(<condition>, <timeout>, <message>)
condition can be a Condition instance, a ...