0
0
Selenium Pythontesting~8 mins

Full page screenshot in Selenium Python - Framework Patterns

Choose your learning style9 modes available
Framework Mode - Full page screenshot
Folder Structure
selenium-python-project/
├── tests/
│   ├── test_full_page_screenshot.py
│   └── __init__.py
├── pages/
│   ├── base_page.py
│   └── home_page.py
├── utils/
│   ├── screenshot_helper.py
│   └── __init__.py
├── config/
│   ├── config.yaml
│   └── __init__.py
├── drivers/
│   └── chromedriver.exe (or chromedriver binary)
├── reports/
│   └── (test reports and screenshots saved here)
├── requirements.txt
└── conftest.py
    
Test Framework Layers
  • Driver Layer: Manages browser setup and teardown using Selenium WebDriver.
  • Page Objects: Classes representing web pages, encapsulating elements and actions (e.g., BasePage with screenshot method).
  • Utilities: Helper functions like full page screenshot capture logic, image saving, and scrolling.
  • Tests: Test scripts that use page objects and utilities to perform actions and assertions.
  • Configuration: Environment settings, browser options, credentials stored in config files (e.g., YAML).
  • Reports: Store screenshots and test reports for review.
Configuration Patterns

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

# config/config.yaml
base_url: "https://example.com"
browser: "chrome"
screenshot_path: "reports/screenshots/"
    

Load config in conftest.py or utility modules to initialize WebDriver and paths.

import yaml

def load_config():
    with open('config/config.yaml') as f:
        return yaml.safe_load(f)
    
Test Reporting and CI/CD Integration
  • Save full page screenshots in reports/screenshots/ with timestamped filenames.
  • Use pytest-html or Allure for HTML test reports embedding screenshots.
  • Integrate tests in CI/CD pipelines (GitHub Actions, Jenkins) to run on push and upload reports as artifacts.
  • Configure failure hooks to capture screenshots automatically on test failure.
Best Practices
  • Use Page Object Model to keep page interactions and screenshot logic organized.
  • Implement explicit waits before taking screenshots to ensure page fully loads.
  • Store screenshots with clear, timestamped names for easy traceability.
  • Keep configuration separate from code for easy environment switching.
  • Use utilities for scrolling and stitching screenshots if native full page capture is not supported.
Self Check

Where would you add a new utility function to scroll the page before taking a full page screenshot?

Key Result
Organize Selenium Python tests with clear layers, config, and utilities to capture reliable full page screenshots.