Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow click actions to fail silently with an additional parameter #1444

Merged
merged 3 commits into from
Feb 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
shakyShane marked this conversation as resolved.
Show resolved Hide resolved
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
Loading