Skip to content

Commit

Permalink
Adding tests for headers and redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis Li committed Oct 7, 2024
1 parent 5ff742f commit af9ba43
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 4 deletions.
49 changes: 49 additions & 0 deletions features/bacom/headers.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
module.exports = {
name: 'Headers',
features: [
{
tcid: '0',
name: 'Response headers test for Helix BACOM',
path: [
'/',
'/au/',
'/uk/',
'/de/',
'/fr/',
'/jp/',
'/sitemap.xml',
],
tags: '@headers @responseHeaders @bacom @bacomSmoke @regression @akamai',
},
{
tcid: '1',
name: 'Response headers test for AEM dx',
path: [
// Event pages
'/de/events/experience-makers-germany-2023-on-demand.html',
'/ch_de/events/experience-makers-zurich-2023-on-demand.html',
'/it/events/experience-makers-milan-2023-on-demand.html',
'/nl/events/experience-makers-amsterdam-2023-on-demand.html',
'/se/events/experience-makers-stockholm-2023-on-demand.html',
'/fr/events/experience-makers-paris-2023-on-demand.html',
'/uk/events/experience-makers-london-2023-on-demand.html',

// Product Demo pages
'/product-demos/assets-essentials/interactive-tour.html',
'/de/product-demos/assets-essentials/interactive-tour.html',
'/fr/product-demos/assets-essentials/interactive-tour.html',
'/au/product-demos/assets-essentials/interactive-tour.html',
'/uk/product-demos/assets-essentials/interactive-tour.html',
'/jp/product-demos/assets-essentials/interactive-tour.html',

// Summit pages
'/summit/adobe-summit.html',
'/summit/2024/speakers.html',
'/summit/2024/sessions.html',
'/summit/2024/faq.html',
'/summit/2024/sessions/opening-keynote-gs1.html',
],
tags: '@headers @responseHeaders @bacom @bacomSmoke @regression @akamai',
},
],
};
25 changes: 25 additions & 0 deletions features/bacom/redirects.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = {
name: 'Redirects',
features: [
{
tcid: '0',
name: 'Bacom redirects',
path: [
'/',
'/au',
'/uk',
'/de',
'/fr',
'/jp',
'/blog',
'/au/blog',
'/uk/blog',
'/de/blog',
'/fr/blog',
'/jp/blog',
'/kr/blog',
],
tags: '@redirects @bacom @bacomSmoke @regression',
},
],
};
19 changes: 15 additions & 4 deletions libs/webutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,10 @@ exports.WebUtil = class WebUtil {
const rect = modalDialog.getBoundingClientRect();
return (
rect.top >= 0
&& rect.left >= 0
&& rect.bottom
&& rect.left >= 0
&& rect.bottom
<= (window.innerHeight || document.documentElement.clientHeight)
&& rect.right
&& rect.right
<= (window.innerWidth || document.documentElement.clientWidth)
);
}, selector);
Expand Down Expand Up @@ -282,6 +282,17 @@ exports.WebUtil = class WebUtil {
return res.json();
}

/**
* Makes a GET request
* @param {string} url - The URL to make the GET request to.
* @returns {object} The response object.
*/
static async getRequest(url) {
const requestContext = await request.newContext();
const response = await requestContext.get(url);
return response;
}

/**
* Enable network logging
* @param {Array} networklogs - An array to store all network logs
Expand All @@ -290,7 +301,7 @@ exports.WebUtil = class WebUtil {
await this.page.route('**', (route) => {
const url = route.request().url();
if (url.includes('sstats.adobe.com/ee/or2/v1/interact')
|| url.includes('sstats.adobe.com/ee/or2/v1/collect')) {
|| url.includes('sstats.adobe.com/ee/or2/v1/collect')) {
networklogs.push(url);
const firstEvent = route.request().postDataJSON().events[0];
// eslint-disable-next-line no-underscore-dangle
Expand Down
29 changes: 29 additions & 0 deletions tests/bacom/headers.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { expect, test } from '@playwright/test';
import { features } from '../../features/bacom/headers.spec.js';
import { WebUtil } from '../../libs/webutil.js';

const [bacomHelixPages, aemDxPages] = features;

test.describe('BACOM Headers tests', () => {
bacomHelixPages.path.forEach((path) => {
test(`Checking the response header X-Adobe-Content for ${path} tags: ${bacomHelixPages.tags}`, async () => {
const testPage = `https://business.adobe.com${path}`;
console.log(`[Test Page]: ${testPage}`);
const response = await WebUtil.getRequest(testPage);

expect(response.status()).toBe(200);
expect(response.headers()['x-adobe-content']).toBe('Helix BACOM');
});
});

aemDxPages.path.forEach((path) => {
test(`Checking the response header X-Adobe-Content for ${path} tags: ${aemDxPages.tags}`, async () => {
const testPage = `https://business.adobe.com${path}`;
console.log(`[Test Page]: ${testPage}`);
const response = await WebUtil.getRequest(testPage);

expect(response.status()).toBe(200);
expect(response.headers()['x-adobe-content']).toBe('AEM-dx');
});
});
});
22 changes: 22 additions & 0 deletions tests/bacom/redirects.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { expect, test } from '@playwright/test';
import { features } from '../../features/bacom/redirects.spec.js';
import { WebUtil } from '../../libs/webutil.js';

const [test1] = features;

test.describe('BACOM Redirects tests', () => {
test1.path.forEach((path) => {
test(
`Verifying redirects for URLs without trailing slashes, path: ${path} tags: ${test1.tags}`,
async () => {
const pathWithoutTrailingSlash = path.endsWith('/') ? path.slice(0, -1) : path;
const testPage = `https://business.adobe.com${pathWithoutTrailingSlash}`;
console.log(`[Test Page]: ${testPage}`);
const response = await WebUtil.getRequest(testPage);

expect(response.url().slice(-1)).toBe('/');
expect(response.status()).toBe(200);
},
);
});
});

0 comments on commit af9ba43

Please sign in to comment.