← Back to libraryQuestion 303 of 468
🏗️Framework DesignAdvanced

Maintainability Principles and Common Anti-Patterns

📌 Definition:

A maintainable framework follows DRY, single-responsibility, stable-locator, and no-hard-wait principles, and avoids anti-patterns like duplicated code, hard-coded data, assertions in page objects, Thread.sleep, brittle XPath, and giant test methods.

📖 Detailed Explanation:

Good practices: keep tests small and focused (one behavior), reuse via page objects/utilities (DRY), use stable data-* locators over brittle absolute XPath, centralize waits/config/driver, externalize data, and review test code like production code. Anti-patterns to avoid: Thread.sleep, hard-coded URLs/credentials, copy-pasted logic, assertions inside page objects, order-dependent tests, one giant test doing everything, and over-mocking. Naming, structure, and consistency matter because tests are read and maintained far more than written. Interviewers probe whether you treat test code as first-class, maintainable software.

🔑 Key Points:
  • DRY + single responsibility + stable locators + no hard waits
  • Externalize data/config; centralize driver/waits/reporting
  • Avoid: Thread.sleep, hard-coded data, asserts in page objects, brittle XPath
  • Treat test code as first-class software (review, naming, structure)
🌍 Real-World Example:

A code review rejects a PR that hard-codes a URL, uses absolute XPath and Thread.sleep, and asserts inside a page object — the author refactors to ConfigReader, a data-testid locator, an explicit wait, and a test-level assertion, matching framework standards.

🎯 Scenario-Based Interview Question:

List the top anti-patterns you'd flag in a Selenium framework code review and their fixes.