0
0
Selenium Pythontesting~8 mins

Edge configuration in Selenium Python - Framework Patterns

Choose your learning style9 modes available
Framework Mode - Edge configuration
Folder Structure
selenium-python-project/
├── tests/
│   ├── test_login.py
│   └── test_checkout.py
├── pages/
│   ├── base_page.py
│   └── login_page.py
├── drivers/
│   └── msedgedriver.exe  
├── utils/
│   ├── config.py
│   └── edge_driver_factory.py
├── conftest.py
└── requirements.txt
    
Test Framework Layers
  • Driver Layer: Manages Edge WebDriver setup and teardown (e.g., edge_driver_factory.py).
  • Page Objects: Encapsulate page elements and actions (e.g., login_page.py).
  • Tests: Test cases using pytest in tests/ folder.
  • Utilities: Configuration management and helper functions (config.py).
  • Fixtures: Pytest fixtures in conftest.py to initialize Edge driver.
Configuration Patterns

Use a config.py file to manage environment variables like URLs and credentials.

Use edge_driver_factory.py to configure Edge options such as headless mode, window size, and driver path.

Example snippet from edge_driver_factory.py:

from selenium import webdriver
from selenium.webdriver.edge.service import Service
from selenium.webdriver.edge.options import Options

class EdgeDriverFactory:
    @staticmethod
    def create_driver(headless: bool = False):
        options = Options()
        if headless:
            options.add_argument('--headless=new')
        options.add_argument('--window-size=1920,1080')
        service = Service(executable_path='./drivers/msedgedriver.exe')
        driver = webdriver.Edge(service=service, options=options)
        return driver
Test Reporting and CI/CD Integration
  • Use pytest with plugins like pytest-html to generate readable HTML reports.
  • Integrate tests in CI/CD pipelines (GitHub Actions, Jenkins) to run Edge tests on Windows runners.
  • Store test reports as artifacts for review after each run.
  • Use environment variables in CI to configure Edge driver path and headless mode.
Best Practices for Edge Configuration Framework
  1. Use Page Object Model: Keep UI locators and actions separate from tests.
  2. Centralize Driver Setup: Use a factory class to create Edge drivers with consistent options.
  3. Support Headless Mode: Allow tests to run without UI for faster CI runs.
  4. Manage Driver Executable: Keep Edge driver binary in a dedicated folder and update as needed.
  5. Use Pytest Fixtures: Initialize and quit Edge driver cleanly for each test.
Self Check

Where would you add a new page object for the "Checkout" page in this framework structure?

Key Result
Use a dedicated driver factory and configuration files to manage Microsoft Edge WebDriver setup and options in a clean, maintainable Selenium Python framework.