Skip to content

Latest commit

 

History

History
131 lines (86 loc) · 3.35 KB

File metadata and controls

131 lines (86 loc) · 3.35 KB

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.


Overview

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

Features

  • 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

Getting Started

Prerequisites

  • Python 3.8+
  • Playwright Python package (pip install playwright)
  • Perfecto cloud subscription with access credentials (security token, cloud endpoint)
  • Installed Playwright browsers: playwright install

Installation

  1. Clone the repository:

    git clone https://github.com/youruser/Perfecto-Playwright-Python-Demo.git
    cd Perfecto-Playwright-Python-Demo
  2. Create and activate a virtual environment (recommended):

    python -m venv venv
    source venv/bin/activate      # On Windows: venv\Scripts\activate
  3. Install dependencies:

    pip install -r requirements.txt
    playwright install
  4. Configure environment variables or modify conftest.py for 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>


Usage

Running Tests Locally with Perfecto Integration

pytest tests/

The tests will connect to Perfecto's CDP endpoint, launch browsers/devices with specified capabilities, execute Playwright automation commands, and report results.


Project Structure

.
├── tests/                     # Test scripts using Playwright
│   └── test_example.py
├── conftest.py                # Pytest fixtures for browser/page setup
├── requirements.txt           # Python dependencies
├── README.md                  # This file
└── ...

Configuration

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

Contributing

Pull requests welcome! Feel free to open issues for bugs or feature requests.


License

MIT License


References


This demo project aims to accelerate your Playwright automation journey on Perfecto’s powerful cloud testing platform. Enjoy scaling your UI testing efficiently!