Skip to content

Commit 18dda87

Browse files
Merge pull request #2031 from amit-webkul/playwright
Adding Playwright testcases setup.
2 parents c9bc521 + f25d96e commit 18dda87

33 files changed

+1444
-36
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
name: Admin | Playwright Tests
2+
3+
on: [push, pull_request]
4+
5+
permissions:
6+
contents: read
7+
8+
env:
9+
FORCE_COLOR: 1
10+
11+
jobs:
12+
admin_playwright_test:
13+
runs-on: ${{ matrix.operating-systems }}
14+
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
operating-systems: [ubuntu-latest]
19+
php-versions: ['8.3']
20+
node-version: ['22.13.1']
21+
shard-index: [1,2,3,4,5,6]
22+
shard-total: [6]
23+
24+
name: Admin | Playwright Tests | Shard ${{ matrix.shard-index }} Of ${{ matrix.shard-total }}
25+
26+
services:
27+
mysql:
28+
image: mysql:8.0
29+
env:
30+
MYSQL_ROOT_PASSWORD: root
31+
MYSQL_DATABASE: krayin
32+
ports:
33+
- 3306
34+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=5
35+
36+
steps:
37+
- name: Checkout
38+
uses: actions/checkout@v4
39+
40+
- name: Setup PHP
41+
uses: shivammathur/setup-php@v2
42+
with:
43+
php-version: ${{ matrix.php-versions }}
44+
extensions: curl, fileinfo, gd, intl, mbstring, openssl, pdo, pdo_mysql, tokenizer, zip
45+
ini-values: error_reporting=E_ALL
46+
tools: composer:v2
47+
48+
- name: Set Up Node.js
49+
uses: actions/setup-node@v4
50+
with:
51+
node-version: ${{ matrix.node-version }}
52+
53+
- name: Install Node.js Dependencies
54+
run: npm install
55+
working-directory: packages/Webkul/Admin
56+
57+
- name: Install Playwright Browsers
58+
run: npx playwright install --with-deps
59+
working-directory: packages/Webkul/Admin
60+
61+
- name: Setting Environment
62+
run: |
63+
cp .env.example .env
64+
sed -i "s|^\(DB_HOST=\s*\).*$|\1127.0.0.1|" .env
65+
sed -i "s|^\(DB_PORT=\s*\).*$|\1${{ job.services.mysql.ports['3306'] }}|" .env
66+
sed -i "s|^\(DB_DATABASE=\s*\).*$|\1krayin|" .env
67+
sed -i "s|^\(DB_USERNAME=\s*\).*$|\1root|" .env
68+
sed -i "s|^\(DB_PASSWORD=\s*\).*$|\1root|" .env
69+
sed -i "s|^\(APP_DEBUG=\s*\).*$|\1false|" .env
70+
sed -i "s|^\(APP_URL=\s*\).*$|\1http://127.0.0.1:8000|" .env
71+
cat .env
72+
73+
- name: Install Composer Dependencies
74+
run: composer install
75+
76+
- name: Running Krayin Installer
77+
run: php artisan krayin-crm:install --skip-env-check --skip-admin-creation
78+
79+
# - name: Seed Product Table
80+
# run: php artisan db:seed --class="Webkul\\Installer\\Database\\Seeders\\ProductTableSeeder"
81+
82+
- name: Start Laravel server
83+
run: |
84+
php artisan serve --host=0.0.0.0 --port=8000 > server.log 2>&1 &
85+
echo "Waiting for server to start..."
86+
timeout 30 bash -c 'until curl -s http://127.0.0.1:8000 > /dev/null; do sleep 1; done'
87+
88+
- name: Run All Playwright Tests
89+
env:
90+
BASE_URL: 'http://127.0.0.1:8000'
91+
run: |
92+
npx playwright test --reporter=list --config=tests/e2e-pw/playwright.config.ts --shard=${{ matrix.shard-index }}/${{ matrix.shard-total }}
93+
working-directory: packages/Webkul/Admin
94+
95+
- name: Upload Test Results
96+
uses: actions/upload-artifact@v4
97+
if: always()
98+
with:
99+
name: test-results
100+
path: packages/Webkul/Admin/tests/e2e-pw/test-results
101+
retention-days: 1
File renamed without changes.

.github/workflows/ci.yml

+9-22
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ on: [push, pull_request]
55
jobs:
66
tests:
77
runs-on: ${{ matrix.operating-system }}
8+
89
strategy:
910
matrix:
1011
operating-system: [ubuntu-latest]
1112
php-versions: ["8.3", "8.2"]
13+
1214
name: PHP ${{ matrix.php-versions }} test on ${{ matrix.operating-system }}
1315

