Skip to content

Commit

Permalink
feat: allow accepting third-party tracking cookies (#107)
Browse files Browse the repository at this point in the history
 - similar behaviour is available using preLoginSelector, however this only works for accepting cookies on the user's application.
  - this allows configuring multiple additional selectors, which will be used after the initial login click, but before attempting to enter third-party credentials
  -this allows a user to configure the plugin to click third-party GDPR-related warnings, for example those seen on Facebook

* docs: add documentation of options.trackingConsentSelectors
  • Loading branch information
TimLehner committed Nov 21, 2021
1 parent 08718ae commit 35e9ae0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ Options passed to the task include:
| passwordSubmitBtn | Optional for CustomizedLogin: string, a selector for password submit button | |
| screenshotOnError | Optional: will grab a screen shot if an error occurs on the username, password, or post-login page and saves in the Cypress screenshots folder. | false |
| additionalSteps | Optional: function, to define any additional steps which may be required after executing functions for username and password, such as answering security questions, PIN, or anything which may be required to fill out after username and password process. The function and this property must be defined or referenced from index.js for Cypress Plugins directory. | `async function moreSteps({page, options} = {}) { await page.waitForSelector('#pin_Field') await page.click('#pin_Field') }` |
| trackingConsentSelectors | Optional: selectors to find and click on after clicking the login button, but before entering details on the third-party site (useful for accepting third-party cookies e.g. Facebook login). Provide multiple if wanting to accept only essential cookies and it requires multiple clicks | `['button[data-testid="cookie-policy-dialog-manage-button"]', 'button-data-testid="cookie-policy-manage-dialog-accept-button"]']` |

## Install

Expand Down
9 changes: 9 additions & 0 deletions src/Plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const fs = require('fs')
* @param {options.passwordSubmitBtn} string selector password submit button
* @param {options.additionalSteps} function any additional func which may be required for signin step after username and password
* @param {options.screenshotOnError} boolean grab a screenshot if an error occurs during username, password, or post-login page
* @param {options.trackingConsentSelectors} array[string] selectors to find and click on before entering details on the third-party site (useful for accepting third-party cookies)
*
*/

Expand Down Expand Up @@ -215,6 +216,14 @@ async function baseLoginConnect(
page = pages[pages.length - 1]
}

// Accept third-party cookies if required
if (options.trackingConsentSelectors !== undefined) {
for (const selector of options.trackingConsentSelectors) {
await page.waitForSelector(selector)
await page.click(selector)
}
}

await typeUsername({page, options})
await typePassword({page, options})

Expand Down

0 comments on commit 35e9ae0

Please sign in to comment.