From afc4627353ccdb34f029b92834d3c3fd28f68734 Mon Sep 17 00:00:00 2001 From: Andrii Arsenin Date: Wed, 8 Apr 2026 21:09:36 +0300 Subject: [PATCH] fix(auth): skip sign widget open if already visible MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - check for file input visibility before clicking the sign button - prevents double-open when Готово triggers the widget automatically - remove stale scenario-25-export.json (superseded by notes export) --- scenario-25-export.json | 40 ---------------------------------------- src/auth/auth.service.ts | 20 +++++++++++++------- 2 files changed, 13 insertions(+), 47 deletions(-) delete mode 100644 scenario-25-export.json diff --git a/scenario-25-export.json b/scenario-25-export.json deleted file mode 100644 index 618e61e..0000000 --- a/scenario-25-export.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "name": "Diia STG — Create certificate application (987825)", - "steps": [ - { - "order": 0, - "type": "login", - "sessionName": "diia-stg-session", - "execCode": "{\"keyId\": \"3273334361\", \"environmentName\": \"liquio-diia-stg\"}", - "validateCode": null - }, - { - "order": 1, - "type": "exec", - "sessionName": "diia-stg-session", - "execCode": "// Navigate to the tasks/services list for this user\nawait page.goto(\"https://cabinet-liquio-diia-stg.kitsoft.ua/tasks\", { waitUntil: \"networkidle\" });\nhelpers.log(\"URL: \" + page.url());\nhelpers.log(\"title: \" + await page.title());\n\nconst headings = await page.locator(\"h1, h2, h3\").allTextContents();\nhelpers.log(\"headings: \" + JSON.stringify(headings));\n\n// Find any links that look like task/service links\nconst links = await page.locator(\"a[href*=task], a[href*=service], a[href*=create]\").all();\nconst linkData = [];\nfor (const a of links.slice(0, 20)) {\n linkData.push({ href: await a.getAttribute(\"href\"), text: (await a.textContent()).trim().slice(0, 80) });\n}\nhelpers.log(\"task links: \" + JSON.stringify(linkData));\n\nconst bodyText = await page.locator(\"body\").innerText();\nhelpers.log(\"body (first 800): \" + bodyText.slice(0, 800));\n\nreturn page.url();\n", - "validateCode": null - }, - { - "order": 2, - "type": "exec", - "sessionName": "diia-stg-session", - "execCode": "helpers.log(\"url=\" + page.url());\nconst btns = await page.locator(\"button\").all();\nconst labels = [];\nfor (const b of btns) { const t = (await b.textContent()) || \"\"; const vis = await b.isVisible(); if (vis) labels.push(t.trim()); }\nhelpers.log(\"visible buttons: \" + JSON.stringify(labels));\nreturn labels;", - "validateCode": null - }, - { - "order": 3, - "type": "sign", - "sessionName": "diia-stg-session", - "execCode": "{\"keyId\": \"3273334361\"}", - "validateCode": null - }, - { - "order": 4, - "type": "exec", - "sessionName": "diia-stg-session", - "execCode": "return page.url();", - "validateCode": "\nconst url = page.url();\nconst successEl = await page.locator('.success, [data-test=\"success\"], .task-success, .done-message').count();\nconst successText = /успішно|success|заяву подано|виконано/i.test(await page.locator('body').innerText());\nreturn {\n success: successEl > 0 || successText,\n description: `Final URL: ${url}`,\n};\n" - } - ] -} diff --git a/src/auth/auth.service.ts b/src/auth/auth.service.ts index 1c96122..66cea3b 100644 --- a/src/auth/auth.service.ts +++ b/src/auth/auth.service.ts @@ -219,13 +219,19 @@ export class AuthService { this.logger.log(`Signing with key ${keyId} on page: ${page.url()}`); - // Open the EDS sign widget - await page - .locator("button") - .filter({ hasText: /підпис|sign/i }) - .first() - .click(); - await page.waitForTimeout(500); + // Open the EDS sign widget (skip if it's already open) + const isSignDialogOpen = await page + .locator('input[accept=".dat,.pfx,.pk8,.zs2,.jks"][type="file"]') + .isVisible() + .catch(() => false); + if (!isSignDialogOpen) { + await page + .locator("button") + .filter({ hasText: /підпис|sign/i }) + .first() + .click(); + await page.waitForTimeout(500); + } // Select the file key tab inside the widget await page