1416
services:
@@ -30,8 +32,10 @@ jobs:
3032
with:
3133
php-version: ${{ matrix.php-versions }}
3234
extensions: curl, gd, intl, mbstring, openssl, pdo, pdo_mysql, tokenizer, zip
35+
ini-values: error_reporting=E_ALL
36+
tools: composer:v2
3337

34-
- name: Composer Install
38+
- name: Running Composer Install
3539
run: composer install
3640

3741
- name: Set Testing Environment
@@ -44,25 +48,8 @@ jobs:
4448
sed -i "s|^\(DB_USERNAME=\s*\).*$|\1root|" .env
4549
sed -i "s|^\(DB_PASSWORD=\s*\).*$|\1root|" .env
4650
47-
- name: Key Generate
48-
run: php artisan key:generate
49-
50-
- name: Complete ENV File
51-
run: |
52-
printf "The complete `.env` ... \n\n"
53-
cat .env
54-
55-
- name: Migrate Database
56-
run: php artisan migrate
57-
58-
- name: Seed Database
59-
run: php artisan db:seed
60-
61-
- name: Vendor Publish
62-
run: php artisan vendor:publish --provider=Webkul\\Core\\Providers\\CoreServiceProvider --force
63-
64-
- name: Optimize Stuffs
65-
run: php artisan optimize:clear
51+
- name: Running Krayin Installer
52+
run: php artisan krayin-crm::install --skip-env-check --skip-admin-creation
6653

67-
- name: Run Tests
68-
run: vendor/bin/pest
54+
- name: Running Pest Test
55+
run: vendor/bin/pest --parallel --colors=always

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Homestead.yaml
1515
/node_modules
1616
npm-debug.log
1717
package-lock.json
18+
/playwright-report
1819
/public/css
1920
/public/js
2021
/public/hot
@@ -26,3 +27,9 @@ package-lock.json
2627
/vendor
2728
yarn.lock
2829
yarn-error.log
30+
31+
# Playwright
32+
node_modules/
33+
/test-results/
34+
/blob-report/
35+
/playwright/.cache/

e2e/example.spec.ts

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
test('has title', async ({ page }) => {
4+
await page.goto('https://playwright.dev/');
5+
6+
// Expect a title "to contain" a substring.
7+
await expect(page).toHaveTitle(/Playwright/);
8+
});
9+
10+
test('get started link', async ({ page }) => {
11+
await page.goto('https://playwright.dev/');
12+
13+
// Click the get started link.
14+
await page.getByRole('link', { name: 'Get started' }).click();
15+
16+
// Expects page to have a heading with the name of Installation.
17+
await expect(page.getByRole('heading', { name: 'Installation' })).toBeVisible();
18+
});

package.json

+13-11
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
{
2-
"private": true,
3-
"type": "module",
4-
"scripts": {
5-
"dev": "vite",
6-
"build": "vite build"
7-
},
8-
"devDependencies": {
9-
"axios": "^1.6.4",
10-
"laravel-vite-plugin": "^1.0.0",
11-
"vite": "^5.0.0"
12-
}
2+
"private": true,
3+
"type": "module",
4+
"scripts": {
5+
"dev": "vite",
6+
"build": "vite build"
7+
},
8+
"devDependencies": {
9+
"@playwright/test": "^1.50.1",
10+
"@types/node": "^22.13.5",
11+
"axios": "^1.6.4",
12+
"laravel-vite-plugin": "^1.0.0",
13+
"vite": "^5.0.0"
14+
}
1315
}

packages/Webkul/Admin/.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
/node_modules
22
/package-lock.json
3-
npm-debug.log
3+
npm-debug.log
4+
/playwright-report
5+
/test-results

packages/Webkul/Admin/package.json

