Skip to content

Commit

Permalink
Merge pull request #68 from aryangupta701/fix-issue
Browse files Browse the repository at this point in the history
record window handle close when directly pressed save script button
  • Loading branch information
psiinon authored Aug 29, 2023
2 parents 6711ac4 + 0fea90c commit 9921781
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
8 changes: 7 additions & 1 deletion source/Popup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,13 @@ function downloadZestScript(zestScriptJSON: string, title: string): void {
closePopup();
}

function handleSaveScript(): void {
async function handleSaveScript(): Promise<void> {
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);
});
Expand Down
22 changes: 22 additions & 0 deletions test/ContentScript/integrationTests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 9921781

Please sign in to comment.