- Install Cursor AI (recommended IDE)
- Clone/download project and open with Cursor AI (or PyCharm)
Make sure you have the following installed on your system:
- Python (version 3.7 or later)
- pip (Python package manager)
-
Create and activate a virtual environment
python -m venv .venv source venv/bin/activate # On macOS/Linux .venv\Scripts\activate # On Windows
-
Install dependencies
python -m pip install --upgrade pip pip install -r requirements.txt
-
Install pre-commit hooks
pre-commit install
Note: This step needs to be done manually after installing requirements. Pre-commit hooks (including Black formatter) cannot be installed automatically through requirements.txt as this is a Git security feature.
-
Install Playwright browsers
playwright install
-
Verify Playwright installation
python -c "import playwright; print(playwright.__version__)"
To execute your Playwright tests with pytest, run:
# To run functional tests:
pytest -v -s tests_graphql/tests/
# To run visual tests:
pytest tests_e2e/tests/ -v -s --show-browser
# Run a specific test
pytest tests_graphql/tests/test_graphql_add_variation_to_cart.py -k test_add_variation_to_cart
# Run with more detailed output
pytest tests_graphql/tests/test_graphql_add_variation_to_cart.py::test_add_variation_to_cart -v -s
For running tests in a specific browser, specify it as follows:
pytest --browser=chromium # or firefox, webkitThis project includes custom pytest options that can be used to configure test behavior:
-
--checkout-mode: Select checkout flow to test- Values:
single-page(default),multi-step - Example:
pytest tests_e2e/tests/ --checkout-mode single-page
- Values:
-
--product-quantity-control: Choose quantity selector type- Values:
stepper(default),button - Example:
pytest tests_e2e/tests/ --product-quantity-control stepper
- Values:
-
--show-browser: Run browser in headed mode (shows browser UI)- Boolean flag (no value needed)
- Example:
pytest tests_e2e/tests/ --show-browser
# Run with default values
pytest tests_e2e/tests/
# Run with custom checkout mode
pytest tests_e2e/tests/ --checkout-mode multi-step
# Run with custom product quantity control
pytest tests_e2e/tests/ --product-quantity-control button
# Run with headed browser
pytest tests_e2e/tests/ --show-browser
# Combine multiple options
pytest tests_e2e/tests/ --checkout-mode single-page --product-quantity-control stepper --show-browserYou can access these options in your test files using the pytestconfig fixture:
def test_example(pytestconfig):
checkout_mode = pytestconfig.getoption("--checkout-mode")
product_quantity_control = pytestconfig.getoption("--product-quantity-control")
show_browser = pytestconfig.getoption("--show-browser")
print(f"Checkout mode: {checkout_mode}")
print(f"Product quantity control: {product_quantity_control}")
print(f"Show browser: {show_browser}")Generate GraphQL types:
python graphql_client/python_graphql_codegen.py -s -vAdd test data:
python -m dataset.dataset_seeder
To store authentication tokens and other secrets securely, create a .env file:
TOKEN=your_auth_token_hereThen, load environment variables in your test files using:
import os
from dotenv import load_dotenv
load_dotenv()
TOKEN = os.getenv("TOKEN")- Use
--slowmoto slow down execution for debugging:pytest --headed --slowmo=500 # 500ms delay between steps - Run tests in debug mode:
pytest --headed --debug
Playwright can generate tests for you by recording actions:
playwright codegen example.comThis opens a browser where you can perform actions, and Playwright generates the corresponding test script.
Happy Testing! 🚀