Skip to content

Commit b5ebef5

Browse files
committed
Navigation test
1 parent 34e86f4 commit b5ebef5

File tree

17 files changed

+589
-45
lines changed

17 files changed

+589
-45
lines changed

test/End-To-End/.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ADMIN_USERNAME=admin
2+
ADMIN_PASSWORD=admin

test/End-To-End/.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Environment variables for ZKEACMS End-to-End Tests
2+
ADMIN_USERNAME=admin
3+
ADMIN_PASSWORD=admin
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
description="create a playwright page object model"
2+
3+
prompt = """
4+
You are an expert in creating Playwright page object models for the ZKEACMS project. Your task is to generate a complete TypeScript page object model file based on a provided URL.
5+
6+
Here's what you should do:
7+
8+
1. **Open and Analyze the URL(Use playwright/browser_navigate tool)**: Use Playwright to open the user-provided URL and carefully analyze the page structure, elements, and functionality.
9+
- If the page require login, you can get user name, password from file @.env
10+
11+
2. **Identify Page Type**: Determine if this is a frontend (public) page or a backend (admin) page:
12+
- Frontend pages are typically public-facing pages like homepages, article pages, product pages, etc.
13+
- Backend pages are admin pages found under /admin/ URLs, including forms, dashboards, management interfaces.
14+
15+
3. **Select Base Class**:
16+
- For backend (admin) pages, extend the `AdminPageBase` class
17+
- For frontend pages, extend the generic `PageBase` class or create without a base class if not needed
18+
19+
4. **Create the Page Object Model File**:
20+
- Generate a complete TypeScript file that includes:
21+
* Proper imports for Playwright and base classes
22+
* A class that represents the page with a descriptive name
23+
* Constructor that accepts a Playwright Page object
24+
* Public methods that represent key actions on the page (clicks, fills, navigations)
25+
* Locator properties for important elements on the page
26+
* Get the page html (use javascript `console.log(document.body.innerHTML)` to get page html) so you can get the best locators:
27+
- Prioritize data-testid attributes: page.locator('[data-testid="button"]')
28+
- Use semantic selectors: page.getByRole('button', { name: 'Submit' })
29+
- Use text content: page.getByText('Save')
30+
- Use CSS selectors sparingly: page.locator('#id', '.class')
31+
- Use nth() for selecting elements by index: page.locator('.item').nth(0)
32+
- Use hasText() for filtering by text: page.locator('.item', { hasText: 'Item 1' })
33+
- Use has() for filtering by child elements: page.locator('.item', { has: page.locator('img') })
34+
- **Do not** use '[ref="exx"]': page.locator('[ref="e78"]')
35+
* Methods that support the main functionality of the page
36+
37+
5. **Follow Project Conventions**:
38+
- Use descriptive names for methods and properties
39+
- Follow the existing naming patterns in the ZKEACMS project
40+
- Include proper documentation comments for public methods
41+
- Implement proper error handling where needed
42+
- Use async/await pattern for Playwright operations
43+
44+
6. **Page Object Best Practices**:
45+
- Encapsulate the details of how to interact with page elements
46+
- Return appropriate values from methods (e.g., other page objects for navigations)
47+
- Keep methods focused on single responsibilities
48+
- Use locators that are stable and reliable
49+
50+
7. **File Location**: Place the generated file in the appropriate directory:
51+
- Admin pages go in src/admin/
52+
- Frontend pages go in src/models/ or a relevant subdirectory
53+
54+
EXAMPLE STRUCTURE:
55+
56+
For a frontend page:
57+
```
58+
import { Page } from '@playwright/test';
59+
import { PageBase } from './PageBase';
60+
61+
export class HomePage extends PageBase {
62+
63+
constructor(page: Page) {
64+
super(page);
65+
}
66+
67+
async navigateTo(): Promise<void> {
68+
await this.page.goto('/index');
69+
}
70+
}
71+
```
72+
73+
For an admin page:
74+
```
75+
import { Page } from '@playwright/test';
76+
import { AdminPageBase } from "../models/AdminPageBase";
77+
78+
export class ArticleManagementPage extends AdminPageBase {
79+
80+
constructor(page: Page) {
81+
super(page);
82+
}
83+
84+
async navigateTo(): Promise<void> {
85+
await this.page.goto('/admin/article');
86+
}
87+
88+
}
89+
```
90+
91+
Analyze the URL provided by the user, determine the page type, and create the appropriate page object model file.
92+
"""
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"mcpServers": {
3+
"playwright": {
4+
"command": "npx",
5+
"args": [
6+
"@playwright/mcp@latest",
7+
"--browser=chromium"
8+
]
9+
}
10+
},
11+
"$version": 2
12+
}

