Skip to content

Commit

Permalink
Add video test script to Modal feature test suite (#199)
Browse files Browse the repository at this point in the history
* add video test to modal and update marquee console fn

* testing token

* update the console log

---------

Co-authored-by: nateekar <[email protected]>
  • Loading branch information
skumar09 and nateekar authored Nov 2, 2023
1 parent b8dd0e2 commit 4a4590a
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 80 deletions.
16 changes: 15 additions & 1 deletion features/milo/modal.block.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,27 @@ module.exports = {
path: '/drafts/nala/blocks/modal/modal-media',
data: {
modalId: 'modal-media',
detailText: 'DETAIL M 12/15',
detailText: 'Detail M 12/15',
fragment: 'media',
contentType: 'media',
h2Text: 'Heading M 24/30 Media',
bodyText: 'Body S 16/24 Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed',
},
tags: '@modal @smoke @regression @milo',
},
{
tcid: '2',
name: '@Modal Autoplay Video',
path: '/drafts/nala/blocks/modal/modal-autoplay-video',
data: {
modalId: 'modal-video-autoplay',
detailText: 'Detail M 12/15',
fragment: 'media',
contentType: 'media',
h2Text: 'Heading M 24/30 Media',
bodyText: 'Body S 16/24 Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed',
},
tags: '@modal @smoke @regression @milo',
},
],
};
111 changes: 38 additions & 73 deletions selectors/milo/modal.block.page.js
Original file line number Diff line number Diff line change
@@ -1,99 +1,64 @@
import { expect } from '@playwright/test';
import { WebUtil } from '../../libs/webutil.js';

