Files
sam-hotfix/e2e/runner/eval_chunk_2.js

1 line
12 KiB
JavaScript
Raw Normal View History

window.__C += 'lector(\n `input[placeholder*="${label}"], textarea[placeholder*="${label}"]`\n );\n }\n\n // Fallback: name search\n if (!el) {\n el = document.querySelector(`input[name*="${label}"], textarea[name*="${label}"]`);\n }\n\n if (!el) {\n results.push({ field: label, status: \'skip\', detail: \'not found\' });\n continue;\n }\n\n if (field.type === \'select\' || el.tagName === \'SELECT\') {\n // Select handling\n const options = Array.from(el.querySelectorAll(\'option\'));\n const opt = options.find((o) => o.textContent?.includes(value));\n if (opt) {\n el.value = opt.value;\n el.dispatchEvent(new Event(\'change\', { bubbles: true }));\n }\n } else if (field.type === \'date\') {\n setInputValue(el, value);\n } else {\n clearInput(el);\n setInputValue(el, value);\n }\n results.push({ field: label, status: \'ok\' });\n await sleep(150);\n }\n const filled = results.filter((r) => r.status === \'ok\').length;\n const skipped = results.filter((r) => r.status === \'skip\').length;\n if (filled === 0) return fail(`fill_form: no fields filled (${skipped} not found)`);\n return pass(`fill_form: ${filled}/${fields.length} filled`);\n },\n\n async fill_and_wait(action, ctx) {\n const result = await ActionHandlers.fill(action, ctx);\n await sleep(1000);\n return result;\n },\n\n async clear(action, ctx) {\n const el = findEl(action.target, { selectors: ctx.selectors });\n if (!el) return fail(`Input not found: ${action.target}`);\n clearInput(el);\n await sleep(200);\n return pass(`Cleared: ${action.target}`);\n },\n\n async edit_field(action, ctx) {\n return ActionHandlers.fill(action, ctx);\n },\n\n // ── Select group ──\n async select(action, ctx) {\n const el = findEl(action.target, { selectors: ctx.selectors });\n if (!el) return fail(`Select not found: ${action.target}`);\n\n if (el.tagName === \'SELECT\') {\n const options = Array.from(el.querySelectorAll(\'option\'));\n const opt = options.find((o) => o.textContent?.includes(action.value));\n if (opt) {\n el.value = opt.value;\n el.dispatchEvent(new Event(\'change\', { bubbles: true }));\n return pass(`Selected: ${action.value}`);\n }\n return fail(`Option "${action.value}" not found`);\n }\n // Custom dropdown\n return ActionHandlers.select_dropdown(action, ctx);\n },\n\n async select_dropdown(action, ctx) {\n // Click trigger to open dropdown\n const trigger = findEl(action.target, { selectors: ctx.selectors });\n if (!trigger) return fail(`Dropdown trigger not found: ${action.target}`);\n triggerClick(trigger);\n await sleep(500);\n\n // Find option in dropdown list\n const optionSelectors = [\n \'[role="option"]\',\n \'[role="listbox"] li\',\n \'[class*="option"]\',\n \'[class*="menu-item"]\',\n \'[class*="dropdown-item"]\',\n \'li\',\n ];\n for (const sel of optionSelectors) {\n const options = document.querySelectorAll(sel);\n const opt = Array.from(options).find((o) => o.textContent?.trim().includes(action.value));\n if (opt) {\n triggerClick(opt);\n await sleep(300);\n return pass(`Selected dropdown: ${action.value}`);\n }\n }\n return fail(`Dropdown option "${action.value}" not found`);\n },\n\n async select_filter(action, ctx) {\n return ActionHandlers.select_dropdown(action, ctx);\n },\n\n // ── Check group ──\n async check(action, ctx) {\n const el = findEl(action.target, { selectors: ctx.selectors });\n if (!el) return fail(`Checkbox not found: ${action.target}`);\n if (!el.checked) {\n triggerClick(el);\n await sleep(200);\