Q: What ExpectedConditions have you used in your project?
A: I commonly use: visibilityOfElementLocated to wait for elements before reading text, elementToBeClickable before clicking buttons, invisibilityOfElementLocated for loading spinners, presenceOfElementLocated for hidden elements like CSRF tokens, textToBePresentInElementLocated for dynamic text, urlContains for page navigation, and alertIsPresent for JavaScript dialogs. I also used frameToBeAvailableAndSwitchToIt for payment iframes.
Q: How do you wait for a page to fully load?
A: Multiple approaches: (1) Wait for a specific element on the target page using visibilityOfElementLocated — most reliable. (2) Wait for URL to change using urlContains. (3) Wait for page title using titleContains. (4) Use JavaScript to check document.readyState === "complete" via a custom ExpectedCondition. (5) Wait for loading spinner to disappear. Best practice is combining URL check with key element visibility check.
Q: What happens if a wait times out?
A: It throws a TimeoutException. The message includes what condition was being waited for and the timeout duration. I handle this with try-catch when the element is optional (like a promo popup). For required elements, I let the exception propagate — it fails the test with a clear error. I also use FluentWait's .withMessage() for descriptive timeout messages that help with debugging.
Q: Why is Thread.sleep() bad practice?
A: Thread.sleep() pauses for a fixed duration regardless of page state. If the page loads in 500ms, you still wait 3 seconds — wasted time. If the API takes 5 seconds, 3 seconds isn't enough — test fails. It also adds 5+ minutes to a suite of 100 tests. The right approach is WebDriverWait which returns as soon as the condition is met, or fails immediately when the timeout expires.
Key Point: WebDriverWait + ExpectedConditions is the professional way to handle timing. Never use Thread.sleep() in production code.
Answer all 5 questions, then submit to see your score.
1. Why is Thread.sleep() bad practice in test automation?
2. What is the key difference between implicit and explicit wait?
3. Which ExpectedCondition should you use before clicking a button?
4. What happens when you mix implicit and explicit waits?
5. How do you wait for a loading spinner to disappear?