πŸ’‘ If you like this website, please share it with your friends and network! πŸš€
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 + Java
import 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();
        }
    }
}