export default class Modal {
constructor(page) {
this.page = page;
// modal locators
this.dialog = this.page.locator('.dialog-modal');
this.modal = this.page.locator('.dialog-modal');
this.fragment = this.modal.locator('.fragment');
this.headingXL = this.page.locator('.heading-xl');
this.bodyM = this.page.locator('.body-m').nth(2);
this.modalCloseButton = this.modal.locator('.dialog-close');
this.marqueeLight = this.page.locator('.marquee.light');
this.dialogCloseButton = this.modal.locator('.dialog-close');
this.marqueeLight = this.dialog.locator('.marquee.light');
this.modelSelector = '.dialog-modal';

// text block
this.text = this.modal.locator('.text');
this.textHeading = this.text.locator('h2');
this.textBodyM = this.text.locator('.body-m');
this.textBlock = this.modal.locator('.text');
this.textBlockHeading = this.textBlock.locator('h2');
this.textBlockBodyM = this.textBlock.locator('.body-m');

// media block
this.media = this.modal.locator('.media');
this.detailM = this.media.locator('.detail-m');
this.textHeadingMedia = this.media.locator('h2');
this.textBodySMedia = this.media.locator('.body-s').first();
this.mediaBlock = this.modal.locator('.media');
this.mediaBlockdetailM = this.mediaBlock.locator('.detail-m');
this.mediaBlockTextHeading = this.mediaBlock.locator('h2');
this.mediaBlockTextBodyS = this.mediaBlock.locator('.body-s').first();

// video block
this.video = this.modal.locator('video');

// modal contents attributes
this.attProperties = {
this.attributes = {
'modal-link': {
class: 'modal link-block ',
'class': 'modal link-block ',
},
'video.inline': {
'playsinline': '',
'autoplay': '',
'loop': '',
'muted': ''
},
};
}

/**
* Verifies that a modal with the specified ID can be opened and closed.
* @param {string} modalData - Modal data required to verify modal.
* @returns {Promise<boolean>} - A Promise that resolves to true if the verification
* is successful, or false if an error occurs.
*/
async verifyModal(modalData) {
* Gets the modal link based on the modal id.
* Waits for the link to be visible before returning the locator.
* @param {Object} data - The data object containing modalId.
* @param {number} [timeout=3000] - Optional timeout for waiting.
* @returns {Promise<Locator>} - The locator for the modal link.
* @throws Will throw an error if the link is not found within the timeout.
*/
async getModalLink(modalId, timeout = 1000) {
if (!modalId) {
throw new Error('Invalid data, "modalId" property is required.');
}
const selector = `a[href="#${modalId}"]`;
const modalLink = this.page.locator(selector);
try {
// verify modal link attributes and then click
const modalLink = await this.page.locator(`a[href="#${modalData.modalId}"]`);
await expect(await modalLink).toBeVisible();
expect(await WebUtil.verifyAttributes(
modalLink,
this.attProperties['modal-link'],
)).toBeTruthy();

await modalLink.click();

// validate modal content
switch (modalData.fragment) {
case 'text':
await expect(await this.modal).toContainText(modalData.bodyText);
await expect(await this.modalCloseButton).toBeVisible();
expect(await WebUtil.isModalInViewport(
this.page,
this.modalSelector,
)).toBeTruthy();

// verify modal content (text fragment)
await expect(await this.text).toBeVisible();
await expect(await this.textHeading).toContainText(modalData.h2Text);
await expect(await this.textBodyM).toContainText(modalData.bodyText);

// close the modal
await this.modalCloseButton.click();

return true;

case 'media':
await expect(await this.modal).toContainText(modalData.bodyText);
await expect(await this.modalCloseButton).toBeVisible();
expect(await WebUtil.isModalInViewport(
this.page,
this.modalSelector,
)).toBeTruthy();

// verify modal content (media fragment)
await expect(await this.media).toBeVisible();
await expect(await this.textHeadingMedia).toContainText(modalData.h2Text);
await expect(await this.textBodySMedia).toContainText(modalData.bodyText);

// close the modal using escape key press.
await this.page.keyboard.press('Escape');

return true;

default:
throw new Error(`Unsupported Text type: ${this.textType}`);
}
await modalLink.waitFor({ state: 'visible', timeout });
return modalLink;
} catch (error) {
console.error(`Error verifying modal: ${error}`);
return false;
throw new Error(`The modal link with selector "${selector}" could not be found within ${timeout}ms.`);
}
}
}
2 changes: 1 addition & 1 deletion tests/milo/marquee.block.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test.describe('Milo Marquee Block test suite', () => {
webUtil = new WebUtil(page);
marquee = new MarqueeBlock(page);

page.on('pageerror', (exception) => {
page.on('console', (exception) => {
if (exception.type() === 'error') {
consoleErrors.push(exception.text());
}
Expand Down
82 changes: 77 additions & 5 deletions tests/milo/modal.block.test.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,51 @@
import { expect, test } from '@playwright/test';
import { WebUtil } from '../../libs/webutil.js';
import { features } from '../../features/milo/modal.block.spec.js';
import ModalBlock from '../../selectors/milo/modal.block.page.js';

let modal;
let webUtil;

test.describe('Milo Modal feature test suite', () => {
test.beforeEach(async ({ page }) => {
modal = new ModalBlock(page);
webUtil = new WebUtil(page);
});

// Test 0 : Modal with Text block
test(`${features[0].name},${features[0].tags}`, async ({ page, baseURL }) => {
console.info(`[Test Page]: ${baseURL}${features[0].path}`);

await test.step('step-1: Go to Modal feature test page', async () => {
await page.goto(`${baseURL}${features[0].path}`);
await page.waitForLoadState('domcontentloaded');
await expect(page).toHaveURL(`${baseURL}${features[0].path}`);
await expect(page).toHaveURL(`${baseURL}${features[0].path}`);
});

await test.step('step-2: Verify Modal text fragment content/specs', async () => {
const modalData = features[0].data;
expect(await modal.verifyModal(modalData)).toBeTruthy();
const data = features[0].data;
const modalLink = await modal.getModalLink(data.modalId);
await expect(await modalLink).toBeVisible();
await expect(await modalLink).toHaveAttribute('class', modal.attributes['modal-link']['class']);

//click the modal link
await modalLink.click();
await expect(await modal.dialog).toBeVisible();

await expect(await modal.textBlock).toBeVisible();
await expect(await modal.textBlockHeading).toContainText(data.h2Text);
await expect(await modal.textBlockBodyM).toContainText(data.bodyText);

expect(await WebUtil.isModalInViewport(modal.page, modal.modalSelector)).toBeTruthy();

// click the modal close button
await expect(await modal.dialogCloseButton).toBeVisible();
await modal.dialogCloseButton.click();

});
});

// Test 1 : Modal with Media block
test(`${features[1].name}, ${features[1].tags}`, async ({ page, baseURL }) => {
console.info(`[Test Page]: ${baseURL}${features[1].path}`);

Expand All @@ -34,8 +56,58 @@ test.describe('Milo Modal feature test suite', () => {
});

await test.step('step-2: Verify Modal media fragement content/specs', async () => {
const modalData = features[1].data;
expect(await modal.verifyModal(modalData)).toBeTruthy();
const data = features[1].data;
//expect(await modal.verifyModal(modalData)).toBeTruthy();

const modalLink = await modal.getModalLink(data.modalId);
await expect(await modalLink).toBeVisible();
await expect(await modalLink).toHaveAttribute('class', modal.attributes['modal-link']['class']);

//click the modal link
await modalLink.click();
await expect(await modal.dialog).toBeVisible();

await expect(await modal.mediaBlock).toBeVisible();
await expect(await modal.mediaBlockdetailM).toContainText(data.detailText);
await expect(await modal.mediaBlockTextHeading).toContainText(data.h2Text);
await expect(await modal.mediaBlockTextBodyS).toContainText(data.bodyText);

expect(await WebUtil.isModalInViewport(modal.page, modal.modalSelector)).toBeTruthy();

// close the modal using escape key press
await expect(await modal.dialogCloseButton).toBeVisible();
await modal.page.keyboard.press('Escape');
});
});

// Test 2 : Modal with Video Autoplay
test(`${features[2].name}, ${features[2].tags}`, async ({ page, baseURL }) => {
console.info(`[Test Page]: ${baseURL}${features[2].path}`);

await test.step('step-1: Go to Modal feature test page', async () => {
await page.goto(`${baseURL}${features[2].path}`);
await page.waitForLoadState('domcontentloaded');
await expect(page).toHaveURL(`${baseURL}${features[2].path}`);
});

await test.step('step-2: Verify Modal media fragement content/specs', async () => {
const data = features[2].data;

const modalLink = await modal.getModalLink(data.modalId);
await expect(await modalLink).toBeVisible();
await expect(await modalLink).toHaveAttribute('class', modal.attributes['modal-link']['class']);

//click the modal link and verify video autoplay
await modalLink.click();
await expect(await modal.dialog).toBeVisible();
expect(await WebUtil.isModalInViewport(modal.page, modal.modalSelector)).toBeTruthy();

await expect(await modal.video).toBeVisible();
expect(await webUtil.verifyAttributes_(await modal.video, modal.attributes['video.inline'])).toBeTruthy();

// close the modal using escape key press
await expect(await modal.dialogCloseButton).toBeVisible();
await modal.page.keyboard.press('Escape');
});
});
});

0 comments on commit 4a4590a

Please sign in to comment.