Skip to content

Commit 9c2beb1

Browse files
authored
Merge pull request #111 from psiinon/tweak/remove-clear
Remove Zest clear statements
2 parents 04b632c + 1bf436d commit 9c2beb1

File tree

4 files changed

+139
-24
lines changed

4 files changed

+139
-24
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ All notable changes to this add-on will be documented in this file.
33

44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
55

6+
## Unreleased
7+
8+
### Removed
9+
- Clear statements before inputting text, they were not needed and could cause problems.
10+
611
## 0.0.11 - 2025-01-17
712

813
### Added

source/Background/index.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ import {
3131
SESSION_STORAGE,
3232
SET_SAVE_SCRIPT_ENABLE,
3333
STOP_RECORDING,
34-
ZEST_CLIENT_ELEMENT_CLEAR,
35-
ZEST_CLIENT_ELEMENT_SEND_KEYS,
3634
ZEST_SCRIPT,
3735
} from '../utils/constants';
3836

@@ -223,14 +221,6 @@ async function handleMessage(
223221
}
224222

225223
case ZEST_SCRIPT: {
226-
const stmt = JSON.parse(request.data);
227-
if (stmt.elementType === ZEST_CLIENT_ELEMENT_SEND_KEYS) {
228-
console.log(stmt);
229-
stmt.elementType = ZEST_CLIENT_ELEMENT_CLEAR;
230-
delete stmt.value;
231-
const cleardata = zestScript.addStatement(JSON.stringify(stmt));
232-
sendZestScriptToZAP(cleardata, zapkey, zapurl);
233-
}
234224
const data = zestScript.addStatement(request.data);
235225
sendZestScriptToZAP(data, zapkey, zapurl);
236226
break;

test/ContentScript/integrationTests.test.ts

Lines changed: 126 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,124 @@ function integrationTests(
123123
await page.close();
124124
// Then
125125
const expectedData =
126-
'["{\\"action\\":{\\"action\\":\\"reportZestStatement\\"},\\"body\\":{\\"statementJson\\":\\"{\\"windowHandle\\":\\"windowHandle1\\",\\"type\\":\\"id\\",\\"element\\":\\"input-1\\",\\"index\\":1,\\"enabled\\":true,\\"elementType\\":\\"ZestClientElementClear\\"}\\",\\"apikey\\":\\"not set\\"}}",' +
127-
'"{\\"action\\":{\\"action\\":\\"reportZestStatement\\"},\\"body\\":{\\"statementJson\\":\\"{\\"value\\":\\"testinput\\",\\"windowHandle\\":\\"windowHandle1\\",\\"type\\":\\"id\\",\\"element\\":\\"input-1\\",\\"index\\":2,\\"enabled\\":true,\\"elementType\\":\\"ZestClientElementSendKeys\\"}\\",\\"apikey\\":\\"not set\\"}}",' +
128-
'"{\\"action\\":{\\"action\\":\\"reportZestStatement\\"},\\"body\\":{\\"statementJson\\":\\"{\\"windowHandle\\":\\"windowHandle1\\",\\"type\\":\\"id\\",\\"element\\":\\"click\\",\\"index\\":3,\\"enabled\\":true,\\"elementType\\":\\"ZestClientElementClick\\"}\\",\\"apikey\\":\\"not set\\"}}"]';
126+
'["{\\"action\\":{\\"action\\":\\"reportZestStatement\\"},\\"body\\":{\\"statementJson\\":\\"{\\"value\\":\\"testinput\\",\\"windowHandle\\":\\"windowHandle1\\",\\"type\\":\\"id\\",\\"element\\":\\"input-1\\",\\"index\\":1,\\"enabled\\":true,\\"elementType\\":\\"ZestClientElementSendKeys\\"}\\",\\"apikey\\":\\"not set\\"}}",' +
127+
'"{\\"action\\":{\\"action\\":\\"reportZestStatement\\"},\\"body\\":{\\"statementJson\\":\\"{\\"windowHandle\\":\\"windowHandle1\\",\\"type\\":\\"id\\",\\"element\\":\\"click\\",\\"index\\":2,\\"enabled\\":true,\\"elementType\\":\\"ZestClientElementClick\\"}\\",\\"apikey\\":\\"not set\\"}}"]';
128+
expect(JSON.stringify(Array.from(actualData))).toBe(expectedData);
129+
});
130+
131+
test('Should record overwrite existing input text', async () => {
132+
// Given / When
133+
server = getFakeZapServer(actualData, _JSONPORT);
134+
const context = await driver.getContext(_JSONPORT, true);
135+
await driver.setEnable(false);
136+
const page = await context.newPage();
137+
await page.goto(
138+
`http://localhost:${_HTTPPORT}/webpages/interactions.html`
139+
);
140+
await page;
141+
await page.fill('#input-3-filled', 'testinput');
142+
await page.click('#click');
143+
await page.waitForLoadState('networkidle');
144+
await page.waitForTimeout(TIMEOUT);
145+
await page.close();
146+
// Then
147+
const expectedData =
148+
'["{\\"action\\":{\\"action\\":\\"reportZestStatement\\"},\\"body\\":{\\"statementJson\\":\\"{\\"value\\":\\"testinput\\",\\"windowHandle\\":\\"windowHandle1\\",\\"type\\":\\"id\\",\\"element\\":\\"input-3-filled\\",\\"index\\":1,\\"enabled\\":true,\\"elementType\\":\\"ZestClientElementSendKeys\\"}\\",\\"apikey\\":\\"not set\\"}}",' +
149+
'"{\\"action\\":{\\"action\\":\\"reportZestStatement\\"},\\"body\\":{\\"statementJson\\":\\"{\\"windowHandle\\":\\"windowHandle1\\",\\"type\\":\\"id\\",\\"element\\":\\"click\\",\\"index\\":2,\\"enabled\\":true,\\"elementType\\":\\"ZestClientElementClick\\"}\\",\\"apikey\\":\\"not set\\"}}"]';
150+
expect(JSON.stringify(Array.from(actualData))).toBe(expectedData);
151+
});
152+
153+
test('Should record inserting before existing input text', async () => {
154+
// Given / When
155+
server = getFakeZapServer(actualData, _JSONPORT);
156+
const context = await driver.getContext(_JSONPORT, true);
157+
await driver.setEnable(false);
158+
const page = await context.newPage();
159+
await page.goto(
160+
`http://localhost:${_HTTPPORT}/webpages/interactions.html`
161+
);
162+
await page;
163+
const inputElement = page.locator('#input-3-filled');
164+
await inputElement.focus();
165+
// Playwright always appends to the start of a field, apparently due to browser inconsistencies
166+
await inputElement.type('testinput');
167+
await page.click('#click');
168+
await page.waitForLoadState('networkidle');
169+
await page.waitForTimeout(TIMEOUT);
170+
await page.close();
171+
// Then
172+
const expectedData =
173+
'["{\\"action\\":{\\"action\\":\\"reportZestStatement\\"},\\"body\\":{\\"statementJson\\":\\"{\\"value\\":\\"testinputExisting text\\",\\"windowHandle\\":\\"windowHandle1\\",\\"type\\":\\"id\\",\\"element\\":\\"input-3-filled\\",\\"index\\":1,\\"enabled\\":true,\\"elementType\\":\\"ZestClientElementSendKeys\\"}\\",\\"apikey\\":\\"not set\\"}}",' +
174+
'"{\\"action\\":{\\"action\\":\\"reportZestStatement\\"},\\"body\\":{\\"statementJson\\":\\"{\\"windowHandle\\":\\"windowHandle1\\",\\"type\\":\\"id\\",\\"element\\":\\"click\\",\\"index\\":2,\\"enabled\\":true,\\"elementType\\":\\"ZestClientElementClick\\"}\\",\\"apikey\\":\\"not set\\"}}"]';
175+
expect(JSON.stringify(Array.from(actualData))).toBe(expectedData);
176+
});
177+
178+
test('Should record overwrite existing input textarea', async () => {
179+
// Given / When
180+
server = getFakeZapServer(actualData, _JSONPORT);
181+
const context = await driver.getContext(_JSONPORT, true);
182+
await driver.setEnable(false);
183+
const page = await context.newPage();
184+
await page.goto(
185+
`http://localhost:${_HTTPPORT}/webpages/interactions.html`
186+
);
187+
await page;
188+
await page.fill('#textarea-1', 'testinput');
189+
await page.click('#click');
190+
await page.waitForLoadState('networkidle');
191+
await page.waitForTimeout(TIMEOUT);
192+
await page.close();
193+
// Then
194+
const expectedData =
195+
'["{\\"action\\":{\\"action\\":\\"reportZestStatement\\"},\\"body\\":{\\"statementJson\\":\\"{\\"value\\":\\"testinput\\",\\"windowHandle\\":\\"windowHandle1\\",\\"type\\":\\"id\\",\\"element\\":\\"textarea-1\\",\\"index\\":1,\\"enabled\\":true,\\"elementType\\":\\"ZestClientElementSendKeys\\"}\\",\\"apikey\\":\\"not set\\"}}",' +
196+
'"{\\"action\\":{\\"action\\":\\"reportZestStatement\\"},\\"body\\":{\\"statementJson\\":\\"{\\"windowHandle\\":\\"windowHandle1\\",\\"type\\":\\"id\\",\\"element\\":\\"click\\",\\"index\\":2,\\"enabled\\":true,\\"elementType\\":\\"ZestClientElementClick\\"}\\",\\"apikey\\":\\"not set\\"}}"]';
197+
expect(JSON.stringify(Array.from(actualData))).toBe(expectedData);
198+
});
199+
200+
test('Should record inserting before existing input textarea', async () => {
201+
// Given / When
202+
server = getFakeZapServer(actualData, _JSONPORT);
203+
const context = await driver.getContext(_JSONPORT, true);
204+
await driver.setEnable(false);
205+
const page = await context.newPage();
206+
await page.goto(
207+
`http://localhost:${_HTTPPORT}/webpages/interactions.html`
208+
);
209+
await page;
210+
const inputElement = page.locator('#textarea-1');
211+
await inputElement.focus();
212+
// Playwright always appends to the start of a field, apparently due to browser inconsistencies
213+
await inputElement.type('testinput');
214+
await page.click('#click');
215+
await page.waitForLoadState('networkidle');
216+
await page.waitForTimeout(TIMEOUT);
217+
await page.close();
218+
// Then
219+
const expectedData =
220+
'["{\\"action\\":{\\"action\\":\\"reportZestStatement\\"},\\"body\\":{\\"statementJson\\":\\"{\\"value\\":\\"testinputExisting text\\",\\"windowHandle\\":\\"windowHandle1\\",\\"type\\":\\"id\\",\\"element\\":\\"textarea-1\\",\\"index\\":1,\\"enabled\\":true,\\"elementType\\":\\"ZestClientElementSendKeys\\"}\\",\\"apikey\\":\\"not set\\"}}",' +
221+
'"{\\"action\\":{\\"action\\":\\"reportZestStatement\\"},\\"body\\":{\\"statementJson\\":\\"{\\"windowHandle\\":\\"windowHandle1\\",\\"type\\":\\"id\\",\\"element\\":\\"click\\",\\"index\\":2,\\"enabled\\":true,\\"elementType\\":\\"ZestClientElementClick\\"}\\",\\"apikey\\":\\"not set\\"}}"]';
222+
expect(JSON.stringify(Array.from(actualData))).toBe(expectedData);
223+
});
224+
225+
test('Should record option select', async () => {
226+
// Given / When
227+
server = getFakeZapServer(actualData, _JSONPORT);
228+
const context = await driver.getContext(_JSONPORT, true);
229+
await driver.setEnable(false);
230+
const page = await context.newPage();
231+
await page.goto(
232+
`http://localhost:${_HTTPPORT}/webpages/interactions.html`
233+
);
234+
await page;
235+
await page.locator("//select[@id='cars']").selectOption('audi');
236+
await page.click('#click');
237+
await page.waitForLoadState('networkidle');
238+
await page.waitForTimeout(TIMEOUT);
239+
await page.close();
240+
// Then
241+
const expectedData =
242+
'["{\\"action\\":{\\"action\\":\\"reportZestStatement\\"},\\"body\\":{\\"statementJson\\":\\"{\\"value\\":\\"audi\\",\\"windowHandle\\":\\"windowHandle1\\",\\"type\\":\\"id\\",\\"element\\":\\"cars\\",\\"index\\":1,\\"enabled\\":true,\\"elementType\\":\\"ZestClientElementSendKeys\\"}\\",\\"apikey\\":\\"not set\\"}}",' +
243+
'"{\\"action\\":{\\"action\\":\\"reportZestStatement\\"},\\"body\\":{\\"statementJson\\":\\"{\\"windowHandle\\":\\"windowHandle1\\",\\"type\\":\\"id\\",\\"element\\":\\"click\\",\\"index\\":2,\\"enabled\\":true,\\"elementType\\":\\"ZestClientElementClick\\"}\\",\\"apikey\\":\\"not set\\"}}"]';
129244
expect(JSON.stringify(Array.from(actualData))).toBe(expectedData);
130245
});
131246

