Skip to content
SDETRole
SDETRole

Replace sleeps with explicit waits

beginner Waits Challenge 6 of 13

The checkout helper is slow and still fails about one run in ten on CI. Replace the hard-coded sleeps with explicit waits.

Requirements

  • Remove every Thread.sleep and the implicit wait.
  • Create one WebDriverWait with Duration.ofSeconds(10).
  • Wait for each button with ExpectedConditions.elementToBeClickable before clicking it.
  • Wait for the confirmation with ExpectedConditions.visibilityOfElementLocated (or textToBePresentInElementLocated) before asserting on its text.

Expected output

The method uses one `WebDriverWait(driver, Duration.ofSeconds(10))`, waits for each button with `elementToBeClickable` and for the confirmation with `visibilityOfElementLocated`, and contains no `Thread.sleep` or implicit wait.

Checks (5)

  • ○No Thread.sleep
  • ○Does not mix in an implicit wait
  • ○Creates a WebDriverWait with a Duration timeout
  • ○Waits for buttons to be clickable
  • ○Waits for the confirmation to be visible
Solution.javaValidated · not executed

Ctrl/⌘ + Enter to validate · your code is saved in this browser

Results

Validate your code against the checks.

Type to search across SDETRole.

Full-text search by Pagefind · runs in your browser Open search page →