0
0
Selenium Pythontesting~8 mins

Opening URLs (get) in Selenium Python - Framework Patterns

Choose your learning style9 modes available
Framework Mode - Opening URLs (get)
Folder Structure
selenium-python-project/
├── src/
│   ├── pages/
│   │   └── home_page.py
│   ├── tests/
│   │   └── test_open_url.py
│   ├── utils/
│   │   └── browser_manager.py
│   └── config/
│       └── config.yaml
├── reports/
│   └── test_report.html
├── requirements.txt
└── pytest.ini

This structure separates page objects, tests, utilities, and configuration files clearly.

Test Framework Layers
  • Driver Layer: browser_manager.py manages WebDriver setup and teardown, including browser options.
  • Page Objects: home_page.py contains methods to interact with the home page, including opening URLs.
  • Tests: test_open_url.py contains test cases that use page objects to open URLs and verify page loads.
  • Utilities: Helper functions or classes for common tasks like waits or logging.
  • Configuration: config.yaml stores environment URLs, browser types, and credentials.
Configuration Patterns

Use a YAML file (config.yaml) to store environment-specific data:

environments:
  dev:
    base_url: "https://dev.example.com"
  staging:
    base_url: "https://staging.example.com"
  prod:
    base_url: "https://www.example.com"
browser: "chrome"

Load this config in browser_manager.py and tests to decide which URL to open and which browser to use.

This keeps tests flexible and easy to run in different environments without code changes.

Test Reporting and CI/CD Integration
  • Use pytest with pytest-html plugin to generate readable HTML reports saved in reports/.
  • Integrate tests into CI/CD pipelines (e.g., GitHub Actions, Jenkins) to run tests automatically on code changes.
  • Reports help quickly see if opening URLs works across browsers and environments.
Best Practices
  1. Use Page Object Model: Encapsulate URL opening in page objects to keep tests clean.
  2. Explicit Waits: Wait for page elements after opening URLs to ensure page loaded fully.
  3. Config-Driven URLs: Avoid hardcoding URLs; use config files for flexibility.
  4. Browser Management: Centralize WebDriver setup and teardown to avoid duplication.
  5. Clear Folder Structure: Separate tests, pages, utils, and configs for maintainability.
Self Check

Where in this folder structure would you add a new page object for the Login page?

Key Result
Use a clear folder structure with page objects managing URL opening and config files controlling environments.