0
0
Selenium Pythontesting~8 mins

HTML report generation in Selenium Python - Framework Patterns

Choose your learning style9 modes available
Framework Mode - HTML report generation
Folder Structure
test_project/
├── tests/
│   ├── test_login.py
│   ├── test_checkout.py
│   └── __init__.py
├── pages/
│   ├── login_page.py
│   ├── checkout_page.py
│   └── __init__.py
├── reports/
│   └── (generated HTML reports here)
├── utils/
│   ├── driver_factory.py
│   ├── logger.py
│   └── __init__.py
├── config/
│   ├── config.yaml
│   └── __init__.py
├── conftest.py
└── pytest.ini
Test Framework Layers
  • Driver Layer: Handles browser setup and teardown (e.g., driver_factory.py).
  • Page Objects: Encapsulate page elements and actions (e.g., login_page.py).
  • Tests: Test cases using PyTest that call page objects and assert results (e.g., test_login.py).
  • Utilities: Helper functions like logging and report generation support.
  • Configuration: Environment settings, browser options, credentials stored in config.yaml.
  • Reports: HTML reports generated after test runs stored in reports/ folder.
Configuration Patterns
  • Environment Settings: Use config/config.yaml to define URLs, browsers, and credentials for different environments (dev, staging, prod).
  • Browser Selection: Pass browser choice via command line or config file, used by driver_factory.py to launch correct browser.
  • Credentials: Store securely in config file or environment variables, accessed in tests or page objects.
  • PyTest ini: Use pytest.ini to configure test runs and plugins like pytest-html for report generation.
Test Reporting and CI/CD Integration
  • HTML Reports: Use pytest-html plugin to generate detailed HTML reports after test execution.
  • Report Location: Reports saved in reports/ folder with timestamped filenames for history.
  • CI/CD Integration: Configure CI pipelines (e.g., GitHub Actions, Jenkins) to run tests and archive HTML reports as artifacts.
  • Notifications: Optionally send report links or summaries via email or messaging tools after CI runs.
Best Practices for HTML Report Generation Framework
  1. Separate Reports Folder: Keep all reports in a dedicated folder to avoid clutter and ease access.
  2. Use Plugins: Leverage existing tools like pytest-html for reliable and rich HTML reports.
  3. Timestamp Reports: Include timestamps in report filenames to track test history and avoid overwriting.
  4. Integrate with CI: Automate report generation and storage in CI pipelines for continuous feedback.
  5. Readable Reports: Ensure reports include clear test names, statuses, screenshots on failure, and logs for easy debugging.
Self Check

Where in this folder structure would you add a new utility to capture screenshots on test failure for the HTML report?

Key Result
Organize Selenium Python tests with clear layers and use pytest-html plugin to generate and store HTML reports in a dedicated folder.