From a3e462627b795223281aa45cb6c8c1ce8e456ce9 Mon Sep 17 00:00:00 2001 From: Jacky Sun Date: Tue, 1 Oct 2024 16:18:51 -0700 Subject: [PATCH 1/8] add tests for graybox-bacom --- configs/graybox-bacom.config.js | 108 ++++++++++++++++++++++ data/graybox/sot-bacom.yml | 22 +++++ envs/envs.js | 1 + features/visual/graybox/sot.bacom.spec.js | 13 +++ tests/visual/graybox/sot.bacom.test.js | 45 +++++++++ 5 files changed, 189 insertions(+) create mode 100644 configs/graybox-bacom.config.js create mode 100644 data/graybox/sot-bacom.yml create mode 100644 features/visual/graybox/sot.bacom.spec.js create mode 100644 tests/visual/graybox/sot.bacom.test.js diff --git a/configs/graybox-bacom.config.js b/configs/graybox-bacom.config.js new file mode 100644 index 00000000..70be8f49 --- /dev/null +++ b/configs/graybox-bacom.config.js @@ -0,0 +1,108 @@ +// @ts-check +const { devices } = require('@playwright/test'); + +const envs = require('../envs/envs.js'); + +/** + * @see https://playwright.dev/docs/test-configuration + * @type {import('@playwright/test').PlaywrightTestConfig} + */ +const config = { + testDir: '../tests/', + testMatch: ['bacom/**/*.test.js', 'milo/**/*.test.js'], + outputDir: '../test-results', + /* Maximum time one test can run for. */ + timeout: 45 * 1000, + expect: { + /** + * Maximum time expect() should wait for the condition to be met. + * For example in `await expect(locator).toHaveText();` + */ + timeout: 10 * 1000, + }, + /* Run tests in files in parallel */ + fullyParallel: true, + /* Fail the build on CI if you accidentally left test.only in the source code. */ + forbidOnly: !!process.env.CI, + /* Retry on CI only */ + retries: process.env.CI ? 2 : 0, + /* Opt out of parallel tests on CI. */ + workers: process.env.CI ? 2 : undefined, + /* Reporter to use. See https://playwright.dev/docs/test-reporters */ + reporter: process.env.CI + ? [['github'], ['list'], ['../utils/reporters/base-reporter.js']] + : [ + [ + 'html', + { + outputFolder: 'test-html-results', + open: 'never', + }, + ], + ['list'], + ['../utils/reporters/base-reporter.js'], + ['json', { outputFile: '../test-json-results/test-results.json' }], + ], + + /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ + use: { + /* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */ + actionTimeout: 60000, + /* Base URL to use in actions like `await page.goto('/')`. */ + // baseURL: 'http://localhost:3000', + + /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ + trace: 'on-first-retry', + baseURL: + process.env.BASE_URL + || envs['@bacom_graybox'] + || 'https://main--bacom--adobecom.hlx.live', + }, + + /* Configure projects for major browsers */ + projects: [ + { + name: 'bacom-live-chrome', + use: { + ...devices['Desktop Chrome'], + baseURL: envs['@bacom_graybox'], + }, + }, + { + name: 'bacom-live-firefox', + use: { + ...devices['Desktop Firefox'], + baseURL: envs['@bacom_graybox'], + }, + }, + { + name: 'bacom-live-webkit', + use: { + ...devices['Desktop Safari'], + baseURL: envs['@bacom_graybox'], + }, + }, + { + name: 'bacom-stage-chrome', + use: { + ...devices['Desktop Chrome'], + baseURL: envs['@bacom_stage'], + }, + }, + { + name: 'bacom-stage-firefox', + use: { + ...devices['Desktop Firefox'], + baseURL: envs['@bacom_stage'], + }, + }, + { + name: 'bacom-stage-webkit', + use: { + ...devices['Desktop Safari'], + baseURL: envs['@bacom_stage'], + }, + }, + ], +}; +module.exports = config; diff --git a/data/graybox/sot-bacom.yml b/data/graybox/sot-bacom.yml new file mode 100644 index 00000000..e5169831 --- /dev/null +++ b/data/graybox/sot-bacom.yml @@ -0,0 +1,22 @@ +--- +'homepage': 'https://business.stage.adobe.com/' +'de homepage': 'https://business.stage.adobe.com/de/' +'fr homepage': 'https://business.stage.adobe.com/fr/' +'au homepage': 'https://business.stage.adobe.com/au/' +'uk homepage': 'https://business.stage.adobe.com/uk/' +'jp homepage': 'https://business.stage.adobe.com/jp/' +'kr homepage': 'https://business.stage.adobe.com/kr/' +'genstudio': 'https://business.stage.adobe.com/products/genstudio.html' +'genstudio/creation': 'https://business.stage.adobe.com/products/genstudio/creation.html' +'aem-sites': 'https://business.stage.adobe.com/products/experience-manager/sites/aem-sites.html' +'rtcdp': 'https://business.stage.adobe.com/products/real-time-customer-data-platform/rtcdp.html' +'ai-assistant': 'https://business.stage.adobe.com/products/sensei/ai-assistant.html' +'resources': 'https://business.stage.adobe.com/resources/main.html' +'holiday-shopping-report': 'https://business.stage.adobe.com/resources/holiday-shopping-report.html' +'experience-cloud': 'https://business.stage.adobe.com/request-consultation/experience-cloud.html' +'experience-magento-compare': 'https://business.stage.adobe.com/resources/experience-magento-compare.html' +'customer-success-stories': 'https://business.stage.adobe.com/customer-success-stories.html' +'pricing': 'https://business.stage.adobe.com/products/pricing.html' +'real-time-customer-data-platform/pricing': 'https://business.stage.adobe.com/products/real-time-customer-data-platform/pricing.html' +'marketo-measure': 'https://business.stage.adobe.com/products/marketo/marketo-measure.html' +'not-found': 'https://business.stage.adobe.com/not-found.html' diff --git a/envs/envs.js b/envs/envs.js index dc72c954..595d41bd 100644 --- a/envs/envs.js +++ b/envs/envs.js @@ -25,4 +25,5 @@ module.exports = { '@dme_stage': 'https://stage--dme-partners--adobecom.hlx.live', '@express_stage': 'https://stage--express--adobecom.hlx.live/express/', '@express_live': 'https://main--express--adobecom.hlx.live/express/', + '@bacom_graybox': 'https://test.business-graybox.adobe.com', }; diff --git a/features/visual/graybox/sot.bacom.spec.js b/features/visual/graybox/sot.bacom.spec.js new file mode 100644 index 00000000..7e5f3082 --- /dev/null +++ b/features/visual/graybox/sot.bacom.spec.js @@ -0,0 +1,13 @@ +module.exports = { + name: 'Graybox Bacom SOT Visual Comparison', + features: [ + { + tcid: '0', + name: '@graybox-bacom-visual', + stable: '@bacom_stage', + beta: '@graybox_bacom', + tags: '@graybox-bacom-visual @visual @graybox-bacom-screenshots', + data: 'data/graybox/sot-bacom.yml', + }, + ], +}; diff --git a/tests/visual/graybox/sot.bacom.test.js b/tests/visual/graybox/sot.bacom.test.js new file mode 100644 index 00000000..970df9ef --- /dev/null +++ b/tests/visual/graybox/sot.bacom.test.js @@ -0,0 +1,45 @@ +/* eslint-disable no-restricted-syntax */ +/* eslint-disable import/named */ +import { test } from '@playwright/test'; +import { features } from '../../../features/visual/graybox/sot.bacom.spec.js'; +import { takeTwo } from '../../../libs/screenshot/take.js'; +import { writeResultsToFile } from '../../../libs/screenshot/utils.js'; + +const { WebUtil } = require('../../../libs/webutil.js'); + +const folderPath = 'screenshots/graybox-bacom'; +const results = {}; + +test.describe('Graybox Bacom SOT visual comparison test suite', () => { + // reset timeout because we use this to run all test data + test.setTimeout(10 * 60 * 1000); + for (const feature of features) { + // eslint-disable-next-line no-loop-func + test(`${feature.name},${feature.tags}`, async ({ page }, testInfo) => { + // load test data from static files + const testdata = await WebUtil.loadTestData(`${feature.data}`); + + for (const key of Object.keys(testdata)) { + const stableURL = testdata[key]; + console.info(stableURL); + const betaURL = testdata[key].replace('business.stage', 'test.business-graybox'); + console.info(betaURL); + + const name = `${feature.name}-${key}-${testInfo.project.name}`; + // eslint-disable-next-line no-await-in-loop + const result = await takeTwo( + page, + stableURL, + async () => { await page.waitForTimeout(5000); }, + betaURL, + async () => { await page.waitForTimeout(5000); }, + folderPath, + name, + { fullPage: true }, + ); + results[name] = [result]; + } + writeResultsToFile(folderPath, testInfo, results); + }); + } +}); From 595509bbd5195e9edad5c75b59c34bebeff372a5 Mon Sep 17 00:00:00 2001 From: Jacky Sun Date: Tue, 1 Oct 2024 16:28:37 -0700 Subject: [PATCH 2/8] just use chrome --- configs/graybox-bacom.config.js | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/configs/graybox-bacom.config.js b/configs/graybox-bacom.config.js index 70be8f49..870048c8 100644 --- a/configs/graybox-bacom.config.js +++ b/configs/graybox-bacom.config.js @@ -68,20 +68,6 @@ const config = { baseURL: envs['@bacom_graybox'], }, }, - { - name: 'bacom-live-firefox', - use: { - ...devices['Desktop Firefox'], - baseURL: envs['@bacom_graybox'], - }, - }, - { - name: 'bacom-live-webkit', - use: { - ...devices['Desktop Safari'], - baseURL: envs['@bacom_graybox'], - }, - }, { name: 'bacom-stage-chrome', use: { @@ -89,20 +75,6 @@ const config = { baseURL: envs['@bacom_stage'], }, }, - { - name: 'bacom-stage-firefox', - use: { - ...devices['Desktop Firefox'], - baseURL: envs['@bacom_stage'], - }, - }, - { - name: 'bacom-stage-webkit', - use: { - ...devices['Desktop Safari'], - baseURL: envs['@bacom_stage'], - }, - }, ], }; module.exports = config; From 6428961166c81ee5640b846e3e33ac1594c939da Mon Sep 17 00:00:00 2001 From: Jacky Sun Date: Tue, 1 Oct 2024 16:53:00 -0700 Subject: [PATCH 3/8] add more waiting time --- tests/visual/graybox/sot.bacom.test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/visual/graybox/sot.bacom.test.js b/tests/visual/graybox/sot.bacom.test.js index 970df9ef..8cb5443d 100644 --- a/tests/visual/graybox/sot.bacom.test.js +++ b/tests/visual/graybox/sot.bacom.test.js @@ -12,7 +12,7 @@ const results = {}; test.describe('Graybox Bacom SOT visual comparison test suite', () => { // reset timeout because we use this to run all test data - test.setTimeout(10 * 60 * 1000); + test.setTimeout(20 * 60 * 1000); for (const feature of features) { // eslint-disable-next-line no-loop-func test(`${feature.name},${feature.tags}`, async ({ page }, testInfo) => { @@ -30,9 +30,9 @@ test.describe('Graybox Bacom SOT visual comparison test suite', () => { const result = await takeTwo( page, stableURL, - async () => { await page.waitForTimeout(5000); }, + async () => { await page.waitForTimeout(10000); }, betaURL, - async () => { await page.waitForTimeout(5000); }, + async () => { await page.waitForTimeout(15000); }, folderPath, name, { fullPage: true }, From 489f826f35613898735abf50dcada96081c71551 Mon Sep 17 00:00:00 2001 From: Jacky Sun Date: Tue, 1 Oct 2024 17:07:37 -0700 Subject: [PATCH 4/8] add merch card --- data/graybox/sot-bacom.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/data/graybox/sot-bacom.yml b/data/graybox/sot-bacom.yml index e5169831..cfe64705 100644 --- a/data/graybox/sot-bacom.yml +++ b/data/graybox/sot-bacom.yml @@ -1,4 +1,5 @@ --- +'not-found': 'https://business.stage.adobe.com/not-found.html' 'homepage': 'https://business.stage.adobe.com/' 'de homepage': 'https://business.stage.adobe.com/de/' 'fr homepage': 'https://business.stage.adobe.com/fr/' @@ -19,4 +20,4 @@ 'pricing': 'https://business.stage.adobe.com/products/pricing.html' 'real-time-customer-data-platform/pricing': 'https://business.stage.adobe.com/products/real-time-customer-data-platform/pricing.html' 'marketo-measure': 'https://business.stage.adobe.com/products/marketo/marketo-measure.html' -'not-found': 'https://business.stage.adobe.com/not-found.html' +'merch-card': 'https://business.stage.adobe.com/drafts/denli/blocks/merch-card' From b5d120040e56b1a508afcf2ae7c766ebc4e9ca87 Mon Sep 17 00:00:00 2001 From: Jacky Sun Date: Mon, 14 Oct 2024 18:27:48 -0700 Subject: [PATCH 5/8] add 404 checker for graxybox-bacom --- configs/graybox-bacom.config.js | 4 +- features/graybox/sot.bacom.404.spec.js | 13 +++++ tests/graybox/sot.bacom.404.test.js | 68 ++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 features/graybox/sot.bacom.404.spec.js create mode 100644 tests/graybox/sot.bacom.404.test.js diff --git a/configs/graybox-bacom.config.js b/configs/graybox-bacom.config.js index 870048c8..e0bc4b88 100644 --- a/configs/graybox-bacom.config.js +++ b/configs/graybox-bacom.config.js @@ -9,7 +9,7 @@ const envs = require('../envs/envs.js'); */ const config = { testDir: '../tests/', - testMatch: ['bacom/**/*.test.js', 'milo/**/*.test.js'], + testMatch: ['bacom/**/*.test.js', 'milo/**/*.test.js', 'graybox/**/*.test.js'], outputDir: '../test-results', /* Maximum time one test can run for. */ timeout: 45 * 1000, @@ -30,7 +30,7 @@ const config = { workers: process.env.CI ? 2 : undefined, /* Reporter to use. See https://playwright.dev/docs/test-reporters */ reporter: process.env.CI - ? [['github'], ['list'], ['../utils/reporters/base-reporter.js']] + ? [['github'], ['list'], ['../utils/reporters/base-reporter.js'], ['json', { outputFile: '../test-json-results/test-results.json' }]] : [ [ 'html', diff --git a/features/graybox/sot.bacom.404.spec.js b/features/graybox/sot.bacom.404.spec.js new file mode 100644 index 00000000..a0f64612 --- /dev/null +++ b/features/graybox/sot.bacom.404.spec.js @@ -0,0 +1,13 @@ +module.exports = { + name: 'Graybox Bacom SOT 404 Check', + features: [ + { + tcid: '0', + name: '@graybox-bacom-404-check', + stable: '@bacom_stage', + beta: '@graybox_bacom', + tags: '@graybox-bacom-404-check', + data: 'data/graybox/sot-bacom.yml', + }, + ], +}; diff --git a/tests/graybox/sot.bacom.404.test.js b/tests/graybox/sot.bacom.404.test.js new file mode 100644 index 00000000..b05d0beb --- /dev/null +++ b/tests/graybox/sot.bacom.404.test.js @@ -0,0 +1,68 @@ +/* eslint-disable no-restricted-syntax */ +/* eslint-disable import/named */ +import { test } from '@playwright/test'; +import { features } from '../../features/graybox/sot.bacom.404.spec.js'; + +const fs = require('fs'); // Add this import at the top + +const { WebUtil } = require('../../libs/webutil.js'); + +const results = {}; +let consoleErrors = []; +let four0FourErrors = []; + +test.describe('Graybox Bacom SOT 404 Check test suite', () => { + test.setTimeout(20 * 60 * 1000); + test.beforeEach(async ({ page }) => { + // Check for 404s + page.on('response', (response) => { + if (response.status() === 404) { + console.log(`Resource not found: ${response.url()}`); + four0FourErrors.push(`Resource not found: ${response.url()}`); + } + }); + + // Check for console errors + page.on('console', (msg) => { + if (msg.type() === 'error') { + console.error(`Console error: ${msg.text()}`); + consoleErrors.push(`Console error: ${msg.text()}`); // Fix to store console errors in the results object + } + }); + }); + + for (const feature of features) { + // eslint-disable-next-line no-loop-func + test(`${feature.name},${feature.tags}`, async ({ page }) => { + // load test data from static files + const testdata = await WebUtil.loadTestData(`${feature.data}`); + + for (const key of Object.keys(testdata)) { + consoleErrors = []; + four0FourErrors = []; + const stableURL = testdata[key]; + const betaURL = stableURL.replace('business.stage', 'test.business-graybox'); + console.info('Checking for 404s on:', betaURL); + // Go to the page you want to check + await page.goto(betaURL); + + // Wait for some time to ensure all resources are loaded + await page.waitForLoadState('networkidle'); // Better way to wait for page load + // {{ edit_1 }}: Log all links on the page + const links = await page.$$eval('a', (anchors) => anchors.map((anchor) => anchor.href)); + console.log('Links on the page:', links); + results[betaURL] = { + four0FourErrors, + consoleErrors, + links, + }; + } + }); + } + + // {{ edit_3 }}: Write results to JSON file after all tests + test.afterAll(async () => { + fs.writeFileSync('404-results.json', JSON.stringify(results, null, 2)); + console.log('Results saved to 404-results.json'); + }); +}); From 5395d4701839676b7d92ccbd5d5236069dd3ca59 Mon Sep 17 00:00:00 2001 From: Jacky Sun Date: Tue, 15 Oct 2024 13:19:25 -0700 Subject: [PATCH 6/8] update gitignore and file name --- .gitignore | 2 ++ tests/graybox/sot.bacom.404.test.js | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 98e50991..006dbce8 100644 --- a/.gitignore +++ b/.gitignore @@ -141,3 +141,5 @@ configs/playwright-browserstack-sdk.config.js playwright-browserstack-sdk.config.temp.json .auth/ + +*-404-results.json diff --git a/tests/graybox/sot.bacom.404.test.js b/tests/graybox/sot.bacom.404.test.js index b05d0beb..69578058 100644 --- a/tests/graybox/sot.bacom.404.test.js +++ b/tests/graybox/sot.bacom.404.test.js @@ -62,7 +62,7 @@ test.describe('Graybox Bacom SOT 404 Check test suite', () => { // {{ edit_3 }}: Write results to JSON file after all tests test.afterAll(async () => { - fs.writeFileSync('404-results.json', JSON.stringify(results, null, 2)); - console.log('Results saved to 404-results.json'); + fs.writeFileSync('graybox-bacom-404-results.json', JSON.stringify(results, null, 2)); + console.log('Results saved to graybox-bacom-404-results.json'); }); }); From 6a3537db207498c10759e22e050dc008bd4d9b13 Mon Sep 17 00:00:00 2001 From: Jacky Sun Date: Thu, 17 Oct 2024 14:03:55 -0700 Subject: [PATCH 7/8] add screenshots for graybox-dc --- data/graybox/sot-dc.yml | 10 ++++++ envs/envs.js | 3 +- features/visual/graybox/sot.dc.spec.js | 13 ++++++++ tests/visual/graybox/sot.dc.test.js | 45 ++++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 data/graybox/sot-dc.yml create mode 100644 features/visual/graybox/sot.dc.spec.js create mode 100644 tests/visual/graybox/sot.dc.test.js diff --git a/data/graybox/sot-dc.yml b/data/graybox/sot-dc.yml new file mode 100644 index 00000000..cbc14ac5 --- /dev/null +++ b/data/graybox/sot-dc.yml @@ -0,0 +1,10 @@ +--- +'not-found': 'https://www.stage.adobe.com/not-found.html' +'Homepage': 'https://www.stage.adobe.com/acrobat/business.html' +'AcrobatPro': 'https://www.stage.adobe.com/acrobat/business/acrobat-pro.html' +'Pricing': 'https://www.stage.adobe.com/acrobat/pricing.html' +'Word2PDF': 'https://www.stage.adobe.com/acrobat/online/word-to-pdf.html' +'AIChatPDF': 'https://www.stage.adobe.com/acrobat/online/ai-chat-pdf.html' +'PDFtoWord': 'https://www.stage.adobe.com/acrobat/online/pdf-to-word.html' +'Sign': 'https://www.stage.adobe.com/acrobat/acrobat/business/sign.html' +'AdobeSign': 'https://www.stage.adobe.com/acrobat/business/online-signature.html' diff --git a/envs/envs.js b/envs/envs.js index 6d031d6a..6bd09d30 100644 --- a/envs/envs.js +++ b/envs/envs.js @@ -25,5 +25,6 @@ module.exports = { '@dme_stage': 'https://stage--dme-partners--adobecom.hlx.live', '@express_stage': 'https://stage--express--adobecom.hlx.live/express', '@express_live': 'https://main--express--adobecom.hlx.live/express', - '@bacom_graybox': 'https://test.business-graybox.adobe.com', + '@graybox_bacom': 'https://test.business-graybox.adobe.com', + '@graybox_dc': 'https://test.graybox.adobe.com', }; diff --git a/features/visual/graybox/sot.dc.spec.js b/features/visual/graybox/sot.dc.spec.js new file mode 100644 index 00000000..19182f7f --- /dev/null +++ b/features/visual/graybox/sot.dc.spec.js @@ -0,0 +1,13 @@ +module.exports = { + name: 'Graybox DC SOT Visual Comparison', + features: [ + { + tcid: '0', + name: '@graybox-dc-visual', + stable: '@adobe_stage', + beta: '@graybox_dc', + tags: '@graybox-dc-visual @visual @graybox-dc-screenshots', + data: 'data/graybox/sot-dc.yml', + }, + ], +}; diff --git a/tests/visual/graybox/sot.dc.test.js b/tests/visual/graybox/sot.dc.test.js new file mode 100644 index 00000000..7c6a58e4 --- /dev/null +++ b/tests/visual/graybox/sot.dc.test.js @@ -0,0 +1,45 @@ +/* eslint-disable no-restricted-syntax */ +/* eslint-disable import/named */ +import { test } from '@playwright/test'; +import { features } from '../../../features/visual/graybox/sot.dc.spec.js'; +import { takeTwo } from '../../../libs/screenshot/take.js'; +import { writeResultsToFile } from '../../../libs/screenshot/utils.js'; + +const { WebUtil } = require('../../../libs/webutil.js'); + +const folderPath = 'screenshots/graybox-dc'; +const results = {}; + +test.describe('Graybox DC SOT visual comparison test suite', () => { + // reset timeout because we use this to run all test data + test.setTimeout(20 * 60 * 1000); + for (const feature of features) { + // eslint-disable-next-line no-loop-func + test(`${feature.name},${feature.tags}`, async ({ page }, testInfo) => { + // load test data from static files + const testdata = await WebUtil.loadTestData(`${feature.data}`); + + for (const key of Object.keys(testdata)) { + const stableURL = testdata[key]; + console.info(stableURL); + const betaURL = testdata[key].replace('www.stage', 'test.graybox'); + console.info(betaURL); + + const name = `${feature.name}-${key}-${testInfo.project.name}`; + // eslint-disable-next-line no-await-in-loop + const result = await takeTwo( + page, + stableURL, + async () => { await page.waitForTimeout(10000); }, + betaURL, + async () => { await page.waitForTimeout(15000); }, + folderPath, + name, + { fullPage: true }, + ); + results[name] = [result]; + } + writeResultsToFile(folderPath, testInfo, results); + }); + } +}); From 4acbc0134738b1ca751db1e316b36697e0bfbc5a Mon Sep 17 00:00:00 2001 From: Jacky Sun Date: Mon, 21 Oct 2024 15:21:33 -0700 Subject: [PATCH 8/8] add 404 checking for graybox dc --- configs/graybox-dc.config.js | 80 +++++++++++++++++++++++++++++ features/graybox/sot.dc.404.spec.js | 13 +++++ tests/graybox/sot.dc.404.test.js | 68 ++++++++++++++++++++++++ 3 files changed, 161 insertions(+) create mode 100644 configs/graybox-dc.config.js create mode 100644 features/graybox/sot.dc.404.spec.js create mode 100644 tests/graybox/sot.dc.404.test.js diff --git a/configs/graybox-dc.config.js b/configs/graybox-dc.config.js new file mode 100644 index 00000000..d6ff1857 --- /dev/null +++ b/configs/graybox-dc.config.js @@ -0,0 +1,80 @@ +// @ts-check +const { devices } = require('@playwright/test'); + +const envs = require('../envs/envs.js'); + +/** + * @see https://playwright.dev/docs/test-configuration + * @type {import('@playwright/test').PlaywrightTestConfig} + */ +const config = { + testDir: '../tests/', + testMatch: ['dc/**/*.test.js', 'milo/**/*.test.js', 'graybox/**/*.test.js'], + outputDir: '../test-results', + /* Maximum time one test can run for. */ + timeout: 45 * 1000, + expect: { + /** + * Maximum time expect() should wait for the condition to be met. + * For example in `await expect(locator).toHaveText();` + */ + timeout: 10 * 1000, + }, + /* Run tests in files in parallel */ + fullyParallel: true, + /* Fail the build on CI if you accidentally left test.only in the source code. */ + forbidOnly: !!process.env.CI, + /* Retry on CI only */ + retries: process.env.CI ? 2 : 0, + /* Opt out of parallel tests on CI. */ + workers: process.env.CI ? 2 : undefined, + /* Reporter to use. See https://playwright.dev/docs/test-reporters */ + reporter: process.env.CI + ? [['github'], ['list'], ['../utils/reporters/base-reporter.js'], ['json', { outputFile: '../test-json-results/test-results.json' }]] + : [ + [ + 'html', + { + outputFolder: 'test-html-results', + open: 'never', + }, + ], + ['list'], + ['../utils/reporters/base-reporter.js'], + ['json', { outputFile: '../test-json-results/test-results.json' }], + ], + + /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ + use: { + /* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */ + actionTimeout: 60000, + /* Base URL to use in actions like `await page.goto('/')`. */ + // baseURL: 'http://localhost:3000', + + /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ + trace: 'on-first-retry', + baseURL: + process.env.BASE_URL + || envs['@graybox_dc'] + || 'https://main--dc--adobecom.hlx.live', + }, + + /* Configure projects for major browsers */ + projects: [ + { + name: 'dc-live-chrome', + use: { + ...devices['Desktop Chrome'], + baseURL: envs['@graybox_dc'], + }, + }, + { + name: 'dc-stage-chrome', + use: { + ...devices['Desktop Chrome'], + baseURL: envs['@adobe_stage'], + }, + }, + ], +}; +module.exports = config; diff --git a/features/graybox/sot.dc.404.spec.js b/features/graybox/sot.dc.404.spec.js new file mode 100644 index 00000000..d6392f61 --- /dev/null +++ b/features/graybox/sot.dc.404.spec.js @@ -0,0 +1,13 @@ +module.exports = { + name: 'Graybox DC SOT 404 Check', + features: [ + { + tcid: '0', + name: '@graybox-dc-404-check', + stable: '@adobe_stage', + beta: '@graybox_dc', + tags: '@graybox-dc-404-check', + data: 'data/graybox/sot-dc.yml', + }, + ], +}; diff --git a/tests/graybox/sot.dc.404.test.js b/tests/graybox/sot.dc.404.test.js new file mode 100644 index 00000000..6471cbfd --- /dev/null +++ b/tests/graybox/sot.dc.404.test.js @@ -0,0 +1,68 @@ +/* eslint-disable no-restricted-syntax */ +/* eslint-disable import/named */ +import { test } from '@playwright/test'; +import { features } from '../../features/graybox/sot.dc.404.spec.js'; + +const fs = require('fs'); // Add this import at the top + +const { WebUtil } = require('../../libs/webutil.js'); + +const results = {}; +let consoleErrors = []; +let four0FourErrors = []; + +test.describe('Graybox DC SOT 404 Check test suite', () => { + test.setTimeout(20 * 60 * 1000); + test.beforeEach(async ({ page }) => { + // Check for 404s + page.on('response', (response) => { + if (response.status() === 404) { + console.log(`Resource not found: ${response.url()}`); + four0FourErrors.push(`Resource not found: ${response.url()}`); + } + }); + + // Check for console errors + page.on('console', (msg) => { + if (msg.type() === 'error') { + console.error(`Console error: ${msg.text()}`); + consoleErrors.push(`Console error: ${msg.text()}`); // Fix to store console errors in the results object + } + }); + }); + + for (const feature of features) { + // eslint-disable-next-line no-loop-func + test(`${feature.name},${feature.tags}`, async ({ page }) => { + // load test data from static files + const testdata = await WebUtil.loadTestData(`${feature.data}`); + + for (const key of Object.keys(testdata)) { + consoleErrors = []; + four0FourErrors = []; + const stableURL = testdata[key]; + const betaURL = stableURL.replace('www.stage', 'test.graybox'); + console.info('Checking for 404s on:', betaURL); + // Go to the page you want to check + await page.goto(betaURL); + + // Wait for some time to ensure all resources are loaded + await page.waitForLoadState('networkidle'); // Better way to wait for page load + // {{ edit_1 }}: Log all links on the page + const links = await page.$$eval('a', (anchors) => anchors.map((anchor) => anchor.href)); + console.log('Links on the page:', links); + results[betaURL] = { + four0FourErrors, + consoleErrors, + links, + }; + } + }); + } + + // {{ edit_3 }}: Write results to JSON file after all tests + test.afterAll(async () => { + fs.writeFileSync('graybox-dc-404-results.json', JSON.stringify(results, null, 2)); + console.log('Results saved to graybox-dc-404-results.json'); + }); +});