43. Enterprise Selenium Best Practices & Clean Automation Code

The 7 Golden Rules of Selenium with Python

1. Never use time.sleep: Always use explicit condition synchronization (WebDriverWait). 2. Isolate Every Test: Never let tests depend on the execution order or shared state of previous tests. 3. Encapsulate in Page Objects: Keep locators and page mechanics inside page classes. 4. Assert in Tests: Page objects provide state; test functions assert outcomes. 5. Always Clean Up with quit(): Use fixtures and context managers to guarantee teardown. 6. Prefer By.ID and unique data-testid attributes: Avoid brittle absolute XPaths. 7. Write Pythonic Code: Use list comprehensions, f-strings, and type hints for readability.

Task

  • Implement calculate_health_rate(total, passed):
  • 1. If total <= 0, return 0.0.
  • 2. Return (passed / total) * 100.0.
πŸ’‘Common doubts
Did you like the problem?
Lesson 43 of 43
Python
Loading code editor…