Skip to content

Commit 1d735c0

Browse files
authored
Merge pull request #1 from rishavjeet/learn/wp-e2e-utils
Add WooCommerce Test Automation
2 parents a23670c + 71cf430 commit 1d735c0

39 files changed

+4686
-2
lines changed

.github/workflows/playwright.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Playwright Tests
2+
on:
3+
push:
4+
branches: [ main, master ]
5+
pull_request:
6+
branches: [ main, master ]
7+
jobs:
8+
test:
9+
timeout-minutes: 60
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- uses: actions/setup-node@v4
14+
with:
15+
node-version: lts/*
16+
- name: Install dependencies
17+
run: npm ci
18+
- name: Install Playwright Browsers
19+
run: npx playwright install --with-deps
20+
- name: Run Playwright tests
21+
run: npx playwright test
22+
- uses: actions/upload-artifact@v4
23+
if: ${{ !cancelled() }}
24+
with:
25+
name: playwright-report
26+
path: playwright-report/
27+
retention-days: 30

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
node_modules/
2+
/test-results/
3+
/playwright-report/
4+
/blob-report/
5+
/playwright/.cache/
6+
.env
7+
.DS_Store
8+
artifacts/

README.md

Lines changed: 85 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,85 @@
1-
# TestAutomation-Hands-on
2-
This repository is for doing hands-on practice for the Playwright Framework
1+
# WordPress WooCommerce E2E Testing with Playwright
2+
3+
This repository contains a set of end-to-end (E2E) test scripts designed to automate various processes in WordPress. The tests are written using the **wp-e2e-utils-playwright** framework functions, providing a powerful and flexible solution for testing WordPress websites.
4+
5+
The test scripts in this repository cover the following areas:
6+
7+
- **Product Management**
8+
- Create a simple product.
9+
- Add product categories and tags.
10+
- Upload product images.
11+
- Set pricing and inventory.
12+
- Publish and verify product visibility.
13+
14+
- **Coupon Management**
15+
- Create different types of coupons (percentage, fixed amount).
16+
- Apply coupons during checkout.
17+
- Verify discount calculations.
18+
19+
- **User Management**
20+
- Create a customer user.
21+
- Customer places an order.
22+
- Admin/Store manager reviews the order.
23+
24+
### Exclusive Features
25+
26+
- **wp-e2e-utils-playwright Framework**: The tests are written using the **wp-e2e-utils-playwright** framework functions, which streamline the process of automating interactions with a WordPress site. This framework helps interact with the WordPress admin panel, as well as simulating user behavior on the frontend.
27+
28+
- **Test Data Cleanup**: Each test script includes a **data cleanup** feature to ensure that the site storage is not overpopulated with test data. After each test execution, the relevant test data (e.g., products, users, coupons) is removed, maintaining a clean environment for subsequent tests.
29+
30+
## Table of Contents
31+
32+
- [Installation](#installation)
33+
- [Prerequisites](#prerequisites)
34+
- [Running the Tests](#running-the-tests)
35+
36+
## Installation
37+
38+
To get started, follow the steps below to set up the testing environment.
39+
40+
1. **Clone the repository**:
41+
42+
```bash
43+
git clone https://github.com/rishavjeet/test-automation-hands-on.git
44+
```
45+
2. **Install the dependencies**:
46+
47+
This project uses npm to manage dependencies. Make sure you have Node.js and npm installed. Then, run the following command to install the required packages:
48+
49+
```bash
50+
npm install
51+
```
52+
2. **Install the dependencies**:
53+
54+
Create a .env file in the root directory of the project. You will need to add your WordPress admin credentials and other relevant environment configurations.
55+
56+
```bash
57+
WP_USERNAME=
58+
WP_PASSWORD=
59+
WP_BASE_URL=
60+
```
61+
62+
## Prerequisites
63+
64+
Before running the test scripts, ensure that you have the following:
65+
66+
- `Node.js` (version 14 or later)
67+
- `npm` (Node Package Manager)
68+
- Playwright (installed automatically through npm)
69+
- WordPress site setup for testing (local or staging environment)
70+
71+
## Running the Tests
72+
73+
Once the environment is set up, you can run the test scripts using Playwright’s test runner.
74+
75+
1. Run all tests:
76+
77+
```bash
78+
npx playwright test
79+
```
80+
2. Run a specific test script:
81+
82+
```bash
83+
npx playwright test path/to/test-script.spec.js
84+
```
85+
*Replace `path/to/test-script.spec.js` with the path to the specific test script you want to run*

assets/product_test_image.png

199 KB
Loading

config/global-setup.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* External dependencies
3+
*/
4+
import { request } from '@playwright/test';
5+
// import type { FullConfig } from '@playwright/test';
6+
7+
/**
8+
* WordPress dependencies
9+
*/
10+
import { RequestUtils } from '@wordpress/e2e-test-utils-playwright';
11+
12+
async function globalSetup( config ) {
13+
const { storageState, baseURL, userAgent } = config.projects[ 0 ].use;
14+
15+
console.log('config :'+ config.projects[0].use.userAgent);
16+
const storageStatePath =
17+
typeof storageState === 'string' ? storageState : undefined;
18+
19+
const requestContext = await request.newContext( {
20+
baseURL,
21+
userAgent,
22+
} );
23+
24+
const requestUtils = new RequestUtils( requestContext, {
25+
storageStatePath,
26+
} );
27+
28+
// Authenticate and save the storageState to disk.
29+
await requestUtils.setupRest();
30+
31+
await requestContext.dispose();
32+
}
33+
34+
export default globalSetup;

0 commit comments

Comments
 (0)