simple-playwright-framework 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +35 -13
- package/scripts/init-demo-project.js +153 -0
- package/scripts/init-framework-project.js +102 -0
- package/scripts/setup-framework.js +0 -70
package/package.json
CHANGED
|
@@ -1,23 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "simple-playwright-framework",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
|
+
"description": "A modular Playwright framework with fixtures, loaders, and demo scaffolding.",
|
|
4
5
|
"main": "dist/index.js",
|
|
5
6
|
"types": "dist/index.d.ts",
|
|
6
7
|
"scripts": {
|
|
7
|
-
"clean": "rimraf dist .cache",
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
"peerDependencies": {
|
|
14
|
-
"@playwright/test": "^1.58.2"
|
|
8
|
+
"clean": "rimraf node_modules package-lock.json dist .cache",
|
|
9
|
+
"reinstall": "npm install",
|
|
10
|
+
"compile": "tsc -p tsconfig.json",
|
|
11
|
+
"build": "npm run clean && npm run reinstall && npm run compile",
|
|
12
|
+
"test": "rimraf playwright-report && playwright test",
|
|
13
|
+
"report": "playwright show-report"
|
|
15
14
|
},
|
|
16
15
|
"bin": {
|
|
17
|
-
"init-
|
|
16
|
+
"init-framework-project": "./scripts/init-framework-project.js",
|
|
17
|
+
"init-demo-project": "./scripts/init-demo-project.js"
|
|
18
18
|
},
|
|
19
19
|
"files": [
|
|
20
|
-
"dist",
|
|
21
|
-
"scripts"
|
|
22
|
-
|
|
20
|
+
"dist/**/*",
|
|
21
|
+
"scripts/init-framework-project.js",
|
|
22
|
+
"scripts/init-demo-project.js"
|
|
23
|
+
],
|
|
24
|
+
"keywords": [
|
|
25
|
+
"playwright",
|
|
26
|
+
"framework",
|
|
27
|
+
"testing",
|
|
28
|
+
"automation",
|
|
29
|
+
"fixtures",
|
|
30
|
+
"typescript"
|
|
31
|
+
],
|
|
32
|
+
"author": "Udayakumar",
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@framework/fixtures": "file:../framework"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@playwright/test": "^1.58.2",
|
|
39
|
+
"@types/node": "^25.2.3",
|
|
40
|
+
"rimraf": "^6.1.2",
|
|
41
|
+
"ts-node": "^10.9.2",
|
|
42
|
+
"tsconfig-paths": "^4.2.0",
|
|
43
|
+
"typescript": "^5.9.3"
|
|
44
|
+
}
|
|
23
45
|
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const fs = require("fs");
|
|
3
|
+
const path = require("path");
|
|
4
|
+
|
|
5
|
+
const cwd = process.cwd();
|
|
6
|
+
const demoDir = path.join(cwd, "demo-project");
|
|
7
|
+
fs.mkdirSync(demoDir, { recursive: true });
|
|
8
|
+
|
|
9
|
+
// package.json
|
|
10
|
+
fs.writeFileSync(path.join(demoDir, "package.json"), JSON.stringify({
|
|
11
|
+
name: "demo-project",
|
|
12
|
+
version: "1.0.0",
|
|
13
|
+
private: true,
|
|
14
|
+
scripts: { test: "playwright test" },
|
|
15
|
+
devDependencies: {
|
|
16
|
+
"@playwright/test": "^1.58.2",
|
|
17
|
+
"simple-playwright-framework": "latest"
|
|
18
|
+
}
|
|
19
|
+
}, null, 2));
|
|
20
|
+
|
|
21
|
+
// playwright.config.ts
|
|
22
|
+
fs.writeFileSync(path.join(demoDir, "playwright.config.ts"), `import { defineConfig } from '@playwright/test';
|
|
23
|
+
export default defineConfig({
|
|
24
|
+
testDir: './tests',
|
|
25
|
+
reporter: [['html']],
|
|
26
|
+
});
|
|
27
|
+
`);
|
|
28
|
+
|
|
29
|
+
// config
|
|
30
|
+
const configDir = path.join(demoDir, "config");
|
|
31
|
+
fs.mkdirSync(configDir, { recursive: true });
|
|
32
|
+
fs.writeFileSync(path.join(configDir, "environments.json"), JSON.stringify({
|
|
33
|
+
defaults: { timeout: 30000, retries: 1, autoLaunch: false },
|
|
34
|
+
dev: { baseUrl: "https://dev.orangehrm.example.com", authStorage: { enabled: true, provider: "OrangeHRMLogin" } },
|
|
35
|
+
qa: { baseUrl: "https://qa.orangehrm.example.com", authStorage: { enabled: true, provider: "OrangeHRMLogin" } },
|
|
36
|
+
prod: { baseUrl: "https://opensource-demo.orangehrmlive.com/", authStorage: { enabled: true, provider: "OrangeHRMLogin" } }
|
|
37
|
+
}, null, 2));
|
|
38
|
+
|
|
39
|
+
// data
|
|
40
|
+
const dataDir = path.join(demoDir, "data/login");
|
|
41
|
+
fs.mkdirSync(dataDir, { recursive: true });
|
|
42
|
+
fs.writeFileSync(path.join(dataDir, "login.json"), JSON.stringify({
|
|
43
|
+
prod: {
|
|
44
|
+
users: {
|
|
45
|
+
admin: { username: "Admin", password: "admin123" },
|
|
46
|
+
employee: { username: "Emp", password: "emp123" },
|
|
47
|
+
locked: { username: "LockedUser", password: "locked123" }
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}, null, 2));
|
|
51
|
+
fs.writeFileSync(path.join(dataDir, "login.scenarios.json"), JSON.stringify({
|
|
52
|
+
prod: [
|
|
53
|
+
{ name: "Valid login", url: "https://opensource-demo.orangehrmlive.com/", username: "Admin", password: "admin123", expected: "success", tags: ["smoke"] },
|
|
54
|
+
{ name: "Invalid login", url: "https://opensource-demo.orangehrmlive.com/", username: "WrongUser", password: "WrongPass", expected: "failure", tags: ["negative"] }
|
|
55
|
+
]
|
|
56
|
+
}, null, 2));
|
|
57
|
+
fs.writeFileSync(path.join(dataDir, "loginwithauthstorage.json"), JSON.stringify({
|
|
58
|
+
prod: { users: { admin: { username: "Admin", password: "admin123" } } }
|
|
59
|
+
}, null, 2));
|
|
60
|
+
|
|
61
|
+
// auth
|
|
62
|
+
const authDir = path.join(demoDir, "auth");
|
|
63
|
+
fs.mkdirSync(authDir, { recursive: true });
|
|
64
|
+
fs.writeFileSync(path.join(authDir, "orangehrm.login.ts"), `import { Page } from '@playwright/test';
|
|
65
|
+
import { AuthProvider } from 'simple-playwright-framework/fixtures/src/types/auth';
|
|
66
|
+
export class OrangeHRMLogin implements AuthProvider {
|
|
67
|
+
constructor(private creds: { username: string; password: string }) {}
|
|
68
|
+
async login(page: Page): Promise<void> {
|
|
69
|
+
await page.fill("input[name='username']", this.creds.username);
|
|
70
|
+
await page.fill("input[name='password']", this.creds.password);
|
|
71
|
+
await page.click("button[type='submit']");
|
|
72
|
+
await page.waitForURL("**/dashboard/**");
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
`);
|
|
76
|
+
|
|
77
|
+
// storage
|
|
78
|
+
const storageDir = path.join(demoDir, "storage");
|
|
79
|
+
fs.mkdirSync(storageDir, { recursive: true });
|
|
80
|
+
fs.writeFileSync(path.join(storageDir, "authStorage.json"), JSON.stringify({
|
|
81
|
+
session: { validityMinutes: 30, provider: "OrangeHRMLogin" }
|
|
82
|
+
}, null, 2));
|
|
83
|
+
|
|
84
|
+
// tests
|
|
85
|
+
const testsDir = path.join(demoDir, "tests");
|
|
86
|
+
fs.mkdirSync(path.join(testsDir, "login"), { recursive: true });
|
|
87
|
+
fs.mkdirSync(path.join(testsDir, "filehandling"), { recursive: true });
|
|
88
|
+
|
|
89
|
+
fs.writeFileSync(path.join(testsDir, "login/login.test.ts"), `import { test, expect } from 'simple-playwright-framework';
|
|
90
|
+
test('login with Admin user @smoke', async ({ page, envConfig, td }) => {
|
|
91
|
+
await page.goto(envConfig.baseUrl);
|
|
92
|
+
await page.fill('input[name="username"]', td.users.admin.username);
|
|
93
|
+
await page.fill('input[name="password"]', td.users.admin.password);
|
|
94
|
+
await page.click('button[type="submit"]');
|
|
95
|
+
await expect(page).toHaveURL(/dashboard/);
|
|
96
|
+
});
|
|
97
|
+
`);
|
|
98
|
+
|
|
99
|
+
fs.writeFileSync(path.join(testsDir, "login/login.scenarios.spec.ts"), `import { test, expect, scenarioLoader, initAuthSession } from 'simple-playwright-framework';
|
|
100
|
+
import { providerRegistry } from '@project/auth';
|
|
101
|
+
const scenarios = scenarioLoader(__filename);
|
|
102
|
+
test.describe.parallel("Login scenarios", () => {
|
|
103
|
+
for (const sc of scenarios) {
|
|
104
|
+
test(\`Scenario: \${sc.name}\`, async ({ page, envConfig }) => {
|
|
105
|
+
await page.goto(envConfig.baseUrl);
|
|
106
|
+
await initAuthSession(page, envConfig.authStorage!, { username: sc.username, password: sc.password }, providerRegistry);
|
|
107
|
+
if (sc.expected === "success") {
|
|
108
|
+
await expect(page).toHaveURL(/.*dashboard.*/);
|
|
109
|
+
} else {
|
|
110
|
+
await expect(page.locator(".oxd-alert-content")).toBeVisible();
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
`);
|
|
116
|
+
|
|
117
|
+
fs.writeFileSync(path.join(testsDir, "login/loginwithauthstorage.spec.ts"), `import { test, expect, initAuthSession } from 'simple-playwright-framework';
|
|
118
|
+
import { providerRegistry } from '@project/auth';
|
|
119
|
+
test('login with Admin user using Auth Storage', async ({ page, envConfig, td }) => {
|
|
120
|
+
await page.goto(envConfig.baseUrl);
|
|
121
|
+
await initAuthSession(page, envConfig.authStorage!, { username: td.users.admin.username, password: td.users.admin.password }, providerRegistry);
|
|
122
|
+
await expect(page).toHaveURL(/dashboard/);
|
|
123
|
+
});
|
|
124
|
+
`);
|
|
125
|
+
|
|
126
|
+
fs.writeFileSync(path.join(testsDir, "login/login.testrail.spec.ts"), `import { test, expect } from 'simple-playwright-framework';
|
|
127
|
+
test('Login linked to TestRail case C1234', async ({ page, envConfig, testrail }) => {
|
|
128
|
+
await page.goto(envConfig.baseUrl);
|
|
129
|
+
await page.fill('input[name="username"]', 'Admin');
|
|
130
|
+
await page.fill('input[name="password"]', 'admin123');
|
|
131
|
+
await page.click('button[type="submit"]');
|
|
132
|
+
try {
|
|
133
|
+
await expect(page).toHaveURL(/dashboard/);
|
|
134
|
+
await testrail.addResult(1234, 1, "Login passed ✅");
|
|
135
|
+
} catch (err) {
|
|
136
|
+
await testrail.addResult(1234, 5, "Login failed ❌");
|
|
137
|
+
throw err;
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
`);
|
|
141
|
+
|
|
142
|
+
fs.writeFileSync(path.join(testsDir, "filehandling/filehandling.spec.ts"), `import { test } from 'simple-playwright-framework/fixtures';
|
|
143
|
+
test("upload and download demo", async ({ page, fileUtils }) => {
|
|
144
|
+
await page.goto("https://the-internet.herokuapp.com/upload");
|
|
145
|
+
await fileUtils.uploadFile("#file-upload", "data/ui/sample.txt");
|
|
146
|
+
await page.click("#file-submit");
|
|
147
|
+
await page.goto("https://the-internet.herokuapp.com/download");
|
|
148
|
+
const downloadedPath = await fileUtils.downloadFile("a[href*='some-file.txt']");
|
|
149
|
+
console.log("Downloaded file path:", downloadedPath);
|
|
150
|
+
});
|
|
151
|
+
`);
|
|
152
|
+
|
|
153
|
+
console.log("✅ Demo project created in ./demo-project with configs, data, auth, storage, and sample tests.");
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const fs = require("fs");
|
|
3
|
+
const path = require("path");
|
|
4
|
+
|
|
5
|
+
const cwd = process.cwd();
|
|
6
|
+
const demoDir = path.join(cwd, "demo-project");
|
|
7
|
+
fs.mkdirSync(demoDir, { recursive: true });
|
|
8
|
+
|
|
9
|
+
// package.json
|
|
10
|
+
fs.writeFileSync(path.join(demoDir, "package.json"), JSON.stringify({
|
|
11
|
+
name: "demo-project",
|
|
12
|
+
version: "1.0.0",
|
|
13
|
+
private: true,
|
|
14
|
+
scripts: { test: "playwright test" },
|
|
15
|
+
devDependencies: {
|
|
16
|
+
"@playwright/test": "^1.58.2",
|
|
17
|
+
"simple-playwright-framework": "latest"
|
|
18
|
+
}
|
|
19
|
+
}, null, 2));
|
|
20
|
+
|
|
21
|
+
// config
|
|
22
|
+
fs.mkdirSync(path.join(demoDir, "config"), { recursive: true });
|
|
23
|
+
fs.writeFileSync(path.join(demoDir, "config/environments.json"), JSON.stringify({
|
|
24
|
+
defaults: { timeout: 30000, retries: 1, autoLaunch: false },
|
|
25
|
+
dev: { baseUrl: "https://dev.orangehrm.example.com", authStorage: { enabled: true, provider: "OrangeHRMLogin" } },
|
|
26
|
+
qa: { baseUrl: "https://qa.orangehrm.example.com", authStorage: { enabled: true, provider: "OrangeHRMLogin" } },
|
|
27
|
+
prod: { baseUrl: "https://opensource-demo.orangehrmlive.com/", authStorage: { enabled: true, provider: "OrangeHRMLogin" } }
|
|
28
|
+
}, null, 2));
|
|
29
|
+
|
|
30
|
+
// data
|
|
31
|
+
const dataDir = path.join(demoDir, "data/login");
|
|
32
|
+
fs.mkdirSync(dataDir, { recursive: true });
|
|
33
|
+
fs.writeFileSync(path.join(dataDir, "login.json"), JSON.stringify({
|
|
34
|
+
prod: { users: { admin: { username: "Admin", password: "admin123" }, employee: { username: "Emp", password: "emp123" } }
|
|
35
|
+
}, null, 2));
|
|
36
|
+
fs.writeFileSync(path.join(dataDir, "login.scenarios.json"), JSON.stringify({
|
|
37
|
+
prod: [
|
|
38
|
+
{ name: "Valid login", url: "https://opensource-demo.orangehrmlive.com/", username: "Admin", password: "admin123", expected: "success" },
|
|
39
|
+
{ name: "Invalid login", url: "https://opensource-demo.orangehrmlive.com/", username: "WrongUser", password: "WrongPass", expected: "failure" }
|
|
40
|
+
]
|
|
41
|
+
}, null, 2));
|
|
42
|
+
fs.writeFileSync(path.join(dataDir, "loginwithauthstorage.json"), JSON.stringify({
|
|
43
|
+
prod: { users: { admin: { username: "Admin", password: "admin123" } } }
|
|
44
|
+
}, null, 2));
|
|
45
|
+
|
|
46
|
+
// auth
|
|
47
|
+
const authDir = path.join(demoDir, "auth");
|
|
48
|
+
fs.mkdirSync(authDir, { recursive: true });
|
|
49
|
+
fs.writeFileSync(path.join(authDir, "orangehrm.login.ts"), `import { Page } from '@playwright/test';
|
|
50
|
+
import { AuthProvider } from 'simple-playwright-framework/fixtures/src/types/auth';
|
|
51
|
+
export class OrangeHRMLogin implements AuthProvider {
|
|
52
|
+
constructor(private creds: { username: string; password: string }) {}
|
|
53
|
+
async login(page: Page): Promise<void> {
|
|
54
|
+
await page.fill("input[name='username']", this.creds.username);
|
|
55
|
+
await page.fill("input[name='password']", this.creds.password);
|
|
56
|
+
await page.click("button[type='submit']");
|
|
57
|
+
await page.waitForURL("**/dashboard/**");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
`);
|
|
61
|
+
|
|
62
|
+
// storage
|
|
63
|
+
const storageDir = path.join(demoDir, "storage");
|
|
64
|
+
fs.mkdirSync(storageDir, { recursive: true });
|
|
65
|
+
fs.writeFileSync(path.join(storageDir, "authStorage.json"), JSON.stringify({
|
|
66
|
+
session: { validityMinutes: 30, provider: "OrangeHRMLogin" }
|
|
67
|
+
}, null, 2));
|
|
68
|
+
|
|
69
|
+
// tests
|
|
70
|
+
const testsDir = path.join(demoDir, "tests");
|
|
71
|
+
fs.mkdirSync(path.join(testsDir, "login"), { recursive: true });
|
|
72
|
+
fs.mkdirSync(path.join(testsDir, "filehandling"), { recursive: true });
|
|
73
|
+
|
|
74
|
+
fs.writeFileSync(path.join(testsDir, "login/login.test.ts"), `import { test, expect } from 'simple-playwright-framework';
|
|
75
|
+
test('login with Admin user @smoke', async ({ page, envConfig, td }) => {
|
|
76
|
+
await page.goto(envConfig.baseUrl);
|
|
77
|
+
await page.fill('input[name="username"]', td.users.admin.username);
|
|
78
|
+
await page.fill('input[name="password"]', td.users.admin.password);
|
|
79
|
+
await page.click('button[type="submit"]');
|
|
80
|
+
await expect(page).toHaveURL(/dashboard/);
|
|
81
|
+
});
|
|
82
|
+
`);
|
|
83
|
+
|
|
84
|
+
fs.writeFileSync(path.join(testsDir, "login/login.scenarios.spec.ts"), `import { test, expect, scenarioLoader, initAuthSession } from 'simple-playwright-framework';
|
|
85
|
+
import { providerRegistry } from '@project/auth';
|
|
86
|
+
const scenarios = scenarioLoader(__filename);
|
|
87
|
+
test.describe.parallel("Login scenarios", () => {
|
|
88
|
+
for (const sc of scenarios) {
|
|
89
|
+
test(\`Scenario: \${sc.name}\`, async ({ page, envConfig }) => {
|
|
90
|
+
await page.goto(envConfig.baseUrl);
|
|
91
|
+
await initAuthSession(page, envConfig.authStorage!, { username: sc.username, password: sc.password }, providerRegistry);
|
|
92
|
+
if (sc.expected === "success") {
|
|
93
|
+
await expect(page).toHaveURL(/.*dashboard.*/);
|
|
94
|
+
} else {
|
|
95
|
+
await expect(page.locator(".oxd-alert-content")).toBeVisible();
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
`);
|
|
101
|
+
|
|
102
|
+
fs.writeFileSync(path.join(testsDir, "login/loginwithauthstorage.spec.ts"), `import { test, expect, initAuthSession } from '
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import fs from "fs";
|
|
3
|
-
import path from "path";
|
|
4
|
-
import readline from "readline";
|
|
5
|
-
|
|
6
|
-
const rl = readline.createInterface({
|
|
7
|
-
input: process.stdin,
|
|
8
|
-
output: process.stdout,
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
function ask(question, defaultValue) {
|
|
12
|
-
return new Promise(resolve => {
|
|
13
|
-
rl.question(`${question} (${defaultValue}): `, answer => {
|
|
14
|
-
resolve(answer.trim() || defaultValue);
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
async function main() {
|
|
20
|
-
console.log("🚀 Init Sample Playwright Project");
|
|
21
|
-
|
|
22
|
-
const projectName = await ask("Project name", "sample-project");
|
|
23
|
-
const includeAuth = await ask("Include auth example? yes/no", "yes");
|
|
24
|
-
const includeData = await ask("Include data example? yes/no", "yes");
|
|
25
|
-
|
|
26
|
-
rl.close();
|
|
27
|
-
|
|
28
|
-
const projectDir = path.join(process.cwd(), projectName);
|
|
29
|
-
fs.mkdirSync(projectDir, { recursive: true });
|
|
30
|
-
|
|
31
|
-
// Config
|
|
32
|
-
fs.mkdirSync(path.join(projectDir, "config"), { recursive: true });
|
|
33
|
-
fs.writeFileSync(
|
|
34
|
-
path.join(projectDir, "config", "environments.json"),
|
|
35
|
-
JSON.stringify({ qa: { baseUrl: "http://localhost:3000" } }, null, 2)
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
// Tests
|
|
39
|
-
fs.mkdirSync(path.join(projectDir, "tests", "ui"), { recursive: true });
|
|
40
|
-
fs.writeFileSync(
|
|
41
|
-
path.join(projectDir, "tests", "ui", "login.spec.ts"),
|
|
42
|
-
`import { test, expect } from '@playwright/test';
|
|
43
|
-
|
|
44
|
-
test('login example', async ({ page }) => {
|
|
45
|
-
await page.goto('http://localhost:3000/login');
|
|
46
|
-
await expect(page).toHaveTitle(/Login/);
|
|
47
|
-
});`
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
if (includeAuth.toLowerCase() === "yes") {
|
|
51
|
-
fs.mkdirSync(path.join(projectDir, "auth"), { recursive: true });
|
|
52
|
-
fs.writeFileSync(
|
|
53
|
-
path.join(projectDir, "auth", "index.ts"),
|
|
54
|
-
`export const creds = { username: "testuser", password: "testpass" };`
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (includeData.toLowerCase() === "yes") {
|
|
59
|
-
fs.mkdirSync(path.join(projectDir, "data", "ui"), { recursive: true });
|
|
60
|
-
fs.writeFileSync(
|
|
61
|
-
path.join(projectDir, "data", "ui", "sample.txt"),
|
|
62
|
-
"Sample test data"
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
console.log(`✅ Sample project created in ${projectDir}`);
|
|
67
|
-
console.log(`👉 Next steps:\n cd ${projectName}\n npx playwright test`);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
main();
|