@@ -145,9 +260,8 @@ function integrationTests(
145260
await page.close();
146261
// Then
147262
const expectedData =
148-
'["{\\"action\\":{\\"action\\":\\"reportZestStatement\\"},\\"body\\":{\\"statementJson\\":\\"{\\"windowHandle\\":\\"windowHandle1\\",\\"type\\":\\"id\\",\\"element\\":\\"input-1\\",\\"index\\":1,\\"enabled\\":true,\\"elementType\\":\\"ZestClientElementClear\\"}\\",\\"apikey\\":\\"not set\\"}}",' +
149-
'"{\\"action\\":{\\"action\\":\\"reportZestStatement\\"},\\"body\\":{\\"statementJson\\":\\"{\\"value\\":\\"testinput\\",\\"windowHandle\\":\\"windowHandle1\\",\\"type\\":\\"id\\",\\"element\\":\\"input-1\\",\\"index\\":2,\\"enabled\\":true,\\"elementType\\":\\"ZestClientElementSendKeys\\"}\\",\\"apikey\\":\\"not set\\"}}",' +
150-
'"{\\"action\\":{\\"action\\":\\"reportZestStatement\\"},\\"body\\":{\\"statementJson\\":\\"{\\"windowHandle\\":\\"windowHandle1\\",\\"type\\":\\"id\\",\\"element\\":\\"input-1\\",\\"index\\":3,\\"enabled\\":true,\\"elementType\\":\\"ZestClientElementSubmit\\"}\\",\\"apikey\\":\\"not set\\"}}"]';
263+
'["{\\"action\\":{\\"action\\":\\"reportZestStatement\\"},\\"body\\":{\\"statementJson\\":\\"{\\"value\\":\\"testinput\\",\\"windowHandle\\":\\"windowHandle1\\",\\"type\\":\\"id\\",\\"element\\":\\"input-1\\",\\"index\\":1,\\"enabled\\":true,\\"elementType\\":\\"ZestClientElementSendKeys\\"}\\",\\"apikey\\":\\"not set\\"}}",' +
264+
'"{\\"action\\":{\\"action\\":\\"reportZestStatement\\"},\\"body\\":{\\"statementJson\\":\\"{\\"windowHandle\\":\\"windowHandle1\\",\\"type\\":\\"id\\",\\"element\\":\\"input-1\\",\\"index\\":2,\\"enabled\\":true,\\"elementType\\":\\"ZestClientElementSubmit\\"}\\",\\"apikey\\":\\"not set\\"}}"]';
151265
expect(JSON.stringify(Array.from(actualData))).toBe(expectedData);
152266
});
153267

