0
0
Selenium Pythontesting~8 mins

First Selenium script in Selenium Python - Framework Patterns

Choose your learning style9 modes available
Framework Mode - First Selenium script
Folder Structure
selenium_project/
├── tests/
│   └── test_first_script.py
├── pages/
│   └── home_page.py
├── utils/
│   └── driver_factory.py
├── config/
│   └── config.yaml
└── requirements.txt
Test Framework Layers
  • Driver Layer: Manages browser setup and teardown (e.g., driver_factory.py).
  • Page Objects: Encapsulate web page elements and actions (e.g., home_page.py).
  • Tests: Contains test scripts that use page objects to perform actions and assertions (e.g., test_first_script.py).
  • Utilities: Helper functions or classes to support tests (e.g., logging, waits).
  • Configuration: Stores environment settings like URLs, browser choice, credentials (config.yaml).
Configuration Patterns

Use a config.yaml file to store environment details such as:

  • Base URL
  • Browser type (Chrome, Firefox)
  • Timeouts
  • Credentials (if needed)

Load this config in your driver factory and tests to keep code flexible and avoid hardcoding.

Test Reporting and CI/CD Integration
  • Use pytest with pytest-html plugin to generate readable HTML reports.
  • Integrate tests in CI pipelines (GitHub Actions, Jenkins) to run on every code push.
  • Configure reports to be saved as artifacts for easy access.
  • Use clear test naming and assertions for easy debugging.
Best Practices
  • Page Object Model: Keep locators and page actions in separate classes to improve maintainability.
  • Explicit Waits: Use Selenium waits to handle dynamic page elements instead of fixed sleeps.
  • Config Driven: Avoid hardcoding URLs or browser types; use config files.
  • Clear Assertions: Write simple, meaningful assertions to verify expected results.
  • Reusable Driver Setup: Centralize browser setup and teardown to avoid duplication.
Self Check

Where would you add a new page object for the Login page in this framework structure?

Key Result
Organize Selenium tests with clear layers: driver setup, page objects, tests, utilities, and config for maintainability and flexibility.