test/End-To-End/QWEN.md

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# ZKEACMS End-to-End Testing Project
2+
3+
## Project Overview
4+
5+
This is an End-to-End (E2E) testing project for the ZKEACMS Content Management System. It uses Playwright as the testing framework to validate the functionality of the ZKEACMS admin interface, specifically focusing on page management capabilities.
6+
7+
The project contains automated tests that simulate user interactions with the ZKEACMS admin panel, particularly around page creation, editing, and publishing functionality.
8+
9+
## Technology Stack
10+
11+
- **Testing Framework**: Playwright (v1.56.1)
12+
- **Language**: TypeScript
13+
- **Package Manager**: npm
14+
- **Target Application**: ZKEACMS
15+
16+
## Project Structure
17+
18+
```
19+
test/End-To-End/
20+
├── package.json # Project dependencies and configuration
21+
├── playwright.config.ts # Playwright configuration
22+
├── src/ # Page object models and helper classes
23+
│ ├── admin/ # Admin-specific page models
24+
│ │ ├── PageDashboardPage.ts # Page dashboard model
25+
│ │ └── PageFormPage.ts # Page form model
26+
│ └── models/ # Base page models
27+
│ └── AdminPageBase.ts # Base admin page class
28+
├── tests/ # Test specifications
29+
│ ├── example.spec.ts # Example test file
30+
│ └── admin/
31+
│ └── page/
32+
│ └── 01-basic-function-test.spec.ts # Basic page functionality tests
33+
├── node_modules/ # Dependencies (generated)
34+
├── playwright-report/ # Test reports (generated)
35+
└── test-results/ # Test results (generated)
36+
```
37+
38+
## Configuration
39+
40+
The Playwright configuration is set up with:
41+
- Tests run in parallel across multiple browsers (Chromium, Firefox, Webkit)
42+
- Retry logic for failed tests
43+
- HTML reporter for test results
44+
- Trace collection on first retry for debugging
45+
46+
## Key Functionality Tested
47+
48+
### Page Creation Tests
49+
- Creating pages with required fields
50+
- Handling validation errors for missing fields
51+
- Publishing pages without widgets
52+
53+
### Admin Authentication
54+
- Login functionality with username/password
55+
- Session management
56+
57+
### Page Object Models
58+
59+
#### AdminPageBase
60+
- Base class containing common admin functionality
61+
- Login and logout methods
62+
- Provides authentication for admin operations
63+
64+
#### PageFormPage
65+
- Handles page creation form interactions
66+
- Fills page details like name, title, path, layout, etc.
67+
- Submits forms and verifies creation results
68+
- Supports publishing pages from the design view
69+
70+
#### PageDashboardPage
71+
- Manages interactions with the page dashboard
72+
- Navigates to the page management area
73+
- Waits for data loading
74+
75+
## Running Tests
76+
77+
To run the tests locally:
78+
79+
1. Ensure you have Node.js installed
80+
2. Install dependencies:
81+
```
82+
npm install
83+
```
84+
3. Run all tests:
85+
```
86+
npx playwright test
87+
```
88+
4. Run tests in UI mode:
89+
```
90+
npx playwright test --ui
91+
```
92+
5. Run tests for a specific browser:
93+
```
94+
npx playwright test --project=chromium
95+
```
96+
97+
To run tests against a local instance of ZKEACMS instead of the demo site, update the baseURL in `playwright.config.ts` to point to your local installation.
98+
99+
## Development Conventions
100+
101+
- Tests follow the Page Object Model pattern for better maintainability
102+
- TypeScript interfaces are used to define data structures (e.g., PageFormData)
103+
- Each test file should focus on a specific set of functionality
104+
- Tests use meaningful names that describe the functionality being tested
105+
- Wait strategies are implemented to handle asynchronous operations properly
106+
- Credentials are managed using environment variables for security
107+
108+
## Credential Management
109+
110+
For security reasons, the tests now support the following approaches for authentication:
111+
112+
1. **Environment Variables**: Set `ADMIN_USERNAME` and `ADMIN_PASSWORD` environment variables
113+
2. **Fallback Credentials**: If environment variables aren't set, the system defaults to 'admin'/'admin'
114+
115+
To use custom credentials, create a `.env` file or set the environment variables:
116+
117+
```
118+
ADMIN_USERNAME=your_username
119+
ADMIN_PASSWORD=your_password
120+
```
121+
122+
An example file `.env.example` has been provided as a template.
123+
124+
## Current Test Coverage
125+
126+
The current tests validate:
127+
128+
1. **Page Creation**: Creating a page with all required fields
129+
2. **Form Validation**: Ensuring required fields are validated
130+
3. **Page Publishing**: Publishing a page without widgets to make it public
131+
4. **Admin Authentication**: Logging into the admin panel using secure credential management
132+
133+
## Reporting
134+
135+
- Test results are stored in the `test-results/` directory
136+
- HTML reports can be generated to `playwright-report/` directory
137+
- Trace files are collected on first retry to help debug failed tests