@@ -215,10 +329,9 @@ function integrationTests(
215329
await page.close();
216330
// Then
217331
const expectedData =
218-
'["{\\"action\\":{\\"action\\":\\"reportZestStatement\\"},\\"body\\":{\\"statementJson\\":\\"{\\"windowHandle\\":\\"windowHandle1\\",\\"type\\":\\"id\\",\\"element\\":\\"input-1\\",\\"index\\":1,\\"enabled\\":true,\\"elementType\\":\\"ZestClientElementClear\\"}\\",\\"apikey\\":\\"not set\\"}}",' +
219-
'"{\\"action\\":{\\"action\\":\\"reportZestStatement\\"},\\"body\\":{\\"statementJson\\":\\"{\\"value\\":\\"testinput\\",\\"windowHandle\\":\\"windowHandle1\\",\\"type\\":\\"id\\",\\"element\\":\\"input-1\\",\\"index\\":2,\\"enabled\\":true,\\"elementType\\":\\"ZestClientElementSendKeys\\"}\\",\\"apikey\\":\\"not set\\"}}",' +
220-
'"{\\"action\\":{\\"action\\":\\"reportZestStatement\\"},\\"body\\":{\\"statementJson\\":\\"{\\"windowHandle\\":\\"windowHandle1\\",\\"type\\":\\"id\\",\\"element\\":\\"click\\",\\"index\\":3,\\"enabled\\":true,\\"elementType\\":\\"ZestClientElementClick\\"}\\",\\"apikey\\":\\"not set\\"}}",' +
221-
'"{\\"action\\":{\\"action\\":\\"reportZestStatement\\"},\\"body\\":{\\"statementJson\\":\\"{\\"windowHandle\\":\\"windowHandle1\\",\\"index\\":4,\\"sleepInSeconds\\":0,\\"enabled\\":true,\\"elementType\\":\\"ZestClientWindowClose\\"}\\",\\"apikey\\":\\"not set\\"}}"]';
332+
'["{\\"action\\":{\\"action\\":\\"reportZestStatement\\"},\\"body\\":{\\"statementJson\\":\\"{\\"value\\":\\"testinput\\",\\"windowHandle\\":\\"windowHandle1\\",\\"type\\":\\"id\\",\\"element\\":\\"input-1\\",\\"index\\":1,\\"enabled\\":true,\\"elementType\\":\\"ZestClientElementSendKeys\\"}\\",\\"apikey\\":\\"not set\\"}}",' +
333+
'"{\\"action\\":{\\"action\\":\\"reportZestStatement\\"},\\"body\\":{\\"statementJson\\":\\"{\\"windowHandle\\":\\"windowHandle1\\",\\"type\\":\\"id\\",\\"element\\":\\"click\\",\\"index\\":2,\\"enabled\\":true,\\"elementType\\":\\"ZestClientElementClick\\"}\\",\\"apikey\\":\\"not set\\"}}",' +
334+
'"{\\"action\\":{\\"action\\":\\"reportZestStatement\\"},\\"body\\":{\\"statementJson\\":\\"{\\"windowHandle\\":\\"windowHandle1\\",\\"index\\":3,\\"sleepInSeconds\\":0,\\"enabled\\":true,\\"elementType\\":\\"ZestClientWindowClose\\"}\\",\\"apikey\\":\\"not set\\"}}"]';
222335
expect(JSON.stringify(Array.from(actualData))).toBe(expectedData);
223336
});
224337

