Skip to content

Commit fa06c25

Browse files
committed
feat: Add SQLite DB utility, UI+DB integration test, and documentation. Enhance DBActions for SQLite. Update tests, sample data, and docs for robust Playwright automation.
1 parent 83154f3 commit fa06c25

30 files changed

Lines changed: 1529 additions & 11 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Explore the `README-ai.md` for details on AI test generation and advanced featur
2727

2828

2929

30-
## 🧪 Automated Test Scenarios
30+
## Automated Test Scenarios
3131

3232

3333
The framework covers critical user journeys, advanced flows, component-level tests, E2E test flows, and visual regression for K11 Software Solutions, including:
@@ -48,7 +48,7 @@ Each scenario validates real user interactions, UI consistency, business logic,
4848
---
4949

5050

51-
## 🏗️ Project Structure
51+
## Project Structure
5252

5353
```
5454
K11TechLab-playwright-javascript-ai-augmented-framework/
@@ -100,7 +100,7 @@ K11TechLab-playwright-javascript-ai-augmented-framework/
100100

101101
---
102102

103-
## 🧪 Sample Test Flows
103+
## Sample Test Flows
104104

105105

106106
### E2E Test Example (with UIElementActions)
@@ -133,7 +133,7 @@ Tests are business-readable, with implementation details handled in page objects
133133

134134
---
135135

136-
## 🔗 API Testing
136+
## API Testing
137137

138138
The framework supports API testing using Playwright's built-in APIRequestContext. You can:
139139
- Validate REST endpoints (GET, POST, PUT, DELETE, etc.)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"refresh": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoicmVmcmVzaCIsImV4cCI6MTc3MTMwMDYxMywiaWF0IjoxNzcwNjk1ODEzLCJqdGkiOiIzYjliOGVhOGU5NGU0MWY5YmRiOGVjZmE5MzJlODdhZSIsInVzZXJfaWQiOiIxIn0.qEq4E4-hMe8OR1pRs7H-bZS4WJWUeld1xrwcAg8Edcw",
3+
"access": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNzcwNjk5NDEzLCJpYXQiOjE3NzA2OTU4MTMsImp0aSI6IjRkYTQ4OTFjMDNjYzQzNzE5MmI0YTM2YzQxNzViYmY5IiwidXNlcl9pZCI6IjEifQ.lHUyVUAG4ajvdHQUqIXOlH89o1cyZhgX6rQvZGHmP8w"
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"refresh": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoicmVmcmVzaCIsImV4cCI6MTc3MTMwMDYxMywiaWF0IjoxNzcwNjk1ODEzLCJqdGkiOiI5ZTNkN2QwOGFmMjY0YzFlYjNjMTE2YzZmMzllNDNmZiIsInVzZXJfaWQiOiIxIn0.bbvBMCELuaiTsZEQJt68CAsTEwB5YZn1tT3Z4UabTyo",
3+
"access": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNzcwNjk5NDEzLCJpYXQiOjE3NzA2OTU4MTMsImp0aSI6ImMwODdmMjE5OTJlMTQ5NGJhYWFmNWJlMmMzYjNkNDBlIiwidXNlcl9pZCI6IjEifQ.zNBbNKFkIynap2QoJcmi_AETypO2QBrSTYgx219B_rY"
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"refresh": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoicmVmcmVzaCIsImV4cCI6MTc3MTMwMDYxNCwiaWF0IjoxNzcwNjk1ODE0LCJqdGkiOiIwNTg5MDQxYjY5ZTc0Y2FhOGEwNTk4MjY2ZTVhNTViZSIsInVzZXJfaWQiOiIxIn0.uJMy9SHToVBIGcMHJ9ADz7ylw-pCNd9NmXI_a_v53kA",
3+
"access": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNzcwNjk5NDE0LCJpYXQiOjE3NzA2OTU4MTQsImp0aSI6IjUwOThhMDQ4ZjhjOTQ5ZDBiZjgxNGRmNjFkZTVhZDBiIiwidXNlcl9pZCI6IjEifQ.-cv-Z9HeVXw63CQf0SrspEvPQPNfaOcE_u7fztWs7_4"
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"refresh": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoicmVmcmVzaCIsImV4cCI6MTc3MTMwMDYxNCwiaWF0IjoxNzcwNjk1ODE0LCJqdGkiOiIzNDI0OTVjYjMwZGQ0YWE3YjMzMjI2NDllYTBkMGZjNyIsInVzZXJfaWQiOiIxIn0.QlhPzgP-HJvsn2RvDtSogYaCnUikaLCpvoqbE3eyvqc",
3+
"access": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNzcwNjk5NDE0LCJpYXQiOjE3NzA2OTU4MTQsImp0aSI6Ijg1YTk4NzhkOTU3NzQzZGZhNTcxNDRlN2Q1N2I1YTUyIiwidXNlcl9pZCI6IjEifQ.IsSfFbN7PVsUvj4YKm3KGyVm80-1Nhq-lrwZ6jur1wc"
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"refresh": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoicmVmcmVzaCIsImV4cCI6MTc3MTMwMDYxNSwiaWF0IjoxNzcwNjk1ODE1LCJqdGkiOiJjYTBkMzJiZDdhMDg0NzFkYjlmMWU5NTdlMTg1NmU1MyIsInVzZXJfaWQiOiIxIn0._S6zaZL5KHduThUl5NYT-5R1JTZrPqeFg1gL5hiXRGg",
3+
"access": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNzcwNjk5NDE1LCJpYXQiOjE3NzA2OTU4MTUsImp0aSI6IjMyODFmZWE5OGUyZDQzZGI4ZTVmY2ZhNGFlZTZkZjdmIiwidXNlcl9pZCI6IjEifQ.ccFZkFrwle6ymKP1Zr8v8lJ38PnYNDWOmBAdcfwnt9k"
4+
}

doc/db-testing-playwright.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Database Testing with Playwright (SQLite Example)
2+
3+
This guide explains how to perform database integration testing in the K11TechLab Playwright JavaScript framework using a sample SQLite database.
4+
5+
---
6+
7+
## Why DB Testing?
8+
- Validate backend data consistency after UI/API actions
9+
- Ensure end-to-end flows update the database as expected
10+
- Enable data-driven test scenarios
11+
12+
---
13+
14+
## Sample Setup: SQLite
15+
16+
### 1. Sample Database
17+
- The file `testdata/sample_db.sqlite` is a SQLite database with a `users` table and sample data.
18+
- The schema and data are defined in `testdata/sample_db.sql`.
19+
- To recreate the database, run:
20+
```bash
21+
node testdata/create_sample_db.js
22+
```
23+
24+
### 2. DB Test Example
25+
File: `tests/db/SampleSQLiteDB.spec.js`
26+
```js
27+
const { test, expect } = require('@playwright/test');
28+
const sqlite3 = require('sqlite3').verbose();
29+
const path = require('path');
30+
31+
const dbPath = path.join(__dirname, '../../testdata/sample_db.sqlite');
32+
33+
function runQuery(db, query) {
34+
return new Promise((resolve, reject) => {
35+
db.all(query, (err, rows) => {
36+
if (err) reject(err);
37+
else resolve(rows);
38+
});
39+
});
40+
}
41+
42+
test.describe('Sample SQLite DB Integration', () => {
43+
let db;
44+
test.beforeAll(async () => {
45+
db = new sqlite3.Database(dbPath);
46+
});
47+
test.afterAll(async () => {
48+
db.close();
49+
});
50+
51+
test('should fetch all users from the users table', async () => {
52+
const rows = await runQuery(db, 'SELECT * FROM users;');
53+
expect(rows.length).toBeGreaterThan(0);
54+
expect(rows[0]).toHaveProperty('username');
55+
expect(rows[0]).toHaveProperty('email');
56+
});
57+
58+
test('should fetch admin user by username', async () => {
59+
const rows = await runQuery(db, "SELECT * FROM users WHERE username = 'admin';");
60+
expect(rows.length).toBe(1);
61+
expect(rows[0].email).toBe('admin@example.com');
62+
});
63+
});
64+
```
65+
66+
---
67+
68+
## Best Practices
69+
- Use a dedicated test database (never production!)
70+
- Clean up or reset data between tests if needed
71+
- Use environment variables for DB credentials in real DBs
72+
- For other DBs (Postgres, SQL Server), see `utils/DBActions.js`
73+
74+
---
75+
76+
## References
77+
- [sqlite3 Node.js package](https://www.npmjs.com/package/sqlite3)
78+
- [Playwright Test Docs](https://playwright.dev/docs/test-intro)
79+
- [DBActions Utility](../utils/DBActions.js)
80+
81+
---
82+
83+
**This example can be extended for other databases and more advanced scenarios.**

0 commit comments

Comments
 (0)