Waiting in TestDriver: Ensuring stability and reducing flakiness
Waiting is a critical feature in TestDriver that ensures tests are stable and reliable, even in dynamic or slow-loading environments.- Automatically adjusts to varying load times, reducing the need for hardcoded delays.
- Ensures that tests wait for dynamic elements to appear, reducing false negatives caused by incomplete rendering.
- By waiting for the screen and network to stabilize,
redraw
minimizes the risk of interacting with incomplete or incorrect elements.
Summary of waiting features
Feature | Description |
---|---|
redraw (automatic) | TestDriver automatically waits for UI changes and network activity to resolve. |
wait-for-text | Waits for specific text to appear on the screen. |
wait-for-image | Waits for a specific image or visual element to appear on the screen. |
Key waiting features in TestDriver
- Automatic Waiting with
redraw
:
- TestDriver automatically waits for the machine before moving to the next step.
- This includes waiting for:
- UI changes to complete.
- Network activity to stabilize (for example, API calls).
- Reduces the need for manual waits, making tests faster and less prone to flakiness.
wait-for-text
Command:
- Waits for specific text to appear on the screen.
- Useful for validating dynamic content or ensuring that a page has fully loaded before proceeding.
wait-for-image
Command:
- Waits for a specific image or visual element to appear on the screen.
- Ideal for verifying the presence of icons, logos, or other graphical elements.
Commands for explicit waiting
1. wait-for-text
The wait-for-text
command pauses the test until the specified text appears on the screen. This is particularly useful for dynamic content that takes time to load.
Syntax
Example
wait-for-image
The wait-for-image
command pauses the test until the specified image or visual element appears on the screen.
Syntax:
Example:
Automatic waiting with redraw
TestDriver’s redraw
function is a built-in mechanism that automatically waits for the screen to stabilize before proceeding to the next step. This includes:
- UI Changes:
- Waits for animations, transitions, or DOM updates to complete.
- Ensures that the screen is fully rendered before interacting with elements.
- Network Stabilization:
- Waits for network activity (for example, API calls, AJAX requests) to finish.
- Ensures that dynamic content is fully loaded before proceeding.
- Screen Stabilization:
- Continuously monitors the screen for changes and only moves forward when the screen is stable.
Best practices for waiting
- Leverage Automatic Waiting:
- Rely on TestDriver’s
redraw
function to handle most waiting scenarios automatically.
- Use Explicit Waiting for Dynamic Elements:
- Use
wait-for-text
orwait-for-image
for elements that take time to load.
- Avoid Hardcoded Delays:
- Replace hardcoded
sleep
orwait
commands with dynamic waiting commands to improve test reliability.
- Set Appropriate Timeouts:
- Use reasonable timeouts for explicit waiting commands to balance reliability and test execution time.
- Test Incrementally:
- Add waiting commands step-by-step to ensure each part of the workflow is stable.