@@ -240,10 +353,9 @@ function integrationTests(
240353
await page.close();
241354
// Then
242355
const expectedData =
243-
'["{\\"action\\":{\\"action\\":\\"reportZestStatement\\"},\\"body\\":{\\"statementJson\\":\\"{\\"windowHandle\\":\\"windowHandle1\\",\\"type\\":\\"id\\",\\"element\\":\\"input-1\\",\\"index\\":1,\\"enabled\\":true,\\"elementType\\":\\"ZestClientElementClear\\"}\\",\\"apikey\\":\\"not set\\"}}",' +
244-
'"{\\"action\\":{\\"action\\":\\"reportZestStatement\\"},\\"body\\":{\\"statementJson\\":\\"{\\"value\\":\\"testinput\\",\\"windowHandle\\":\\"windowHandle1\\",\\"type\\":\\"id\\",\\"element\\":\\"input-1\\",\\"index\\":2,\\"enabled\\":true,\\"elementType\\":\\"ZestClientElementSendKeys\\"}\\",\\"apikey\\":\\"not set\\"}}",' +
245-
'"{\\"action\\":{\\"action\\":\\"reportZestStatement\\"},\\"body\\":{\\"statementJson\\":\\"{\\"windowHandle\\":\\"windowHandle1\\",\\"type\\":\\"id\\",\\"element\\":\\"click\\",\\"index\\":3,\\"enabled\\":true,\\"elementType\\":\\"ZestClientElementClick\\"}\\",\\"apikey\\":\\"not set\\"}}",' +
246-
'"{\\"action\\":{\\"action\\":\\"reportZestStatement\\"},\\"body\\":{\\"statementJson\\":\\"{\\"windowHandle\\":\\"windowHandle1\\",\\"index\\":4,\\"sleepInSeconds\\":0,\\"enabled\\":true,\\"elementType\\":\\"ZestClientWindowClose\\"}\\",\\"apikey\\":\\"not set\\"}}"]';
356+
'["{\\"action\\":{\\"action\\":\\"reportZestStatement\\"},\\"body\\":{\\"statementJson\\":\\"{\\"value\\":\\"testinput\\",\\"windowHandle\\":\\"windowHandle1\\",\\"type\\":\\"id\\",\\"element\\":\\"input-1\\",\\"index\\":1,\\"enabled\\":true,\\"elementType\\":\\"ZestClientElementSendKeys\\"}\\",\\"apikey\\":\\"not set\\"}}",' +
357+
'"{\\"action\\":{\\"action\\":\\"reportZestStatement\\"},\\"body\\":{\\"statementJson\\":\\"{\\"windowHandle\\":\\"windowHandle1\\",\\"type\\":\\"id\\",\\"element\\":\\"click\\",\\"index\\":2,\\"enabled\\":true,\\"elementType\\":\\"ZestClientElementClick\\"}\\",\\"apikey\\":\\"not set\\"}}",' +
358+
'"{\\"action\\":{\\"action\\":\\"reportZestStatement\\"},\\"body\\":{\\"statementJson\\":\\"{\\"windowHandle\\":\\"windowHandle1\\",\\"index\\":3,\\"sleepInSeconds\\":0,\\"enabled\\":true,\\"elementType\\":\\"ZestClientWindowClose\\"}\\",\\"apikey\\":\\"not set\\"}}"]';
247359
expect(JSON.stringify(Array.from(actualData))).toBe(expectedData);
248360
});
249361

test/ContentScript/webpages/interactions.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55
<button id="click">click me</button>
66
<input type="text" id="input-1" />
77
<input type="date" id="input-2" />
8+
<input type="text" id="input-3-filled" value="Existing text"/>
9+
<textarea id="textarea-1">Existing text</textarea>
10+
<select name="cars" id="cars">
11+
<option value="volvo">Volvo</option>
12+
<option value="saab">Saab</option>
13+
<option value="mercedes">Mercedes</option>
14+
<option value="audi">Audi</option>
15+
</select>
816
<iframe src="./testFrame.html" name="frame1"></iframe>
917
</body>
1018
</html>

0 commit comments

Comments
 (0)