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

Add 404 checking for graybox-bacom #453

Merged
merged 9 commits into from
Oct 15, 2024
Merged
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: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,5 @@ configs/playwright-browserstack-sdk.config.js
playwright-browserstack-sdk.config.temp.json

.auth/

*-404-results.json
4 changes: 2 additions & 2 deletions configs/graybox-bacom.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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',
Expand Down
13 changes: 13 additions & 0 deletions features/graybox/sot.bacom.404.spec.js
Original file line number Diff line number Diff line change
@@ -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',
},
],
};
68 changes: 68 additions & 0 deletions tests/graybox/sot.bacom.404.test.js
Original file line number Diff line number Diff line change
@@ -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('graybox-bacom-404-results.json', JSON.stringify(results, null, 2));
console.log('Results saved to graybox-bacom-404-results.json');
});
});
Loading