0
0
Selenium Pythontesting~8 mins

Reading test data from Excel in Selenium Python - Framework Patterns

Choose your learning style9 modes available
Framework Mode - Reading test data from Excel
Folder Structure
selenium_python_project/
├── tests/
│   ├── test_login.py
│   └── test_checkout.py
├── pages/
│   ├── login_page.py
│   └── checkout_page.py
├── utils/
│   ├── excel_reader.py
│   └── webdriver_manager.py
├── config/
│   ├── config.yaml
│   └── credentials.yaml
├── reports/
│   └── test_report.html
├── conftest.py
└── requirements.txt
Test Framework Layers
  • Driver Layer: Manages browser setup and teardown (webdriver_manager.py).
  • Page Objects: Encapsulate UI elements and actions (login_page.py, checkout_page.py).
  • Test Cases: Actual test scripts using pytest (test_login.py, test_checkout.py).
  • Utilities: Helper functions like reading Excel files (excel_reader.py).
  • Configuration: Stores environment settings and credentials (config.yaml, credentials.yaml).
Configuration Patterns
  • Use config.yaml to define environment URLs and browser types.
  • Store sensitive data like usernames and passwords in credentials.yaml, excluded from version control.
  • Use pytest fixtures in conftest.py to load config and pass to tests.
  • Excel test data files are placed in a dedicated folder (e.g., data/test_data.xlsx), path managed in config or utils.
  • Use openpyxl library in excel_reader.py to read Excel data in a reusable way.
Test Reporting and CI/CD Integration
  • Use pytest with plugins like pytest-html to generate readable HTML reports in reports/.
  • Integrate tests in CI/CD pipelines (GitHub Actions, Jenkins) to run on code push.
  • Reports and logs are archived for review after each run.
  • Failures can trigger notifications (email, Slack) with report links.
Best Practices
  • Separate test data from test code: Keep Excel files outside test scripts for easy updates.
  • Use utility functions: Create reusable Excel reading functions to avoid duplication.
  • Validate data format: Check Excel data correctness before using in tests to avoid runtime errors.
  • Use explicit waits: In Selenium tests, wait for elements to be ready before actions.
  • Keep config secure: Never commit sensitive credentials to public repos.
Self Check Question

Where in this folder structure would you add a new utility function to read a different Excel sheet for test data?

Key Result
Organize Selenium Python tests with clear layers and use utility modules to read Excel test data cleanly.