0
0
Selenium Pythontesting~8 mins

Parameterize with test data in Selenium Python - Framework Patterns

Choose your learning style9 modes available
Framework Mode - Parameterize with test data
Folder Structure
selenium-python-project/
├── src/
│   ├── pages/
│   │   └── login_page.py
│   ├── tests/
│   │   └── test_login.py
│   ├── utils/
│   │   └── test_data.py
│   └── config/
│       └── config.yaml
├── reports/
├── drivers/
│   └── chromedriver.exe
├── requirements.txt
└── pytest.ini
    
Test Framework Layers
  • Driver Layer: Manages browser drivers and WebDriver setup/teardown.
  • Page Objects: Classes representing web pages with locators and actions.
  • Tests: Test scripts using pytest with parameterized test data.
  • Utilities: Helper modules, including test data providers for parameterization.
  • Configuration: Environment settings, browser options, credentials stored in config files.
Configuration Patterns

Use config.yaml to store environment URLs, browser types, and credentials.

Example config.yaml:

environments:
  dev:
    url: "https://dev.example.com"
  prod:
    url: "https://www.example.com"
browser: chrome
credentials:
  username: "testuser"
  password: "password123"
    

Load config in tests and utilities to select environment and browser dynamically.

Test data for parameterization is stored in utils/test_data.py as lists or dictionaries.

Test Reporting and CI/CD Integration
  • Use pytest with pytest-html plugin to generate HTML reports.
  • Reports saved in reports/ folder with timestamps for easy tracking.
  • Integrate tests in CI/CD pipelines (e.g., GitHub Actions, Jenkins) to run tests on code push.
  • Parameterization allows running tests with multiple data sets automatically in CI.
Best Practices for Parameterizing with Test Data
  • Keep test data separate from test logic for easy updates and readability.
  • Use @pytest.mark.parametrize decorator to run tests with multiple inputs.
  • Use descriptive test case names to identify which data set failed.
  • Store sensitive data securely and avoid hardcoding credentials in test scripts.
  • Validate test data format and completeness before running tests to avoid false failures.
Self Check

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

Key Result
Separate test data from test logic and use pytest parameterization to run tests with multiple data sets.