0
0
Selenium Pythontesting~8 mins

Markers for categorization in Selenium Python - Framework Patterns

Choose your learning style9 modes available
Framework Mode - Markers for categorization
Folder Structure
selenium-python-project/
├── tests/
│   ├── test_login.py
│   ├── test_checkout.py
│   └── test_search.py
├── pages/
│   ├── login_page.py
│   ├── checkout_page.py
│   └── search_page.py
├── markers/
│   ├── smoke.py
│   ├── regression.py
│   └── slow.py
├── utils/
│   ├── driver_factory.py
│   └── helpers.py
├── config/
│   ├── config.yaml
│   └── credentials.yaml
├── conftest.py
└── pytest.ini
    
Test Framework Layers
  • Test Layer: Contains test scripts using pytest with markers to categorize tests (e.g., @pytest.mark.smoke).
  • Page Object Layer: Classes representing web pages with methods to interact with page elements.
  • Markers Layer: Python files defining custom markers for categorizing tests like smoke, regression, slow.
  • Utilities Layer: Helper functions and driver setup for browser management.
  • Configuration Layer: YAML or other config files for environment settings, credentials, and pytest.ini for marker registration.
Configuration Patterns

Use pytest.ini to register markers so pytest recognizes them and avoids warnings:

[pytest]
markers =
    smoke: quick tests to check basic functionality
    regression: full test suite for release validation
    slow: tests that take longer to run
    

Use config/config.yaml to store environment URLs and browser preferences.

Use conftest.py to define fixtures that read config and initialize WebDriver accordingly.

Test Reporting and CI/CD Integration
  • Use pytest built-in reporting with --junitxml=report.xml for CI tools to parse results.
  • Integrate with CI/CD pipelines (e.g., GitHub Actions, Jenkins) to run tests on push or pull requests.
  • Use markers to select tests in CI jobs, e.g., run only smoke tests on every commit, full regression nightly.
  • Generate HTML reports with plugins like pytest-html for easy visualization.
Best Practices for Markers in Selenium Python Framework
  1. Register all custom markers in pytest.ini to avoid warnings and keep documentation clear.
  2. Use markers to categorize tests by purpose (smoke, regression, slow) to control test execution scope easily.
  3. Keep marker definitions in a dedicated folder for clarity and easy maintenance.
  4. Use markers in combination with pytest command line to run specific groups of tests, improving test speed and feedback.
  5. Document marker usage clearly so all team members understand test categories and when to run them.
Self Check

Where in this folder structure would you add a new marker called api to categorize API tests?

Key Result
Use pytest markers to categorize tests for flexible and efficient test execution in Selenium Python frameworks.