0
0
Selenium Pythontesting~8 mins

Drag and drop in Selenium Python - Framework Patterns

Choose your learning style9 modes available
Framework Mode - Drag and drop
Folder Structure
project-root/
├── src/
│   ├── pages/
│   │   └── drag_and_drop_page.py
│   ├── tests/
│   │   └── test_drag_and_drop.py
│   ├── utils/
│   │   └── selenium_helpers.py
│   └── config/
│       └── config.yaml
├── reports/
│   └── test_report.html
├── requirements.txt
└── pytest.ini
  
Test Framework Layers
  • Driver Layer: Manages browser setup and teardown using Selenium WebDriver.
  • Page Objects: Encapsulate drag and drop page elements and actions in drag_and_drop_page.py.
  • Tests: Contains test cases like test_drag_and_drop.py that use page objects to perform drag and drop and assert results.
  • Utilities: Helper functions for Selenium actions, e.g., custom drag and drop methods in selenium_helpers.py.
  • Configuration: Environment settings, URLs, browser options stored in config.yaml.
Configuration Patterns

Use a YAML file (config/config.yaml) to store:

  • Base URL of the application under test
  • Browser choice (e.g., Chrome, Firefox)
  • Timeouts for waits
  • Credentials if needed (securely handled)

Load this config in test setup to initialize WebDriver accordingly.

Test Reporting and CI/CD Integration
  • Use pytest with pytest-html plugin to generate HTML reports in reports/ folder.
  • Reports show pass/fail status of drag and drop tests with screenshots on failure.
  • Integrate tests in CI pipelines (GitHub Actions, Jenkins) to run on code push.
  • Failing tests block merges until fixed, ensuring drag and drop functionality stays stable.
Framework Design Principles
  • Page Object Model: Keep drag and drop logic inside page objects for easy maintenance.
  • Explicit Waits: Use Selenium waits to ensure elements are ready before drag and drop.
  • Reusable Utilities: Create helper methods for drag and drop actions to avoid code duplication.
  • Clear Assertions: Verify drag and drop success with clear, meaningful assertions.
  • Configurable Tests: Use config files to run tests on different browsers and environments without code changes.
Self Check

Where in this folder structure would you add a new page object for a drag and drop widget on a different page?

Key Result
Organize Selenium Python tests with clear page objects, reusable utilities, and config-driven setup for reliable drag and drop testing.