Skip to content

Commit

Permalink
Fix Ketch and eu-cookie-compliance (#351)
Browse files Browse the repository at this point in the history
* Improve the Ketch rule

* Better handle `if` without `else`

* Improve eu-cookie-compliance rule

* Address PR comments
  • Loading branch information
muodov authored Jan 31, 2024
1 parent e90e456 commit 342087b
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 26 deletions.
4 changes: 3 additions & 1 deletion lib/cmps/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export class AutoConsentCMP extends AutoConsentCMPBase {
}

async evaluateRuleStep(rule: AutoConsentRuleStep) {
const results = [];
const results: Array<Promise<boolean> | boolean> = [];
const logsConfig = this.autoconsent.config.logs;
if (rule.exists) {
results.push(this.elementExists(rule.exists));
Expand Down Expand Up @@ -282,6 +282,8 @@ export class AutoConsentCMP extends AutoConsentCMPBase {
results.push(this._runRulesSequentially(rule.then));
} else if (rule.else) {
results.push(this._runRulesSequentially(rule.else));
} else {
results.push(true);
}
}
if (rule.any) {
Expand Down
13 changes: 10 additions & 3 deletions rules/autoconsent/eu-cookie-compliance.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
{
"name": "eu-cookie-compliance-banner",
"detectCmp": [{ "exists": ".eu-cookie-compliance-banner-info" }],
"detectPopup": [{ "exists": ".eu-cookie-compliance-popup-open" }],
"detectCmp": [{ "exists": "body.eu-cookie-compliance-popup-open" }],
"detectPopup": [{ "exists": "body.eu-cookie-compliance-popup-open" }],
"optIn": [{ "click": ".agree-button" }],
"optOut": [
{ "click": ".decline-button,.eu-cookie-compliance-save-preferences-button", "optional": true },
{
"if": {
"visible": ".decline-button,.eu-cookie-compliance-save-preferences-button"
},
"then": [{
"click": ".decline-button,.eu-cookie-compliance-save-preferences-button"
}]
},
{ "hide": ".eu-cookie-compliance-banner-info, #sliding-popup" }
],
"test": [
Expand Down
43 changes: 23 additions & 20 deletions rules/autoconsent/ketch.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "ketch",
"vendorUrl": "https://www.ketch.com",
"runContext": {
"frame": false,
"main": true
Expand All @@ -24,37 +25,39 @@
"exists": "#lanyard_root button[class='confirmButton']"
},
"then": [
{ "waitForThenClick":"#lanyard_root div[class^='buttons'] > :nth-child(2)" },
{ "waitForThenClick":"#lanyard_root div[class*=buttons] > :nth-child(2)" },
{ "click": "#lanyard_root button[class='confirmButton']" }
],
"else": [
{ "waitForThenClick":"#lanyard_root div[class^='buttons'] > :nth-child(2)" }
{ "waitForThenClick":"#lanyard_root div[class*=buttons] > :nth-child(2)" }
]
}
],
"optOut": [
{
"click": "#lanyard_root button[class^='link']",
{
"if": {
"exists": "#lanyard_root [aria-describedby=banner-description]"
},
"then": [
{
"waitForThenClick":"#lanyard_root div[class*=buttons] > button[class*=secondaryButton]",
"comment": "can be either settings or reject button"
}
]
},
{
"waitFor": "#lanyard_root [aria-describedby=preference-description],#lanyard_root [aria-describedby=modal-description]",
"timeout": 1000,
"optional": true
},
{
"if": {
"exists": "#lanyard_root button[class*='confirmButton']"
},
"exists": "#lanyard_root [aria-describedby=preference-description],#lanyard_root [aria-describedby=modal-description]"
},
"then": [
{ "waitForThenClick": "#lanyard_root button[class*='rejectButton']" },
{ "click": "#lanyard_root button[class*='confirmButton']" }
],
"else": [
{
"click": "#lanyard_root div[class^='buttons'] > :nth-child(1)",
"optional": true
},
{ "waitForThenClick": "#lanyard_root input:checked" },
{ "click": "#consentsTab > div:nth-child(2) > div > div[class^='actions'] > button:nth-child(1)" }
{ "waitForThenClick": "#lanyard_root button[class*=rejectButton]" },
{ "click": "#lanyard_root button[class*=confirmButton],#lanyard_root div[class*=actions_] > button:nth-child(1)" }
]
}
],
"test": []
}

]
}
2 changes: 1 addition & 1 deletion tests/eu-cookie-compliance-banner.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import generateCMPTests from "../playwright/runner";

generateCMPTests('eu-cookie-compliance-banner', [
'https://www.bauwion.de/',
'https://www.theposh.com/table/226',
'https://publichealth.jhu.edu/',
]);
2 changes: 1 addition & 1 deletion tests/ketch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import generateCMPTests from "../playwright/runner";
generateCMPTests("ketch", [
"https://www.smartsheet.com/",
"https://www.ketch.com/",
"https://www.patreon.com/",
"https://www.forbes.com/",
]);

0 comments on commit 342087b

Please sign in to comment.