0
0
Selenium Pythontesting~8 mins

Parameterized tests in Selenium Python - Framework Patterns

Choose your learning style9 modes available
Framework Mode - Parameterized tests
Folder Structure
test_project/
├── tests/
│   ├── test_login.py
│   ├── test_search.py
│   └── test_checkout.py
├── pages/
│   ├── login_page.py
│   ├── search_page.py
│   └── checkout_page.py
├── utils/
│   ├── driver_factory.py
│   ├── test_data.py
│   └── helpers.py
├── config/
│   ├── config.yaml
│   └── credentials.yaml
├── conftest.py
└── pytest.ini
Test Framework Layers
  • Driver Layer: Manages browser setup and teardown (e.g., driver_factory.py).
  • Page Objects: Encapsulate page elements and actions (e.g., login_page.py).
  • Tests: Test scripts using parameterized inputs (e.g., test_login.py with @pytest.mark.parametrize).
  • Utilities: Helper functions and test data management (e.g., test_data.py for parameter sets).
  • Configuration: Environment settings, credentials, and browser options (e.g., config.yaml).
Configuration Patterns
  • Environment Config: Use config/config.yaml to define URLs, browsers, and environment variables.
  • Credentials: Store sensitive data in credentials.yaml and load securely in tests.
  • Parameter Data: Keep test input data in utils/test_data.py or external files (CSV/JSON) for easy updates.
  • pytest.ini: Configure pytest options and markers for parameterized tests.
  • Fixtures: Use conftest.py to provide reusable setup and parameter injection.
Test Reporting and CI/CD Integration
  • Use pytest built-in reports with --junitxml=report.xml for CI tools.
  • Integrate with CI/CD pipelines (GitHub Actions, Jenkins) to run parameterized tests on multiple environments.
  • Use plugins like pytest-html for readable HTML reports showing each parameter set result.
  • Configure test retries and failure screenshots for flaky tests.
Best Practices for Parameterized Tests
  1. Keep test data separate: Store parameters outside test code for easy maintenance.
  2. Use descriptive parameter names: Helps understand test cases in reports.
  3. Limit parameter combinations: Avoid too many combinations to keep tests fast and focused.
  4. Use fixtures for setup: Inject parameters cleanly and reuse setup code.
  5. Validate all parameter cases: Ensure assertions cover all input variations.
Self Check

Where would you add a new set of login credentials to test multiple user types in this framework structure?

Key Result
Organize parameterized tests by separating test data, using fixtures, and structuring code into clear layers for maintainability and clarity.