Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
49a74ac
add: initial test sripts
rishavjeet Jan 2, 2025
58aee79
add: add inventory and product image test scripts
rishavjeet Jan 2, 2025
2d26fc3
add: add test scripts for publish product and visibility of prdt
rishavjeet Jan 3, 2025
597e4b7
add: checkout and place order test script
rishavjeet Jan 3, 2025
b44f175
refactor: add some code refactor and utils function
rishavjeet Jan 5, 2025
bf9af35
add: add test data clean up function
rishavjeet Jan 5, 2025
a558824
add: add test coupon deletion function
rishavjeet Jan 5, 2025
56d7682
add: add checkout and place order test scripts
rishavjeet Jan 5, 2025
85e341f
add: add coupon verification test script
rishavjeet Jan 6, 2025
2c6fac1
refactor: add utils for apply coupon
rishavjeet Jan 6, 2025
ec3dfab
add: add review orders test scripts
rishavjeet Jan 6, 2025
3bab81f
fix: fix the review orders test script
rishavjeet Jan 7, 2025
957a037
refactor: use in-built createUser utils function
rishavjeet Jan 7, 2025
7c5898c
add: add adminLogin utils function
rishavjeet Jan 7, 2025
cb9668f
add: add JS docs for test scripts
rishavjeet Jan 7, 2025
e513e9d
add: add JS docs and comments in the utils function
rishavjeet Jan 7, 2025
8954ecd
update: update README.md file
rishavjeet Jan 7, 2025
35674a8
update: update README Pre-requisites
rishavjeet Jan 7, 2025
682d2fa
fix: fix the product image test script
rishavjeet Jan 7, 2025
47e7146
refcator: refactor tag and category test scripts
rishavjeet Jan 7, 2025
cc91d5e
refactor: refactor add product image test script
rishavjeet Jan 7, 2025
e035ae9
refactor: refactor assign product tag and category test script and ad…
rishavjeet Jan 7, 2025
ba359c2
update: update the test assertion for product visibility
rishavjeet Jan 8, 2025
c4da181
update: update the test assertions for assign tag & category test scr…
rishavjeet Jan 8, 2025
20cfed9
refcator: add artifacts in .gitignore
rishavjeet Jan 13, 2025
0f4c079
update: rename the test files
rishavjeet Jan 13, 2025
71cf430
fix: fix the file name of add-tag test script file
rishavjeet Jan 13, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Playwright Tests
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
- name: Install dependencies
run: npm ci
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Run Playwright tests
run: npx playwright test
- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: playwright-report
path: playwright-report/
retention-days: 30
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules/
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
.env
.DS_Store
artifacts/
87 changes: 85 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,85 @@
# TestAutomation-Hands-on
This repository is for doing hands-on practice for the Playwright Framework
# WordPress WooCommerce E2E Testing with Playwright

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.

The test scripts in this repository cover the following areas:

- **Product Management**
- Create a simple product.
- Add product categories and tags.
- Upload product images.
- Set pricing and inventory.
- Publish and verify product visibility.

- **Coupon Management**
- Create different types of coupons (percentage, fixed amount).
- Apply coupons during checkout.
- Verify discount calculations.

- **User Management**
- Create a customer user.
- Customer places an order.
- Admin/Store manager reviews the order.

### Exclusive Features

- **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.

- **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.

## Table of Contents

- [Installation](#installation)
- [Prerequisites](#prerequisites)
- [Running the Tests](#running-the-tests)

## Installation

To get started, follow the steps below to set up the testing environment.

1. **Clone the repository**:

```bash
git clone https://github.com/rishavjeet/test-automation-hands-on.git
```
2. **Install the dependencies**:

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:

```bash
npm install
```
2. **Install the dependencies**:

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.

```bash
WP_USERNAME=
WP_PASSWORD=
WP_BASE_URL=
```

## Prerequisites

Before running the test scripts, ensure that you have the following:

- `Node.js` (version 14 or later)
- `npm` (Node Package Manager)
- Playwright (installed automatically through npm)
- WordPress site setup for testing (local or staging environment)

## Running the Tests

Once the environment is set up, you can run the test scripts using Playwright’s test runner.

1. Run all tests:

```bash
npx playwright test
```
2. Run a specific test script:

```bash
npx playwright test path/to/test-script.spec.js
```
*Replace `path/to/test-script.spec.js` with the path to the specific test script you want to run*
Binary file added assets/product_test_image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions config/global-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* External dependencies
*/
import { request } from '@playwright/test';
// import type { FullConfig } from '@playwright/test';

/**
* WordPress dependencies
*/
import { RequestUtils } from '@wordpress/e2e-test-utils-playwright';

async function globalSetup( config ) {
const { storageState, baseURL, userAgent } = config.projects[ 0 ].use;

console.log('config :'+ config.projects[0].use.userAgent);
const storageStatePath =
typeof storageState === 'string' ? storageState : undefined;

const requestContext = await request.newContext( {
baseURL,
userAgent,
} );

const requestUtils = new RequestUtils( requestContext, {
storageStatePath,
} );

// Authenticate and save the storageState to disk.
await requestUtils.setupRest();

await requestContext.dispose();
}

export default globalSetup;
Loading
Loading