0
0
Selenium Pythontesting~8 mins

Custom wait conditions in Selenium Python - Framework Patterns

Choose your learning style9 modes available
Framework Mode - Custom wait conditions
Folder Structure
my_selenium_project/
├── tests/
│   ├── test_login.py
│   └── test_checkout.py
├── pages/
│   ├── base_page.py
│   ├── login_page.py
│   └── checkout_page.py
├── waits/
│   └── custom_waits.py
├── utils/
│   ├── logger.py
│   └── config_reader.py
├── config/
│   ├── dev_config.yaml
│   ├── prod_config.yaml
│   └── test_config.yaml
├── conftest.py
└── requirements.txt
Test Framework Layers
  • Driver Layer: Manages browser setup and teardown, usually in conftest.py using pytest fixtures.
  • Page Objects: Classes in pages/ folder representing web pages with element locators and actions.
  • Custom Waits: Functions or classes in waits/custom_waits.py defining special wait conditions beyond built-in Selenium waits.
  • Tests: Test scripts in tests/ folder that use page objects and custom waits to perform validations.
  • Utilities: Helper modules like logging and configuration readers in utils/.
  • Configuration: Environment-specific settings stored in config/ folder.
Configuration Patterns
  • Environment Files: Use YAML files in config/ to store URLs, credentials, and browser preferences for dev, test, and prod.
  • Config Reader Utility: A Python module in utils/config_reader.py to load and parse config files based on environment variable.
  • Browser Setup: In conftest.py, read config to launch desired browser with options.
  • Credentials Handling: Store sensitive data in config files excluded from version control or use environment variables.
Test Reporting and CI/CD Integration
  • Test Reports: Use pytest with plugins like pytest-html or pytest-allure to generate readable HTML or Allure reports.
  • Logging: Centralized logging in utils/logger.py to capture test steps and errors.
  • CI/CD: Integrate tests in pipelines (GitHub Actions, Jenkins) to run on code push, with reports archived and notifications sent.
  • Custom Waits Impact: Custom wait conditions improve test stability by waiting for specific page states before actions.
Best Practices for Custom Wait Conditions Framework
  1. Use Explicit Waits: Prefer explicit waits with custom conditions over implicit waits for better control and reliability.
  2. Keep Waits Reusable: Write custom wait functions or classes that can be reused across multiple tests and pages.
  3. Timeouts and Polling: Set sensible timeout and polling intervals to balance test speed and stability.
  4. Fail Fast: Custom waits should raise clear exceptions when conditions are not met to help debugging.
  5. Separate Wait Logic: Keep custom wait conditions in their own module/folder to keep code organized and maintainable.
Self Check Question

Where in this folder structure would you add a new custom wait condition that waits for a specific animation to finish on a page?

Key Result
Organize custom wait conditions in a dedicated module to improve test reliability and maintainability.