simple-playwright-framework 0.0.10 → 0.0.12
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 +1 -1
- package/scripts/init-demo-project.js +68 -37
package/package.json
CHANGED
|
@@ -62,7 +62,15 @@ writeFileSafe(path.join(demoDir, "tsconfig.json"),
|
|
|
62
62
|
// -------------------- playwright.config.ts --------------------
|
|
63
63
|
writeFileSafe(path.join(demoDir, "playwright.config.ts"),
|
|
64
64
|
`import { defineConfig } from '@playwright/test';
|
|
65
|
-
|
|
65
|
+
|
|
66
|
+
export default defineConfig({
|
|
67
|
+
testDir: './tests',
|
|
68
|
+
reporter: [['html']],
|
|
69
|
+
use: {
|
|
70
|
+
// Default environment for scenarioLoader
|
|
71
|
+
env: process.env.TEST_ENV || "prod",
|
|
72
|
+
},
|
|
73
|
+
});
|
|
66
74
|
`);
|
|
67
75
|
|
|
68
76
|
// -------------------- environments.json --------------------
|
|
@@ -98,37 +106,6 @@ export class OrangeHRMLogin implements AuthProvider {
|
|
|
98
106
|
}
|
|
99
107
|
`);
|
|
100
108
|
|
|
101
|
-
// -------------------- FileUtils --------------------
|
|
102
|
-
writeFileSafe(path.join(demoDir, "utils/file-utils.ts"),
|
|
103
|
-
`import { Page } from "@playwright/test";
|
|
104
|
-
import fs from "fs";
|
|
105
|
-
import path from "path";
|
|
106
|
-
|
|
107
|
-
export class FileUtils {
|
|
108
|
-
constructor(private page: Page) {}
|
|
109
|
-
|
|
110
|
-
async uploadFile(selector: string, filePath: string) {
|
|
111
|
-
const absolutePath = path.resolve(filePath);
|
|
112
|
-
if (!fs.existsSync(absolutePath)) {
|
|
113
|
-
throw new Error(\`❌ File not found: \${absolutePath}\`);
|
|
114
|
-
}
|
|
115
|
-
await this.page.setInputFiles(selector, absolutePath);
|
|
116
|
-
console.log(\`✅ Uploaded file: \${absolutePath}\`);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
async downloadFile(selector: string, downloadDir: string = "downloads") {
|
|
120
|
-
const downloadPromise = this.page.waitForEvent("download");
|
|
121
|
-
await this.page.click(selector);
|
|
122
|
-
const download = await downloadPromise;
|
|
123
|
-
|
|
124
|
-
const filePath = path.join(downloadDir, await download.suggestedFilename());
|
|
125
|
-
await download.saveAs(filePath);
|
|
126
|
-
console.log(\`✅ File downloaded to: \${filePath}\`);
|
|
127
|
-
return filePath;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
`);
|
|
131
|
-
|
|
132
109
|
// -------------------- Data --------------------
|
|
133
110
|
writeFileSafe(path.join(demoDir, "data/login/login.json"),
|
|
134
111
|
JSON.stringify({
|
|
@@ -168,6 +145,19 @@ writeFileSafe(path.join(demoDir, "storage/authStorage.json"),
|
|
|
168
145
|
);
|
|
169
146
|
|
|
170
147
|
// -------------------- Tests --------------------
|
|
148
|
+
// Login basic test
|
|
149
|
+
writeFileSafe(path.join(demoDir, "tests/login/login.test.ts"),
|
|
150
|
+
`import { test, expect } from 'simple-playwright-framework';
|
|
151
|
+
test('login with Admin user @smoke', async ({ page, envConfig, td }) => {
|
|
152
|
+
await page.goto(envConfig.baseUrl);
|
|
153
|
+
await page.fill('input[name="username"]', td.users.admin.username);
|
|
154
|
+
await page.fill('input[name="password"]', td.users.admin.password);
|
|
155
|
+
await page.click('button[type="submit"]');
|
|
156
|
+
await expect(page).toHaveURL(/dashboard/);
|
|
157
|
+
});
|
|
158
|
+
`);
|
|
159
|
+
|
|
160
|
+
// Login scenarios
|
|
171
161
|
writeFileSafe(path.join(demoDir, "tests/login/login.scenarios.spec.ts"),
|
|
172
162
|
`import { test, expect, scenarioLoader, initAuthSession } from 'simple-playwright-framework';
|
|
173
163
|
import { providerRegistry } from '@demo-project/auth';
|
|
@@ -187,23 +177,56 @@ test.describe.parallel("Login scenarios", () => {
|
|
|
187
177
|
});
|
|
188
178
|
`);
|
|
189
179
|
|
|
180
|
+
// Login with auth storage
|
|
181
|
+
writeFileSafe(path.join(demoDir, "tests/login/loginwithauthstorage.spec.ts"),
|
|
182
|
+
`import { test, expect, initAuthSession } from 'simple-playwright-framework';
|
|
183
|
+
import { providerRegistry } from '@demo-project/auth';
|
|
184
|
+
test('login with Admin user using Auth Storage', async ({ page, envConfig, td }) => {
|
|
185
|
+
await page.goto(envConfig.baseUrl);
|
|
186
|
+
await initAuthSession(page, envConfig.authStorage!, { username: td.users.admin.username, password: td.users.admin.password }, providerRegistry);
|
|
187
|
+
await expect(page).toHaveURL(/dashboard/);
|
|
188
|
+
});
|
|
189
|
+
`);
|
|
190
|
+
|
|
191
|
+
// Login with TestRail reporting
|
|
192
|
+
writeFileSafe(path.join(demoDir, "tests/login/login.testrail.spec.ts"),
|
|
193
|
+
`import { test, expect } from 'simple-playwright-framework';
|
|
194
|
+
test('Login linked to TestRail case C1234', async ({ page, envConfig, testrail }) => {
|
|
195
|
+
await page.goto(envConfig.baseUrl);
|
|
196
|
+
await page.fill('input[name="username"]', 'Admin');
|
|
197
|
+
await page.fill('input[name="password"]', 'admin123');
|
|
198
|
+
await page.click('button[type="submit"]');
|
|
199
|
+
try {
|
|
200
|
+
await expect(page).toHaveURL(/dashboard/);
|
|
201
|
+
await testrail.addResult(1234, 1, "Login passed ✅");
|
|
202
|
+
} catch (err) {
|
|
203
|
+
await testrail.addResult(1234, 5, "Login failed ❌");
|
|
204
|
+
throw err;
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
`);
|
|
208
|
+
|
|
209
|
+
// File handling test (fixed locator)
|
|
190
210
|
writeFileSafe(path.join(demoDir, "tests/filehandling/filehandling.spec.ts"),
|
|
191
211
|
`import { test, expect } from 'simple-playwright-framework';
|
|
192
212
|
|
|
193
213
|
test("upload and download demo", async ({ page, fileUtils }) => {
|
|
214
|
+
// Upload
|
|
194
215
|
await page.goto("https://the-internet.herokuapp.com/upload");
|
|
195
216
|
await fileUtils.uploadFile("#file-upload", "data/ui/sample.txt");
|
|
196
217
|
await page.click("#file-submit");
|
|
197
218
|
|
|
219
|
+
// Download
|
|
198
220
|
await page.goto("https://the-internet.herokuapp.com/download");
|
|
199
|
-
const link = page.
|
|
221
|
+
const link = page.getByRole('link', { name: 'sample.txt', exact: true });
|
|
200
222
|
await expect(link).toBeVisible();
|
|
201
223
|
|
|
202
|
-
const downloadedPath = await fileUtils.downloadFile("a[href
|
|
224
|
+
const downloadedPath = await fileUtils.downloadFile("a[href='download/sample.txt']");
|
|
203
225
|
console.log("Downloaded file path:", downloadedPath);
|
|
204
226
|
});
|
|
205
227
|
`);
|
|
206
228
|
|
|
229
|
+
// API test
|
|
207
230
|
writeFileSafe(path.join(demoDir, "tests/api/api.test.ts"),
|
|
208
231
|
`import { test, expect } from 'simple-playwright-framework';
|
|
209
232
|
test('sample API call', async ({ request, envConfig }) => {
|
|
@@ -213,7 +236,15 @@ test('sample API call', async ({ request, envConfig }) => {
|
|
|
213
236
|
});
|
|
214
237
|
`);
|
|
215
238
|
|
|
216
|
-
//
|
|
239
|
+
// Reporting example
|
|
240
|
+
writeFileSafe(path.join(demoDir, "tests/reporting/testrail.test.ts"),
|
|
241
|
+
`import { test } from 'simple-playwright-framework';
|
|
242
|
+
test('reporting example', async ({ testrail }) => {
|
|
243
|
+
await testrail.addResult(5678, 1, "Reporting fixture works ✅");
|
|
244
|
+
});
|
|
245
|
+
`);
|
|
246
|
+
|
|
247
|
+
// README
|
|
217
248
|
writeFileSafe(path.join(demoDir, "README.md"),
|
|
218
249
|
`# Demo Project
|
|
219
250
|
|
|
@@ -224,6 +255,7 @@ This is a scaffolded Playwright demo project using **simple-playwright-framework
|
|
|
224
255
|
- ✅ API test using jsonplaceholder
|
|
225
256
|
- ✅ File upload & download test with FileUtils
|
|
226
257
|
- ✅ Auth storage example
|
|
258
|
+
- ✅ TestRail reporting example
|
|
227
259
|
|
|
228
260
|
## Usage
|
|
229
261
|
- Run \`npm run init\` to scaffold the project
|
|
@@ -231,7 +263,7 @@ This is a scaffolded Playwright demo project using **simple-playwright-framework
|
|
|
231
263
|
- Run \`npm run build\` to compile TypeScript
|
|
232
264
|
`);
|
|
233
265
|
|
|
234
|
-
//
|
|
266
|
+
// Final step: install deps + build
|
|
235
267
|
try {
|
|
236
268
|
console.log("🚀 Installing dependencies and building demo-project...");
|
|
237
269
|
run("npm install", demoDir);
|
|
@@ -241,4 +273,3 @@ try {
|
|
|
241
273
|
console.error("❌ Init failed:", err.message);
|
|
242
274
|
process.exit(1);
|
|
243
275
|
}
|
|
244
|
-
|