simple-playwright-framework 0.0.11 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "simple-playwright-framework",
3
- "version": "0.0.11",
3
+ "version": "0.0.12",
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",
@@ -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
- export default defineConfig({ testDir: './tests', reporter: [['html']] });
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({
@@ -229,20 +206,22 @@ test('Login linked to TestRail case C1234', async ({ page, envConfig, testrail }
229
206
  });
230
207
  `);
231
208
 
232
- // File handling test
209
+ // File handling test (fixed locator)
233
210
  writeFileSafe(path.join(demoDir, "tests/filehandling/filehandling.spec.ts"),
234
211
  `import { test, expect } from 'simple-playwright-framework';
235
212
 
236
213
  test("upload and download demo", async ({ page, fileUtils }) => {
214
+ // Upload
237
215
  await page.goto("https://the-internet.herokuapp.com/upload");
238
216
  await fileUtils.uploadFile("#file-upload", "data/ui/sample.txt");
239
217
  await page.click("#file-submit");
240
218
 
219
+ // Download
241
220
  await page.goto("https://the-internet.herokuapp.com/download");
242
- const link = page.locator("a[href*='sample.txt']");
221
+ const link = page.getByRole('link', { name: 'sample.txt', exact: true });
243
222
  await expect(link).toBeVisible();
244
223
 
245
- const downloadedPath = await fileUtils.downloadFile("a[href*='sample.txt']");
224
+ const downloadedPath = await fileUtils.downloadFile("a[href='download/sample.txt']");
246
225
  console.log("Downloaded file path:", downloadedPath);
247
226
  });
248
227
  `);