diff --git a/source/Popup/index.tsx b/source/Popup/index.tsx index 68b7129..9b3e3bc 100644 --- a/source/Popup/index.tsx +++ b/source/Popup/index.tsx @@ -181,7 +181,13 @@ function downloadZestScript(zestScriptJSON: string, title: string): void { closePopup(); } -function handleSaveScript(): void { +async function handleSaveScript(): Promise { + const storageItems = await Browser.storage.sync.get({ + zaprecordingactive: false, + }); + if (storageItems.zaprecordingactive) { + await Browser.runtime.sendMessage({type: STOP_RECORDING}); + } Browser.runtime.sendMessage({type: SAVE_ZEST_SCRIPT}).then((items) => { downloadZestScript(items.script, items.title); }); diff --git a/test/ContentScript/integrationTests.test.ts b/test/ContentScript/integrationTests.test.ts index de72369..1fb607f 100644 --- a/test/ContentScript/integrationTests.test.ts +++ b/test/ContentScript/integrationTests.test.ts @@ -193,6 +193,28 @@ function integrationTests( expect(JSON.stringify(Array.from(actualData))).toBe(expectedData); }); + test('Should send window handle close script when directly pressed save script', async () => { + server = getFakeZapServer(actualData, _JSONPORT); + const context = await driver.getContext(_JSONPORT, true); + await driver.setEnable(false); + const page = await context.newPage(); + await page.goto(await driver.getOptionsURL()); + await page.goto( + `http://localhost:${_HTTPPORT}/webpages/interactions.html` + ); + await page.fill('#input-1', 'testinput'); + await page.click('#click'); + await page.goto(await driver.getPopupURL()); + await page.click('#save-script'); + await page.waitForLoadState('networkidle'); + await page.waitForTimeout(1000); + await page.close(); + // Then + const expectedData = + '["{\\"action\\":{\\"action\\":\\"reportZestScript\\"},\\"body\\":{\\"scriptJson\\":\\"{\\"windowHandle\\":\\"windowHandle1\\",\\"type\\":\\"id\\",\\"element\\":\\"input-1\\",\\"index\\":1,\\"enabled\\":true,\\"elementType\\":\\"ZestClientElementClear\\"}\\",\\"apikey\\":\\"not set\\"}}","{\\"action\\":{\\"action\\":\\"reportZestScript\\"},\\"body\\":{\\"scriptJson\\":\\"{\\"value\\":\\"testinput\\",\\"windowHandle\\":\\"windowHandle1\\",\\"type\\":\\"id\\",\\"element\\":\\"input-1\\",\\"index\\":2,\\"enabled\\":true,\\"elementType\\":\\"ZestClientElementSendKeys\\"}\\",\\"apikey\\":\\"not set\\"}}","{\\"action\\":{\\"action\\":\\"reportZestScript\\"},\\"body\\":{\\"scriptJson\\":\\"{\\"windowHandle\\":\\"windowHandle1\\",\\"type\\":\\"id\\",\\"element\\":\\"click\\",\\"index\\":3,\\"enabled\\":true,\\"elementType\\":\\"ZestClientElementClick\\"}\\",\\"apikey\\":\\"not set\\"}}","{\\"action\\":{\\"action\\":\\"reportZestScript\\"},\\"body\\":{\\"scriptJson\\":\\"{\\"windowHandle\\":\\"windowHandle1\\",\\"index\\":4,\\"sleepInSeconds\\":0,\\"enabled\\":true,\\"elementType\\":\\"ZestClientWindowClose\\"}\\",\\"apikey\\":\\"not set\\"}}"]'; + expect(JSON.stringify(Array.from(actualData))).toBe(expectedData); + }); + test('Should configure downloaded script name', async () => { // Given server = getFakeZapServer(actualData, _JSONPORT);