Skip to content

Commit b520d2d

Browse files
authored
Merge pull request #282 from thc202/ignore-click-submit
Ignore synthetic click event
2 parents f421dbe + 03346da commit b520d2d

File tree

5 files changed

+46
-3
lines changed

5 files changed

+46
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
77

88
### Fixed
99
- Ignore events on non-visible elements, which will fail on replay.
10+
- Ignore click after submit, since the former is a side effect of the latter.
1011

1112
## 0.1.7 - 2025-11-28
1213

CHANGELOG.rec.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
77

88
### Fixed
99
- Ignore events on non-visible elements, which will fail on replay.
10+
- Ignore click after submit, since the former is a side effect of the latter.
1011

1112
## 0.1.7 - 2025-11-28
1213

source/ContentScript/recorder.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,15 @@ class Recorder {
145145
this.handleFrameSwitches(level, frame);
146146
console.log(event, 'ZAP clicked');
147147
const elementLocator = getPath(event.target as HTMLElement, element);
148+
149+
if ((event as MouseEvent).detail === 0) {
150+
// Not a user click.
151+
if (this.cachedSubmit) {
152+
this.handleCachedSubmit();
153+
}
154+
return;
155+
}
156+
148157
this.sendZestScriptToZAP(
149158
new ZestStatementElementScrollTo(elementLocator, waited),
150159
false

test/ContentScript/integrationTests.test.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -690,9 +690,29 @@ function integrationTests(
690690
reportZestStatementScrollTo(3, 'visibleButton'),
691691
reportZestStatementClick(4, 'visibleButton'),
692692
reportZestStatementScrollTo(5, 'visibleCheckBox'),
693-
reportZestStatementClick(6, 'visibleCheckBox'),
694-
reportZestStatementScrollTo(7, 'visibleCheckBox'),
695-
reportZestStatementSendKeys(8, 'visibleCheckBox', 'on', 'id'),
693+
reportZestStatementSendKeys(6, 'visibleCheckBox', 'on', 'id'),
694+
]);
695+
});
696+
697+
test('Should not record click before submit', async () => {
698+
// Given / When
699+
await driver.toggleRecording();
700+
const wd = await driver.getWebDriver();
701+
await wd.get(`http://localhost:${_HTTPPORT}/webpages/submitClick.html`);
702+
const input = await wd.findElement(By.id('input'));
703+
await input.sendKeys('value');
704+
await input.sendKeys(Key.ENTER);
705+
await eventsProcessed();
706+
// Then
707+
expect(actualData).toEqual([
708+
reportZestStatementComment(),
709+
reportZestStatementLaunch(
710+
'http://localhost:1801/webpages/submitClick.html'
711+
),
712+
reportZestStatementScrollTo(3, 'input'),
713+
reportZestStatementSendKeys(4, 'input', 'value'),
714+
reportZestStatementScrollTo(5, 'input'),
715+
reportZestStatementSubmit(6, 'input'),
696716
]);
697717
});
698718

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Submit and Click</title>
5+
</head>
6+
<body>
7+
<form>
8+
<input id="input" type="text">
9+
<button id="submit" type="submit">Click Me</button>
10+
</form>
11+
</body>
12+
</html>

0 commit comments

Comments
 (0)