0
0
Selenium Pythontesting~8 mins

Maximize and minimize window in Selenium Python - Framework Patterns

Choose your learning style9 modes available
Framework Mode - Maximize and minimize window
Folder Structure
selenium_python_project/
├── src/
│   ├── pages/
│   │   └── base_page.py
│   ├── tests/
│   │   └── test_window_actions.py
│   ├── utils/
│   │   └── driver_factory.py
│   └── config/
│       └── config.yaml
├── reports/
├── requirements.txt
└── pytest.ini
  
Test Framework Layers
  • Driver Layer: driver_factory.py creates and manages WebDriver instances.
  • Page Objects: base_page.py contains common browser actions like maximize and minimize window.
  • Tests: test_window_actions.py contains test cases to verify maximize and minimize window functionality.
  • Utilities: Helper functions or classes for driver setup and teardown.
  • Configuration: config.yaml stores environment settings like browser type and URLs.
Configuration Patterns

Use a config.yaml file to store environment variables such as:

  • Browser type (e.g., chrome, firefox)
  • Base URL
  • Timeouts

Load these settings in driver_factory.py to create the WebDriver accordingly.

Example snippet from config.yaml:

browser: chrome
base_url: "https://example.com"
timeout: 10
  
Test Reporting and CI/CD Integration
  • Use pytest with pytest-html plugin to generate HTML reports after test runs.
  • Reports are saved in the reports/ folder for easy access.
  • Integrate tests into CI/CD pipelines (e.g., GitHub Actions, Jenkins) to run tests automatically on code changes.
  • Failing tests will be clearly reported with screenshots if configured.
Framework Design Principles
  • Page Object Model: Keep window actions in a base page class to reuse across pages.
  • Explicit Waits: Use waits to ensure the page is ready before maximizing or minimizing.
  • Driver Factory: Centralize WebDriver creation to easily switch browsers.
  • Config Driven: Use config files to avoid hardcoding browser or URL values.
  • Clear Reporting: Generate readable reports to quickly identify window action test results.
Self Check

Where in this folder structure would you add a new method to minimize the browser window?

Hint: Think about where common browser actions are stored.

Key Result
Use a Page Object Model with a driver factory and config files to manage maximize and minimize window actions cleanly.