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

Adding tests for headers and redirects #447

Merged
merged 2 commits into from
Oct 8, 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
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);
},
);
});
});
Loading