-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
533 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@guardian/consent-management-platform": patch | ||
--- | ||
|
||
Proof of concept for consumer-self-test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -871,6 +871,11 @@ | |
resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.56.0.tgz#ef20350fec605a7f7035a01764731b2de0f3782b" | ||
integrity sha512-gMsVel9D7f2HLkBma9VbtzZRehRogVRfbr++f06nL2vnCGCNlzOD+/MUov/F4p8myyAHspEhVobgjpX64q5m6A== | ||
|
||
"@guardian/[email protected]": | ||
version "0.0.0-beta-20240219152933" | ||
resolved "https://registry.yarnpkg.com/@guardian/consent-management-platform/-/consent-management-platform-0.0.0-beta-20240219152933.tgz#70a2d7e42a1560a600a75203c29b39449cda9c8c" | ||
integrity sha512-h++oUjYpMm06jkFK9m69AGgMeex5dUM6yqxbupMnVwLARLr79CLa4ghRA9yeBBMY9YBzpqi3rGmQqGqs/L3Dag== | ||
|
||
"@guardian/eslint-config-typescript@^9.0.1": | ||
version "9.0.1" | ||
resolved "https://registry.yarnpkg.com/@guardian/eslint-config-typescript/-/eslint-config-typescript-9.0.1.tgz#42d63f6b4d0c0414d5a7a6a4da3b288fa53df709" | ||
|
@@ -891,6 +896,11 @@ | |
eslint-plugin-eslint-comments "3.2.0" | ||
eslint-plugin-import "2.29.1" | ||
|
||
"@guardian/libs@^16.0.0": | ||
version "16.0.2" | ||
resolved "https://registry.yarnpkg.com/@guardian/libs/-/libs-16.0.2.tgz#df739ffa67f938e125330b52587b33622f8ff797" | ||
integrity sha512-GC3DTyRAWMYNOheSnQES24CA2k9WKZiv+WnZbe3hPu6MsZwjeSeRvylJ+VXk7d2ndX5uDW1OdwkWBX45fVXqsA== | ||
|
||
"@guardian/prettier@^7.0.0": | ||
version "7.0.0" | ||
resolved "https://registry.yarnpkg.com/@guardian/prettier/-/prettier-7.0.0.tgz#42ff79808b8aa989ccc2a26aceb14165587b1172" | ||
|
@@ -4724,10 +4734,10 @@ playwright-aws-lambda@^0.10.0: | |
dependencies: | ||
lambdafs "^2.1.1" | ||
|
||
playwright-core@^1.40.1: | ||
version "1.40.1" | ||
resolved "https://registry.yarnpkg.com/playwright-core/-/playwright-core-1.40.1.tgz#442d15e86866a87d90d07af528e0afabe4c75c05" | ||
integrity sha512-+hkOycxPiV534c4HhpfX6yrlawqVUzITRKwHAmYfmsVreltEl6fAZJ3DPfLMOODw0H3s1Itd6MDCWmP1fl/QvQ== | ||
playwright-core@1.41.2: | ||
version "1.41.2" | ||
resolved "https://registry.yarnpkg.com/playwright-core/-/playwright-core-1.41.2.tgz#db22372c708926c697acc261f0ef8406606802d9" | ||
integrity sha512-VaTvwCA4Y8kxEe+kfm2+uUUw5Lubf38RxF7FpBxLPmGe5sdNkSg5e3ChEigaGrX7qdqT3pt2m/98LiyvU2x6CA== | ||
|
||
prelude-ls@^1.2.1: | ||
version "1.2.1" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import type { Browser, BrowserContext, Page } from 'playwright-core'; | ||
import { launchChromium } from 'playwright-aws-lambda'; | ||
|
||
const ELEMENT_ID = { | ||
TCFV2_FIRST_LAYER_ACCEPT_ALL: | ||
'div.message-component.message-row > button.sp_choice_type_11', | ||
CMP_CONTAINER: '[id*="sp_message_iframe"]', | ||
}; | ||
|
||
/** | ||
* This function console logs an info message. | ||
* | ||
* @param {string} message | ||
*/ | ||
export const log_info = (message: string): void => { | ||
console.log(`(cmp monitoring) info: ${message}`); | ||
}; | ||
|
||
/** | ||
* This function console logs an error message. | ||
* | ||
* @param {string} message | ||
*/ | ||
export const log_error = (message: string): void => { | ||
console.error(`(cmp monitoring): error: ${message}`); | ||
}; | ||
|
||
/** | ||
* This function waits for the page to load | ||
* clicks the accept all button | ||
* | ||
* @param {Config} config | ||
* @param {Page} page | ||
* @param {string} textToPrintToConsole | ||
*/ | ||
export const clickAcceptAllCookies = async (page: Page, textToPrintToConsole: string) => { | ||
|
||
log_info(`Clicking on "${textToPrintToConsole}" on CMP`); | ||
|
||
const acceptAllButton = page.frameLocator(ELEMENT_ID.CMP_CONTAINER).locator(ELEMENT_ID.TCFV2_FIRST_LAYER_ACCEPT_ALL); | ||
await acceptAllButton.click(); | ||
|
||
log_info(`Clicked on "${textToPrintToConsole}"`); | ||
}; | ||
|
||
export const getCMPVersionRunning = async (page: Page) => { | ||
log_info(`Sourcepoint version: ${await page.evaluate('window._sp_.version')}`); | ||
log_info(`CMP version: ${await page.evaluate('window.guCmpHotFix.cmp.version')}`); | ||
}; | ||
|
||
/** | ||
* This function checks for the CMP banner on the page | ||
* | ||
* @param {Page} page | ||
* @return {*} {Promise<void>} | ||
*/ | ||
export const checkCMPIsOnPage = async (page: Page): Promise<void> => { | ||
log_info(`Waiting for CMP: Start`); | ||
|
||
const cmpl = page.locator(ELEMENT_ID.CMP_CONTAINER); | ||
await cmpl.waitFor(); | ||
await getCMPVersionRunning(page); | ||
if (!(await cmpl.isVisible())) { | ||
throw Error('CMP is not present on page'); | ||
} | ||
|
||
log_info(`Waiting for CMP: Complete`); | ||
}; | ||
|
||
/** | ||
* This function loads a url onto a chromium page | ||
* | ||
* @param {Page} page | ||
* @param {string} url | ||
* @return {*} {Promise<void>} | ||
*/ | ||
export const loadPage = async (page: Page, url: string): Promise<void> => { | ||
log_info(`Loading page: Start`); | ||
log_info(`Loading page ${url}`); | ||
|
||
const response = await page.goto(url, { | ||
waitUntil: 'domcontentloaded', | ||
timeout: 30000, | ||
}); | ||
|
||
// If the response status code is not a 2xx success code | ||
if (response != null) { | ||
if (response.status() < 200 || response.status() > 299) { | ||
log_error(`Loading URL: Error: Status ${response.status()}`); | ||
throw 'Failed to load page!'; | ||
} | ||
} | ||
|
||
log_info(`Loading page: Complete`); | ||
}; | ||
|
||
/** | ||
* This function creates a new chromium browser | ||
* | ||
* @param {boolean} debugMode | ||
* @return {*} {Promise<Browser>} | ||
*/ | ||
export const makeNewBrowser = async (debugMode: boolean): Promise<Browser> => { | ||
const browser = await launchChromium({headless:!debugMode}); | ||
return browser; | ||
}; | ||
|
||
/** | ||
* This function creates a new page | ||
* | ||
* @param {BrowserContext} context | ||
* @return {*} {Promise<Page>} | ||
*/ | ||
export const makeNewPage = async (context: BrowserContext): Promise<Page> => { | ||
const page = await context.newPage(); | ||
return page; | ||
}; |
Oops, something went wrong.