form-tester 0.8.2 → 0.8.3

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.
@@ -78,27 +78,33 @@ Dokumenter verification (only when modal confirms storage):
78
78
  1. Navigate to `/dokumenter?pnr={PNR}` and select the same person used during form fill.
79
79
  2. The document list loads sorted newest first. The first entry should match the form title.
80
80
  3. Click "Se detaljer" on the first document, then click "Åpne dokumentet".
81
- 4. After clicking "Åpne dokumentet", the document may open in a dialog, a new tab, or inline. FIRST determine the format before capturing:
82
-
83
- Step A Detect format:
84
- Run `form-tester exec snapshot` and examine the result.
85
- - If you see an iframe/embed/object with a src containing `.pdf`, `blob:`, or a PDF viewer it's a PDF.
86
- - If you see rendered HTML content (headings, paragraphs, form data) → it's HTML.
87
- - If `--full-page` screenshot times out it's almost certainly a PDF viewer. Do NOT retry the screenshot. Switch to PDF download.
88
-
89
- Step BPDF documents (viewer in dialog/modal/iframe/new tab):
90
- Do NOT screenshot PDFs it will timeout or produce garbage. Download the file:
91
- 1. Extract PDF URL from the iframe/embed/object:
92
- `form-tester exec eval "document.querySelector('iframe')?.src || document.querySelector('embed')?.src || document.querySelector('object')?.data"`
93
- 2. If the result is a URL, download it with run-code:
94
- `form-tester exec run-code "async page => { const url = await page.evaluate(() => document.querySelector('iframe')?.src || document.querySelector('embed')?.src || document.querySelector('object')?.data); if (url) { const resp = await page.request.get(url); require('fs').writeFileSync('$OUTPUT_DIR/document.pdf', await resp.body()); } }"`
95
- 3. Or if the PDF viewer has a download button, click it.
96
- 4. Record in test_results.txt: document type PDF, downloaded to document.pdf.
97
-
98
- Step C HTML documents:
99
- Take a FULL-PAGE screenshot (`form-tester exec screenshot --filename "$OUTPUT_DIR/document_screenshot.png" --full-page`).
81
+ 4. After clicking "Åpne dokumentet", determine the document format:
82
+
83
+ How to detect format:
84
+ - Take a snapshot: `form-tester exec snapshot`
85
+ - If snapshot shows a link with href containing `/pdf/` or `blob:` → PDF
86
+ - If `--full-page` screenshot times out PDF (do NOT retry, switch to download)
87
+ - If snapshot shows rendered HTML content (headings, paragraphs, form data) HTML
88
+
89
+ PDF documentsDOWNLOAD, do NOT screenshot:
90
+ IMPORTANT: `run-code` does NOT have access to `require` or `fs`. Do NOT use `require('fs')`. Use Playwright's download API instead.
91
+
92
+ Find the PDF download link in the snapshot (look for `a[href*="/pdf/"]` or "Last ned" link), then download using the Playwright download event:
93
+ ```
94
+ form-tester exec run-code "async page => { const link = page.locator('a[href*=\"/pdf/\"]').first(); const [download] = await Promise.all([ page.waitForEvent('download'), link.click() ]); await download.saveAs('$OUTPUT_DIR/document.pdf'); }"
95
+ ```
96
+ If there is no direct PDF link but a "Last ned" button:
97
+ ```
98
+ form-tester exec run-code "async page => { const [download] = await Promise.all([ page.waitForEvent('download'), page.getByRole('link', { name: 'Last ned' }).click() ]); await download.saveAs('$OUTPUT_DIR/document.pdf'); }"
99
+ ```
100
+ Verify the download: check that document.pdf exists in the output folder.
101
+
102
+ HTML documents — SCREENSHOT full page:
103
+ ```
104
+ form-tester exec screenshot --filename "$OUTPUT_DIR/document_screenshot.png" --full-page
105
+ ```
100
106
  Also save raw HTML: `form-tester exec eval "document.documentElement.outerHTML"` → save to document.html.
101
107
 
102
- Step D — XML/other: Note type in test_results.txt, skip capture.
108
+ XML/other: Note type in test_results.txt, skip capture.
103
109
 
104
110
  5. Include the document verification results in test_results.txt (document title, whether it matched the form h1, document type: HTML/PDF/XML).
@@ -87,13 +87,18 @@ After submission, read the modal text:
87
87
  - If it mentions Dokumenter storage -> navigate to `/dokumenter?pnr={PNR}`, verify the document appears.
88
88
  - If it does NOT mention Dokumenter -> skip verification, note in test_results.txt.
89
89
 
90
- Document capture — FIRST detect the format by running `form-tester exec snapshot`:
90
+ Document capture — detect format via `form-tester exec snapshot`:
91
91
 
92
- **PDF documents** (iframe/embed with .pdf or blob: URL, or screenshot times out): Do NOT screenshot PDFs. Download instead:
93
- 1. Extract URL: `form-tester exec eval "document.querySelector('iframe')?.src || document.querySelector('embed')?.src || document.querySelector('object')?.data"`
94
- 2. Download: `form-tester exec run-code "async page => { const url = await page.evaluate(() => document.querySelector('iframe')?.src || document.querySelector('embed')?.src || document.querySelector('object')?.data); if (url) { const resp = await page.request.get(url); require('fs').writeFileSync('OUTPUT_DIR/document.pdf', await resp.body()); } }"`
95
- 3. Or click the download button in the PDF viewer if available.
96
- 4. If `--full-page` screenshot times out, it's a PDF switch to download, don't retry screenshot.
92
+ **PDF documents** (link with href containing `/pdf/`, or screenshot times out):
93
+ Do NOT screenshot PDFs. Do NOT use `require('fs')` in run-code (it doesn't exist there).
94
+ Download using Playwright's download event:
95
+ ```
96
+ form-tester exec run-code "async page => { const link = page.locator('a[href*=\"/pdf/\"]').first(); const [download] = await Promise.all([ page.waitForEvent('download'), link.click() ]); await download.saveAs('$OUTPUT_DIR/document.pdf'); }"
97
+ ```
98
+ Or if there's a "Last ned" button:
99
+ ```
100
+ form-tester exec run-code "async page => { const [download] = await Promise.all([ page.waitForEvent('download'), page.getByRole('link', { name: 'Last ned' }).click() ]); await download.saveAs('$OUTPUT_DIR/document.pdf'); }"
101
+ ```
97
102
 
98
103
  **HTML documents**: `form-tester exec screenshot --filename "..." --full-page`. Also save raw HTML.
99
104
 
package/form-tester.js CHANGED
@@ -6,7 +6,7 @@ const { spawn, execSync } = require("child_process");
6
6
 
7
7
  const CONFIG_PATH = path.join(process.cwd(), "form-tester.config.json");
8
8
  const OUTPUT_BASE = path.resolve(process.cwd(), "output");
9
- const LOCAL_VERSION = "0.8.2";
9
+ const LOCAL_VERSION = "0.8.3";
10
10
  const RECOMMENDED_PERSON = "Uromantisk Direktør";
11
11
 
12
12
  // Recording — persisted to disk so `form-tester exec` can append across processes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "form-tester",
3
- "version": "0.8.2",
3
+ "version": "0.8.3",
4
4
  "description": "AI-powered form testing skill for /skjemautfyller forms using Playwright CLI. Works with Claude Code and GitHub Copilot.",
5
5
  "main": "form-tester.js",
6
6
  "bin": {