Skip to content

Commit 1706d59

Browse files
brianhallmgurgel
authored andcommitted
Allow click actions to fail silently with an additional parameter (#1444)
* Allow click actions to fail silently with an additional parameter * Make the failSilently directive work per-element
1 parent 26a0446 commit 1706d59

File tree

7 files changed

+127
-1
lines changed

7 files changed

+127
-1
lines changed

injected/integration-test/broker-protection.spec.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,46 @@ test.describe('Broker Protection communications', () => {
469469
await page.waitForURL((url) => url.hash === '#no', { timeout: 2000 });
470470
});
471471

472+
test('clicking selectors that do not exists should fail', async ({ page }, workerInfo) => {
473+
const dbp = BrokerProtectionPage.create(page, workerInfo.project.use);
474+
await dbp.enabled();
475+
await dbp.navigatesTo('clicks.html');
476+
await dbp.receivesAction('click-nonexistent-selector.json');
477+
const response = await dbp.collector.waitForMessage('actionCompleted');
478+
479+
dbp.isErrorMessage(response);
480+
});
481+
482+
test('clicking buttons that are disabled should fail', async ({ page }, workerInfo) => {
483+
const dbp = BrokerProtectionPage.create(page, workerInfo.project.use);
484+
await dbp.enabled();
485+
await dbp.navigatesTo('clicks.html');
486+
await dbp.receivesAction('click-disabled-button.json');
487+
const response = await dbp.collector.waitForMessage('actionCompleted');
488+
489+
dbp.isErrorMessage(response);
490+
});
491+
492+
test('clicking selectors that do not exist when failSilently is enabled should not fail', async ({ page }, workerInfo) => {
493+
const dbp = BrokerProtectionPage.create(page, workerInfo.project.use);
494+
await dbp.enabled();
495+
await dbp.navigatesTo('clicks.html');
496+
await dbp.receivesAction('click-nonexistent-selector-failSilently.json');
497+
const response = await dbp.collector.waitForMessage('actionCompleted');
498+
499+
dbp.isSuccessMessage(response);
500+
});
501+
502+
test('clicking buttons that are disabled when failSilently is enabled should not fail', async ({ page }, workerInfo) => {
503+
const dbp = BrokerProtectionPage.create(page, workerInfo.project.use);
504+
await dbp.enabled();
505+
await dbp.navigatesTo('clicks.html');
506+
await dbp.receivesAction('click-disabled-button-failSilently.json');
507+
const response = await dbp.collector.waitForMessage('actionCompleted');
508+
509+
dbp.isSuccessMessage(response);
510+
});
511+
472512
test('getCaptchaInfo', async ({ page }, workerInfo) => {
473513
const dbp = BrokerProtectionPage.create(page, workerInfo.project.use);
474514
await dbp.enabled();
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"state": {
3+
"action": {
4+
"actionType": "click",
5+
"id": "1",
6+
"elements": [
7+
{
8+
"type": "button",
9+
"selector": ".btn",
10+
"failSilently": true
11+
}
12+
]
13+
}
14+
}
15+
}
16+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"state": {
3+
"action": {
4+
"actionType": "click",
5+
"id": "1",
6+
"elements": [
7+
{
8+
"type": "button",
9+
"selector": ".btn"
10+
}
11+
]
12+
}
13+
}
14+
}
15+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"state": {
3+
"action": {
4+
"actionType": "click",
5+
"id": "1",
6+
"elements": [
7+
{
8+
"type": "button",
9+
"selector": ".test",
10+
"failSilently": true
11+
}
12+
]
13+
}
14+
}
15+
}
16+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"state": {
3+
"action": {
4+
"actionType": "click",
5+
"id": "1",
6+
"elements": [
7+
{
8+
"type": "button",
9+
"selector": ".test"
10+
}
11+
]
12+
}
13+
}
14+
}
15+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width">
6+
<title>Broker Protection</title>
7+
</head>
8+
<body>
9+
<div class="result">
10+
<div class="name">John Doe</div>
11+
<div class="age">32</div>
12+
<div class="locations" data-id="1">
13+
<span>New York, NY</span>
14+
<span>Los Angeles, CA</span>
15+
<a href="#" class="view-more">View More</a>
16+
</div>
17+
<button disabled class="btn">View More</button>
18+
</div>
19+
</body>
20+
</html>

injected/src/features/broker-protection/actions/click.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ export function click(action, userData, root = document) {
5151
const elements = getElements(rootElement, element.selector);
5252

5353
if (!elements?.length) {
54+
if (element.failSilently) {
55+
return new SuccessResponse({ actionID: action.id, actionType: action.actionType, response: null });
56+
}
57+
5458
return new ErrorResponse({
5559
actionID: action.id,
5660
message: `could not find element to click with selector '${element.selector}'!`,
@@ -63,7 +67,7 @@ export function click(action, userData, root = document) {
6367
const elem = elements[i];
6468

6569
if ('disabled' in elem) {
66-
if (elem.disabled) {
70+
if (elem.disabled && !element.failSilently) {
6771
return new ErrorResponse({ actionID: action.id, message: `could not click disabled element ${element.selector}'!` });
6872
}
6973
}

0 commit comments

Comments
 (0)