Skip to content

Commit

Permalink
Allow click actions to fail silently with an additional parameter (#1444
Browse files Browse the repository at this point in the history
)

* Allow click actions to fail silently with an additional parameter

* Make the failSilently directive work per-element
  • Loading branch information
brianhall authored Feb 1, 2025
1 parent c6b67bb commit 8e1a55f
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 1 deletion.
40 changes: 40 additions & 0 deletions injected/integration-test/broker-protection.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,46 @@ test.describe('Broker Protection communications', () => {
await page.waitForURL((url) => url.hash === '#no', { timeout: 2000 });
});

test('clicking selectors that do not exists should fail', async ({ page }, workerInfo) => {
const dbp = BrokerProtectionPage.create(page, workerInfo.project.use);
await dbp.enabled();
await dbp.navigatesTo('clicks.html');
await dbp.receivesAction('click-nonexistent-selector.json');
const response = await dbp.collector.waitForMessage('actionCompleted');

dbp.isErrorMessage(response);
});

test('clicking buttons that are disabled should fail', async ({ page }, workerInfo) => {
const dbp = BrokerProtectionPage.create(page, workerInfo.project.use);
await dbp.enabled();
await dbp.navigatesTo('clicks.html');
await dbp.receivesAction('click-disabled-button.json');
const response = await dbp.collector.waitForMessage('actionCompleted');

dbp.isErrorMessage(response);
});

test('clicking selectors that do not exist when failSilently is enabled should not fail', async ({ page }, workerInfo) => {
const dbp = BrokerProtectionPage.create(page, workerInfo.project.use);
await dbp.enabled();
await dbp.navigatesTo('clicks.html');
await dbp.receivesAction('click-nonexistent-selector-failSilently.json');
const response = await dbp.collector.waitForMessage('actionCompleted');

dbp.isSuccessMessage(response);
});

test('clicking buttons that are disabled when failSilently is enabled should not fail', async ({ page }, workerInfo) => {
const dbp = BrokerProtectionPage.create(page, workerInfo.project.use);
await dbp.enabled();
await dbp.navigatesTo('clicks.html');
await dbp.receivesAction('click-disabled-button-failSilently.json');
const response = await dbp.collector.waitForMessage('actionCompleted');

dbp.isSuccessMessage(response);
});

test('getCaptchaInfo', async ({ page }, workerInfo) => {
const dbp = BrokerProtectionPage.create(page, workerInfo.project.use);
await dbp.enabled();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"state": {
"action": {
"actionType": "click",
"id": "1",
"elements": [
{
"type": "button",
"selector": ".btn",
"failSilently": true
}
]
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"state": {
"action": {
"actionType": "click",
"id": "1",
"elements": [
{
"type": "button",
"selector": ".btn"
}
]
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"state": {
"action": {
"actionType": "click",
"id": "1",
"elements": [
{
"type": "button",
"selector": ".test",
"failSilently": true
}
]
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"state": {
"action": {
"actionType": "click",
"id": "1",
"elements": [
{
"type": "button",
"selector": ".test"
}
]
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Broker Protection</title>
</head>
<body>
<div class="result">
<div class="name">John Doe</div>
<div class="age">32</div>
<div class="locations" data-id="1">
<span>New York, NY</span>
<span>Los Angeles, CA</span>
<a href="#" class="view-more">View More</a>
</div>
<button disabled class="btn">View More</button>
</div>
</body>
</html>
6 changes: 5 additions & 1 deletion injected/src/features/broker-protection/actions/click.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ export function click(action, userData, root = document) {
const elements = getElements(rootElement, element.selector);

if (!elements?.length) {
if (element.failSilently) {
return new SuccessResponse({ actionID: action.id, actionType: action.actionType, response: null });
}

return new ErrorResponse({
actionID: action.id,
message: `could not find element to click with selector '${element.selector}'!`,
Expand All @@ -63,7 +67,7 @@ export function click(action, userData, root = document) {
const elem = elements[i];

if ('disabled' in elem) {
if (elem.disabled) {
if (elem.disabled && !element.failSilently) {
return new ErrorResponse({ actionID: action.id, message: `could not click disabled element ${element.selector}'!` });
}
}
Expand Down

0 comments on commit 8e1a55f

Please sign in to comment.