Welcome to the SmartUI SDK sample for Playwright Python. This repository demonstrates how to integrate SmartUI visual regression testing with Playwright Python.
smartui-playwright-python-sdk-sample/
├── SmartUI_SDK_LT_hub.py # Cloud test
├── SmartUI_SDK_local.py # Local test
├── SmartUI_SDK_Ignore.py # Example with ignore options
├── requirements.txt # Python dependencies
└── smartui-web.json # SmartUI config (create with npx smartui config:create)
- Python 3.7 or higher
- Node.js (for SmartUI CLI)
- LambdaTest account credentials (for Cloud tests)
- Chrome browser (for Local tests)
For Cloud:
export LT_USERNAME='your_username'
export LT_ACCESS_KEY='your_access_key'
export PROJECT_TOKEN='your_project_token'For Local:
export PROJECT_TOKEN='your_project_token'git clone https://github.com/LambdaTest/smartui-playwright-python-sdk-sample
cd smartui-playwright-python-sdk-sampleRecommended: Use a virtual environment (recommended to avoid dependency conflicts):
For Python 3.13+ (if you encounter greenlet errors):
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
npm install @lambdatest/smartui-cli
pip install playwright lambdatest-playwright-driver lambdatest-sdk-utils
python -m playwright install chromium # Local onlyFor Python 3.7-3.12:
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
npm install @lambdatest/smartui-cli
pip install -r requirements.txt
python -m playwright install chromium # Local onlyDependencies included:
playwright- Playwright Python librarylambdatest-playwright-driver- SmartUI SDK for Playwright Pythonlambdatest-sdk-utils- LambdaTest SDK utilities
npx smartui config:create smartui-web.jsonThe SmartUI screenshot function is already implemented in the repository.
Cloud Test (SmartUI_SDK_LT_hub.py):
from lambdatest_playwright_driver import smartui_snapshot
page.goto("https://www.lambdatest.com")
smartui_snapshot(page, "screenshot")Local Test (SmartUI_SDK_local.py):
from lambdatest_playwright_driver import smartui_snapshot
page.goto("https://www.lambdatest.com")
smartui_snapshot(page, "screenshot")Note: The code is already configured and ready to use. You can modify the URL and screenshot name if needed.
If using a virtual environment, activate it first:
source venv/bin/activate # On Windows: venv\Scripts\activatenpx smartui exec python SmartUI_SDK_local.pynpx smartui exec python SmartUI_SDK_LT_hub.py- Connects to LambdaTest Cloud using CDP (Chrome DevTools Protocol)
- Reads credentials from environment variables (
LT_USERNAME,LT_ACCESS_KEY) - Takes screenshot with name:
screenshot
- Runs Playwright locally using Chromium
- Requires Chrome browser installed
- Takes screenshot with name:
screenshot
- Demonstrates how to use ignore options in SmartUI snapshots
- Shows how to exclude specific DOM elements from visual comparison
After running the tests, visit your SmartUI project dashboard to view the captured screenshots and compare them with baseline builds.
For detailed onboarding instructions, see the SmartUI Playwright Python Onboarding Guide.