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

Re-implement AMP page checks. #1033

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion cdk/lib/monitoring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class Monitoring extends GuStack {


const monitoringDuration: Duration =
stage === 'PROD' ? Duration.minutes(prodDurationInMinutes) : Duration.days(1); // Every day for CODE; Every 2 minutes for PROD.
stage === 'PROD' ? Duration.minutes(prodDurationInMinutes) : Duration.minutes(2); // REMOVE // Every day for CODE; Every 2 minutes for PROD.

new Rule(this, 'cmp monitoring schedule', {
schedule: Schedule.rate(monitoringDuration),
Expand Down
19 changes: 19 additions & 0 deletions monitoring/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

success_count=0
error_count=0
iterations=20

for ((i=0; i<$iterations; i++))
do
pnpm start --env prod --jurisdiction tcfv2
if [ $? -eq 0 ]
then
((success_count++))
else
((error_count++))
fi
done

echo "Success count: $success_count"
echo "Error count: $error_count"
9 changes: 7 additions & 2 deletions monitoring/src/check-page/common-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ export const ScreenDimensions = {
* @return {*} {Promise<void>}
*/
export const clearCookies = async (page: Page): Promise<void> => {
await page.context().clearCookies();
const cookies = await page.context().cookies();

for(const cookie of cookies) {
await page.context().clearCookies(cookie);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this better than clearCookies()? Could maybe do with a comment for future travellers so nobody ends up "optimizing" this and reverting your change!

}

log_info(`Cleared Cookies`);
};

Expand Down Expand Up @@ -378,7 +383,7 @@ export const checkCMPIsOnPage = async (

if (isAmp) {
cmpl = page
.frameLocator('.i-amphtml-consent-ui-fill')
.frameLocator(ELEMENT_ID.AMP_CMP_CONTAINER)
.locator(ELEMENT_ID.CMP_CONTAINER);
} else {
cmpl = page.locator(ELEMENT_ID.CMP_CONTAINER);
Expand Down
39 changes: 23 additions & 16 deletions monitoring/src/check-page/tcfv2.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Browser, BrowserContext, Page } from 'playwright-core';
import type { Config } from '../types';
import type { CheckPagesProps } from './common-functions';
import {
checkAds,
checkCMPIsNotVisible,
Expand Down Expand Up @@ -65,7 +66,7 @@ const checkSubsequentPage = async (
* @param {string} url
* @param {string} nextUrl
*/
const checkPages = async (config: Config, url: string, nextUrl: string, isAmp: boolean = false) => {
const checkPages = async ({ config, url, nextUrl, isAmp }: CheckPagesProps) => {
log_info(`Start checking Page URL: ${url}`);

const browser: Browser = await makeNewBrowser(config.debugMode);
Expand All @@ -81,8 +82,10 @@ const checkPages = async (config: Config, url: string, nextUrl: string, isAmp: b
const browserForSecondLayerCheck: Browser = await makeNewBrowser(
config.debugMode,
);
const contextForSecondLayerCheck =
await makeNewContext(browserForSecondLayerCheck, isAmp);
const contextForSecondLayerCheck = await makeNewContext(
browserForSecondLayerCheck,
isAmp,
);
const pageForSecondLayerCheck = await makeNewPage(
contextForSecondLayerCheck,
);
Expand Down Expand Up @@ -120,7 +123,7 @@ export const firstLayerCheck = async function (
url: string,
page: Page,
context: BrowserContext,
nextUrl: string,
nextUrl: string | undefined,
isAmp: boolean = false,
): Promise<void> {
log_info('Checking first layer: Start');
Expand Down Expand Up @@ -241,19 +244,23 @@ export const secondLayerCheck = async function (
export const mainCheck = async function (config: Config): Promise<void> {
log_info('checkPage (tcfv2)');
// Testing the user first visits home page then an article page
await checkPages(
await checkPages({
config,
`${config.frontUrl}?adtest=fixed-puppies`,
`${config.articleUrl}?adtest=fixed-puppies`,
);
url: `${config.frontUrl}?adtest=fixed-puppies`,
nextUrl: `${config.articleUrl}?adtest=fixed-puppies`,
isAmp: false,
});

// Testing the user first visits only an article page
await checkPages(config, `${config.articleUrl}?adtest=fixed-puppies`, '');

// await checkPages(
// config,
// `${config.ampArticle}?adtest=fixed-puppies`,
// '',
// true
// );
await checkPages({
config,
url: `${config.articleUrl}?adtest=fixed-puppies`,
isAmp: false,
});

await checkPages({
config,
url: `${config.ampArticle}?adtest=fixed-puppies`,
isAmp: true,
});
};
3 changes: 2 additions & 1 deletion monitoring/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ export const ELEMENT_ID = {
CCPA_DO_NOT_SELL_BUTTON: 'div.message-component > button.sp_choice_type_13',
TCFV2_SECOND_LAYER_REJECT_ALL: 'button.sp_choice_type_REJECT_ALL',
TCFV2_SECOND_LAYER_ACCEPT_ALL: 'button.sp_choice_type_ACCEPT_ALL',
AMP_CMP_CONTAINER: '.i-amphtml-consent-ui-fill'
AMP_CMP_CONTAINER: '.i-amphtml-consent-ui-fill',
AMP_CONSENT: 'amp-consent',
};

export const AWS_REGIONS = {
Expand Down