+7-2
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,27 @@
66
"build": "vite build"
77
},
88
"devDependencies": {
9+
"@playwright/test": "^1.50.1",
10+
"@types/node": "^22.7.8",
911
"autoprefixer": "^10.4.16",
10-
"axios": "^1.6.4",
12+
"axios": "^1.7.4",
1113
"laravel-vite-plugin": "^1.0",
1214
"postcss": "^8.4.23",
1315
"tailwindcss": "^3.3.2",
1416
"vite": "^5.4.12",
15-
"vue": "^3.4.19"
17+
"vue": "^3.4.21"
1618
},
1719
"dependencies": {
1820
"@vee-validate/i18n": "^4.9.1",
1921
"@vee-validate/rules": "^4.9.1",
2022
"@vitejs/plugin-vue": "^4.2.3",
2123
"chartjs-chart-funnel": "^4.2.1",
2224
"dompurify": "^3.1.7",
25+
"dotenv": "^16.4.7",
2326
"flatpickr": "^4.6.13",
2427
"mitt": "^3.0.1",
28+
"playwright": "^1.48.1",
29+
"readline-sync": "^1.4.10",
2530
"vee-validate": "^4.9.1",
2631
"vue-cal": "^4.9.0",
2732
"vue-flatpickr": "^2.3.0",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/playwright-report
2+
/test-results
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { defineConfig, devices } from "@playwright/test";
2+
import dotenv from "dotenv";
3+
import path from "path";
4+
import { fileURLToPath } from "url";
5+
6+
const __filename = fileURLToPath(import.meta.url);
7+
const __dirname = path.dirname(__filename);
8+
9+
dotenv.config({ path: path.resolve(__dirname, "../../../../../.env") });
10+
11+
export default defineConfig({
12+
testDir: "./tests",
13+
14+
timeout: 30 * 1000,
15+
16+
expect: { timeout: 20 * 1000 },
17+
18+
outputDir: "./test-results",
19+
20+
fullyParallel: false,
21+
22+
workers: 1,
23+
24+
forbidOnly: !!process.env.CI,
25+
26+
retries: 0,
27+
28+
reportSlowTests: null,
29+
30+
reporter: [
31+
[
32+
"html",
33+
{
34+
outputFolder: "./playwright-report",
35+
},
36+
],
37+
],
38+
39+
use: {
40+
baseURL: `${process.env.APP_URL}/`.replace(/\/+$/, "/"),
41+
screenshot: { mode: "only-on-failure", fullPage: true },
42+
video: "retain-on-failure",
43+
trace: "retain-on-failure",
44+
},
45+
46+
projects: [
47+
{
48+
name: "chromium",
49+
use: { ...devices["Desktop Chrome"] },
50+
},
51+
],
52+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { test as base, expect, type Page } from "@playwright/test";
2+
3+
type AdminFixtures = {
4+
adminPage: Page;
5+
};
6+
7+
export const test = base.extend<AdminFixtures>({
8+
adminPage: async ({ page }, use) => {
9+
const adminCredentials = {
10+
11+
password: "admin123",
12+
};
13+
14+
await page.goto("admin/login");
15+
await page.fill('input[name="email"]', adminCredentials.email);
16+
await page.fill('input[name="password"]', adminCredentials.password);
17+
await page.press('input[name="password"]', "Enter");
18+
19+
await page.waitForURL("**/admin/dashboard");
20+
21+
await use(page);
22+
},
23+
});
24+
25+
export { expect };
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { test, expect } from "../setup";
2+
3+
const adminCredentials = {
4+
5+
password: "admin123",
6+
};
7+
8+
test("should be able to login", async ({ page }) => {
9+
/**
10+
* Login as admin.
11+
*/
12+
await page.goto("admin/login");
13+
await page.getByPlaceholder("Email Address").click();
14+
await page.getByPlaceholder("Email Address").fill(adminCredentials.email);
15+
await page.getByPlaceholder("Password").click();
16+
await page.getByPlaceholder("Password").fill(adminCredentials.password);
17+
await page.getByRole("button", { name: "Sign In" }).click();
18+
19+
await expect(page.getByPlaceholder("Mega Search").first()).toBeVisible();
20+
});
21+
22+
test("should be able to logout", async ({ page }) => {
23+
/**
24+
* Login as admin.
25+
*/
26+
await page.goto("admin/login");
27+
await page.getByPlaceholder("Email Address").click();
28+
await page.getByPlaceholder("Email Address").fill(adminCredentials.email);
29+
await page.getByPlaceholder("Password").click();
30+
await page.getByPlaceholder("Password").fill(adminCredentials.password);
31+
await page.getByLabel("Sign In").click();
32+
await page.click("button:text('E')");
33+
await page.getByRole("link", { name: "Sign Out" }).click();
34+
35+
await page.waitForTimeout(5000);
36+
37+
await expect(page.getByPlaceholder("Password").first()).toBeVisible();
38+
});

packages/Webkul/Admin/tests/e2e-pw/tests/mail/draft.spec.ts

Whitespace-only changes.

0 commit comments

Comments
 (0)