Back to All Scenarios
Scenario 98 of 100
Debugging UI Failures
Beginner
Slowing Down Test Execution Safely for Demos or Debugging
πScenario Overview
Slowing Down Test Execution Safely for Demos or Debugging
Key Takeaways & Cheat Sheet
- βUse custom listener hooks to highlight elements briefly before clicks
- βAvoid hardcoding Thread.sleep() delays across your codebase
- βUse chrome debugging tools or proxy proxies to throttle execution speeds
- βWrite clean action wrappers that include controlled visual pauses
Short Direct Answer
To slow down tests safely for live demos or debugging, avoid adding static sleeps directly in your test code. Instead, build a custom driver listener that intercepts actions (like clicking or typing) and includes a brief pause or highlights the target element, keeping your production test suite fast.
β οΈ Senior Warning (Red Flag)
Never check long Thread.sleep() calls into your master repository branch to slow down tests permanently. This wastes valuable CI pipeline execution hours and introduces severe latency.
π‘ STAR Deep Dive Explanation & Pro Tip
Using WebDriverListener is highly extensible. It allows you to toggle execution dampening on and off dynamically using configuration flags without modifying individual test code.
SeleniumAutomation.java
Selenium 4 + Javaimport org.openqa.selenium.support.events.WebDriverListener;
// β
Implement WebDriverListener to add controlled visual delays
public class DemoVisualDampener implements WebDriverListener {
@Override
public void beforeClick(WebElement element) {
// Highlight element before click
// ((JavascriptExecutor) driver).executeScript("arguments[0].style.border='3px solid orange';", element);
try {
// Add a controlled 1-second pause to let viewers follow the action
Thread.sleep(1000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}