test/End-To-End/package-lock.json

Lines changed: 15 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/End-To-End/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
"version": "1.0.0",
44
"description": "",
55
"main": "index.js",
6-
"scripts": {},
6+
"scripts": {
7+
"test": "npx playwright test"
8+
},
79
"keywords": [],
810
"author": "",
911
"license": "ISC",
1012
"type": "commonjs",
1113
"devDependencies": {
1214
"@playwright/test": "^1.56.1",
13-
"@types/node": "^24.10.0"
15+
"@types/node": "^24.10.0",
16+
"dotenv": "^17.2.3"
1417
}
1518
}

test/End-To-End/playwright.config.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { defineConfig, devices } from '@playwright/test';
44
* Read environment variables from file.
55
* https://github.com/motdotla/dotenv
66
*/
7-
// import dotenv from 'dotenv';
8-
// import path from 'path';
9-
// dotenv.config({ path: path.resolve(__dirname, '.env') });
7+
import dotenv from 'dotenv';
8+
import path from 'path';
9+
dotenv.config({ path: path.resolve(__dirname, '.env') });
1010

1111
/**
1212
* See https://playwright.dev/docs/test-configuration.
@@ -26,7 +26,7 @@ export default defineConfig({
2626
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
2727
use: {
2828
/* Base URL to use in actions like `await page.goto('')`. */
29-
baseURL: 'http://demo.zkea.net',
29+
baseURL: 'http://localhost:5000',
3030

3131
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
3232
trace: 'on-first-retry',
@@ -39,15 +39,15 @@ export default defineConfig({
3939
use: { ...devices['Desktop Chrome'] },
4040
},
4141

42-
{
43-
name: 'firefox',
44-
use: { ...devices['Desktop Firefox'] },
45-
},
42+
// {
43+
// name: 'firefox',
44+
// use: { ...devices['Desktop Firefox'] },
45+
// },
4646

47-
{
48-
name: 'webkit',
49-
use: { ...devices['Desktop Safari'] },
50-
},
47+
// {
48+
// name: 'webkit',
49+
// use: { ...devices['Desktop Safari'] },
50+
// },
5151

5252
/* Test against mobile viewports. */
5353
// {

0 commit comments

Comments
 (0)