simple-playwright-framework 0.0.11 → 0.0.13
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 +3 -3
- package/scripts/init-demo-project.js +16 -36
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "simple-playwright-framework",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.13",
|
|
4
4
|
"description": "A modular Playwright framework with fixtures, loaders, and demo scaffolding.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -37,10 +37,10 @@
|
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@playwright/test": "^1.58.2",
|
|
39
39
|
"@types/node": "^25.2.3",
|
|
40
|
+
"node-fetch": "^2.7.0",
|
|
40
41
|
"rimraf": "^6.1.2",
|
|
41
42
|
"ts-node": "^10.9.2",
|
|
42
43
|
"tsconfig-paths": "^4.2.0",
|
|
43
|
-
"typescript": "^5.9.3"
|
|
44
|
-
"node-fetch": "^2.6.7"
|
|
44
|
+
"typescript": "^5.9.3"
|
|
45
45
|
}
|
|
46
46
|
}
|
|
@@ -34,7 +34,8 @@ writeFileSafe(path.join(demoDir, "package.json"),
|
|
|
34
34
|
"@playwright/test": "^1.58.2",
|
|
35
35
|
"simple-playwright-framework": "latest",
|
|
36
36
|
"@types/node": "^20.0.0",
|
|
37
|
-
"rimraf": "^5.0.0"
|
|
37
|
+
"rimraf": "^5.0.0",
|
|
38
|
+
"node-fetch": "^2.6.7"
|
|
38
39
|
}
|
|
39
40
|
}, null, 2)
|
|
40
41
|
);
|
|
@@ -62,7 +63,15 @@ writeFileSafe(path.join(demoDir, "tsconfig.json"),
|
|
|
62
63
|
// -------------------- playwright.config.ts --------------------
|
|
63
64
|
writeFileSafe(path.join(demoDir, "playwright.config.ts"),
|
|
64
65
|
`import { defineConfig } from '@playwright/test';
|
|
65
|
-
|
|
66
|
+
|
|
67
|
+
export default defineConfig({
|
|
68
|
+
testDir: './tests',
|
|
69
|
+
reporter: [['html']],
|
|
70
|
+
use: {
|
|
71
|
+
// Default environment for scenarioLoader
|
|
72
|
+
env: process.env.TEST_ENV || "prod",
|
|
73
|
+
},
|
|
74
|
+
});
|
|
66
75
|
`);
|
|
67
76
|
|
|
68
77
|
// -------------------- environments.json --------------------
|
|
@@ -98,37 +107,6 @@ export class OrangeHRMLogin implements AuthProvider {
|
|
|
98
107
|
}
|
|
99
108
|
`);
|
|
100
109
|
|
|
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
110
|
// -------------------- Data --------------------
|
|
133
111
|
writeFileSafe(path.join(demoDir, "data/login/login.json"),
|
|
134
112
|
JSON.stringify({
|
|
@@ -229,20 +207,22 @@ test('Login linked to TestRail case C1234', async ({ page, envConfig, testrail }
|
|
|
229
207
|
});
|
|
230
208
|
`);
|
|
231
209
|
|
|
232
|
-
// File handling test
|
|
210
|
+
// File handling test (fixed locator)
|
|
233
211
|
writeFileSafe(path.join(demoDir, "tests/filehandling/filehandling.spec.ts"),
|
|
234
212
|
`import { test, expect } from 'simple-playwright-framework';
|
|
235
213
|
|
|
236
214
|
test("upload and download demo", async ({ page, fileUtils }) => {
|
|
215
|
+
// Upload
|
|
237
216
|
await page.goto("https://the-internet.herokuapp.com/upload");
|
|
238
217
|
await fileUtils.uploadFile("#file-upload", "data/ui/sample.txt");
|
|
239
218
|
await page.click("#file-submit");
|
|
240
219
|
|
|
220
|
+
// Download
|
|
241
221
|
await page.goto("https://the-internet.herokuapp.com/download");
|
|
242
|
-
const link = page.
|
|
222
|
+
const link = page.getByRole('link', { name: 'sample.txt', exact: true });
|
|
243
223
|
await expect(link).toBeVisible();
|
|
244
224
|
|
|
245
|
-
const downloadedPath = await fileUtils.downloadFile("a[href
|
|
225
|
+
const downloadedPath = await fileUtils.downloadFile("a[href='download/sample.txt']");
|
|
246
226
|
console.log("Downloaded file path:", downloadedPath);
|
|
247
227
|
});
|
|
248
228
|
`);
|