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 8, 2024
1 parent 5ff742f commit 58b5b64
Show file tree
Hide file tree
Showing 5 changed files with 175 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',
},
],
};
48 changes: 48 additions & 0 deletions features/bacom/redirects.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
module.exports = {
name: 'Redirects',
features: [
{
tcid: '0',
name: 'Bacom redirects for URLs without trailing slashes',
path: [
'/',
'/au',
'/uk',
'/de',
'/fr',
'/jp',
'/blog',
'/au/blog',
'/uk/blog',
'/de/blog',
'/fr/blog',
'/jp/blog',
'/kr/blog',
],
tags: '@redirects @bacom @bacomSmoke @regression',
},
{
tcid: '1',
name: 'Checking URLs that should get .html appended',
path: [
'/customer-success-stories/',
'/customer-success-stories',
'/resources/',
'/resources/main',
'/request-consultation/experience-cloud/',
'/products/genstudio',
'/products/experience-manager/sites/aem-sites',
'/products/real-time-customer-data-platform/rtcdp',
'/resources/holiday-shopping-report',
'/products/pricing',
'/products/marketo/marketo-measure',
'/au/products/real-time-customer-data-platform/rtcdp',
'/uk/resources/real-time-cdp',
'/de/request-consultation/experience-cloud',
'/fr/resources/',
'/jp/request-consultation/experience-cloud',
],
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
27 changes: 27 additions & 0 deletions tests/bacom/headers.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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}`;
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}`;
const response = await WebUtil.getRequest(testPage);

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

const [test1, test2] = 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}`;
const response = await WebUtil.getRequest(testPage);

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

test2.path.forEach((path) => {
test(
`Verifying URLs get .html appended, path: ${path} tags: ${test1.tags}`,
async () => {
const pathWithoutHtml = path.endsWith('.html') ? path.slice(0, -5) : path;
console.log(`pathWithoutHtml: ${pathWithoutHtml}`);
const testPage = `https://business.adobe.com${pathWithoutHtml}`;
const response = await WebUtil.getRequest(testPage);

expect(response.url().slice(-5)).toBe('.html');
expect(response.status()).toBe(200);
},
);
});
});

0 comments on commit 58b5b64

Please sign in to comment.