form-tester 0.11.3 → 0.11.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/form-tester.js +84 -21
- package/package.json +1 -1
package/form-tester.js
CHANGED
|
@@ -7,7 +7,7 @@ const { spawn, execSync } = require("child_process");
|
|
|
7
7
|
const CONFIG_PATH = path.join(process.cwd(), "form-tester.config.json");
|
|
8
8
|
const OUTPUT_BASE = path.resolve(process.cwd(), "output");
|
|
9
9
|
const ISSUES_PATH = path.join(OUTPUT_BASE, "issues.jsonl");
|
|
10
|
-
const LOCAL_VERSION = "0.11.
|
|
10
|
+
const LOCAL_VERSION = "0.11.5";
|
|
11
11
|
const RECOMMENDED_PERSON = "Uromantisk Direktør";
|
|
12
12
|
|
|
13
13
|
// Recording — persisted to disk so `form-tester exec` can append across processes
|
|
@@ -167,36 +167,99 @@ async function handleDocuments(config, flags = {}) {
|
|
|
167
167
|
}
|
|
168
168
|
await sleep(2000);
|
|
169
169
|
|
|
170
|
-
// Step 2: Check if person selection is needed
|
|
170
|
+
// Step 2: Check if person selection is needed — parse snapshot for person buttons
|
|
171
171
|
const checkSnapshot = path.join(outputDir, "dokumenter_check.yml");
|
|
172
172
|
await runPlaywrightCli(["snapshot", "--filename", checkSnapshot]);
|
|
173
173
|
if (fs.existsSync(checkSnapshot)) {
|
|
174
174
|
const checkText = fs.readFileSync(checkSnapshot, "utf8");
|
|
175
175
|
if (checkText.includes("Hvem vil du bruke Helsenorge") || checkText.includes("personliste")) {
|
|
176
|
-
log("Person selection detected on Dokumenter page.
|
|
177
|
-
// Use direct click approach — the person page has simple buttons with person names
|
|
176
|
+
log("Person selection detected on Dokumenter page.");
|
|
178
177
|
const personName = config.lastPerson || config.person || RECOMMENDED_PERSON;
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
178
|
+
// Find the button ref INSIDE the person list region (not the nav header)
|
|
179
|
+
let clickRef = null;
|
|
180
|
+
const lines = checkText.split(/\r?\n/);
|
|
181
|
+
let inRegion = false;
|
|
182
|
+
for (const line of lines) {
|
|
183
|
+
if (line.includes('region "Hvem vil du bruke Helsenorge')) inRegion = true;
|
|
184
|
+
if (!inRegion) continue;
|
|
185
|
+
const btnMatch = line.match(/button "([^"]*)" \[ref=(e\d+)\]/);
|
|
186
|
+
if (btnMatch) {
|
|
187
|
+
// First try to match person name
|
|
188
|
+
if (btnMatch[1].includes(personName)) {
|
|
189
|
+
clickRef = btnMatch[2];
|
|
190
|
+
log(`Found person button: "${btnMatch[1]}" (ref=${clickRef})`);
|
|
191
|
+
break;
|
|
192
|
+
}
|
|
193
|
+
// Or take first button in region as fallback
|
|
194
|
+
if (!clickRef) {
|
|
195
|
+
clickRef = btnMatch[2];
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (clickRef && !lines.some((l) => l.includes(personName) && l.includes(clickRef))) {
|
|
200
|
+
log(`Fallback: clicking first person button in region (ref=${clickRef})`);
|
|
201
|
+
}
|
|
202
|
+
if (clickRef) {
|
|
203
|
+
await runPlaywrightCli(["click", clickRef]);
|
|
204
|
+
log("Person clicked on Dokumenter page. Waiting for navigation...");
|
|
205
|
+
await sleep(3000);
|
|
206
|
+
// Verify we left the person picker — take a new snapshot
|
|
207
|
+
const verifySnapshot = path.join(outputDir, "dokumenter_verify.yml");
|
|
208
|
+
await runPlaywrightCli(["snapshot", "--filename", verifySnapshot]);
|
|
209
|
+
if (fs.existsSync(verifySnapshot)) {
|
|
210
|
+
const verifyText = fs.readFileSync(verifySnapshot, "utf8");
|
|
211
|
+
if (verifyText.includes("Hvem vil du bruke Helsenorge")) {
|
|
212
|
+
// Still on person picker — the click might have opened the nav dropdown instead
|
|
213
|
+
// Try clicking the person button inside the full-page list (region), not the nav
|
|
214
|
+
log("Still on person picker. Looking for person in full-page list...");
|
|
215
|
+
const regionLines = verifyText.split(/\r?\n/);
|
|
216
|
+
let inFullPageRegion = false;
|
|
217
|
+
let retryRef = null;
|
|
218
|
+
for (const line of regionLines) {
|
|
219
|
+
if (line.includes('region "Hvem vil du bruke Helsenorge')) inFullPageRegion = true;
|
|
220
|
+
if (line.includes('listitem') && inFullPageRegion) {
|
|
221
|
+
const btnMatch = line.match(/button "[^"]*" \[ref=(e\d+)\]/);
|
|
222
|
+
// Also check next lines for button
|
|
223
|
+
if (btnMatch) {
|
|
224
|
+
retryRef = btnMatch[1];
|
|
225
|
+
break;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
if (inFullPageRegion) {
|
|
229
|
+
const btnMatch = line.match(/button "([^"]*)" \[ref=(e\d+)\]/);
|
|
230
|
+
if (btnMatch && btnMatch[1].includes(personName)) {
|
|
231
|
+
retryRef = btnMatch[2];
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
// If region-based search didn't find it, just click first listitem button in region
|
|
237
|
+
if (!retryRef && inFullPageRegion) {
|
|
238
|
+
let inList = false;
|
|
239
|
+
for (const line of regionLines) {
|
|
240
|
+
if (line.includes('region "Hvem vil du bruke Helsenorge')) inList = true;
|
|
241
|
+
if (inList) {
|
|
242
|
+
const btnMatch = line.match(/button "[^"]*" \[ref=(e\d+)\].*\[cursor=pointer\]/);
|
|
243
|
+
if (btnMatch) {
|
|
244
|
+
retryRef = btnMatch[1];
|
|
245
|
+
break;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
if (retryRef) {
|
|
251
|
+
log(`Retrying with ref=${retryRef}...`);
|
|
252
|
+
await runPlaywrightCli(["click", retryRef]);
|
|
253
|
+
await sleep(3000);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
try { fs.unlinkSync(verifySnapshot); } catch (e) {}
|
|
185
257
|
}
|
|
186
|
-
// Fallback: click first person button (usually has class personliste__person)
|
|
187
|
-
const first = document.querySelector('button[class*="personliste"], button[class*="person"]');
|
|
188
|
-
if (first) { first.click(); return "clicked-first: " + (first.textContent || "").trim().substring(0, 60); }
|
|
189
|
-
return "not-found";
|
|
190
|
-
}`;
|
|
191
|
-
const personResult = await runPlaywrightCliCapture(["eval", clickScript]);
|
|
192
|
-
const personOutput = personResult.stdout.replace(/^### Result\s*/i, "").trim();
|
|
193
|
-
if (personOutput.startsWith("clicked")) {
|
|
194
|
-
log(`Person selected: ${personOutput}`);
|
|
195
258
|
} else {
|
|
196
|
-
log("Could not
|
|
259
|
+
log("Could not find person button in snapshot. Trying select-person...");
|
|
197
260
|
await handleSelectPerson(config, personName);
|
|
261
|
+
await sleep(3000);
|
|
198
262
|
}
|
|
199
|
-
await sleep(2000);
|
|
200
263
|
}
|
|
201
264
|
try { fs.unlinkSync(checkSnapshot); } catch (e) {}
|
|
202
265
|
}
|
package/package.json
CHANGED