s# Perfecto-Playwright-Python-Demo
A demonstration project showcasing how to use Playwright with Python to run automated UI tests on the Perfecto cloud testing platform.
This project provides a simple, practical example of integrating Playwright's Python test automation framework with Perfecto’s cloud-based device and browser infrastructure. It covers:
- Connecting to Perfecto's Continuous Delivery Platform (CDP) using WebSocket endpoints
- Defining Playwright test scripts that run remotely on Perfecto devices
- Setting up authentication via security tokens
- Using Playwright’s async Python API for reliable cross-browser cross-device testing
- Playwright async tests configured for Perfecto CDP cloud execution
- Sample test scripts navigating web pages and asserting UI elements
- Customizable device and browser capabilities for varied test environments
- Efficient use of pytest fixtures with Playwright pages for scalability
- Graceful setup/teardown handling with async context management
- Python 3.8+
- Playwright Python package (
pip install playwright) - Perfecto cloud subscription with access credentials (security token, cloud endpoint)
- Installed Playwright browsers:
playwright install
-
Clone the repository:
git clone https://github.com/youruser/Perfecto-Playwright-Python-Demo.git cd Perfecto-Playwright-Python-Demo -
Create and activate a virtual environment (recommended):
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt playwright install
-
Configure environment variables or modify
conftest.pyfor your Perfecto endpoint and security token.
E.g.
MAC:
export cloud=<perfecto cloud name>
export sec_token=<perfecto token>
WINDOWS:
set cloud=<perfecto cloud name>
export sec_token=<perfecto token>
pytest tests/The tests will connect to Perfecto's CDP endpoint, launch browsers/devices with specified capabilities, execute Playwright automation commands, and report results.
.
├── tests/ # Test scripts using Playwright
│ └── test_example.py
├── conftest.py # Pytest fixtures for browser/page setup
├── requirements.txt # Python dependencies
├── README.md # This file
└── ...
Set the following environment variables before running tests:
cloud: Your Perfecto`: Your Perfecto security token
Example WebSocket endpoint constructed as:
wss://{cloud}.perfectomobile.com/websocket
Pull requests welcome! Feel free to open issues for bugs or feature requests.
MIT License
This demo project aims to accelerate your Playwright automation journey on Perfecto’s powerful cloud testing platform. Enjoy scaling your UI testing efficiently!