Skip to content

Commit 0048b95

Browse files
authored
ME-17952: test if video is playing on main page (#733)
* vp test: test if video is playing on main page * vp test: rename playVideo to clickPlay
1 parent 9707d4d commit 0048b95

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { Page } from '@playwright/test';
2+
3+
/**
4+
* Video component
5+
*/
6+
export class VideoComponent {
7+
private page: Page;
8+
private readonly videoSelector: string;
9+
10+
constructor(page: Page, videoSelector: string) {
11+
this.page = page;
12+
this.videoSelector = videoSelector;
13+
}
14+
15+
/**
16+
* Click the play button if necessary in case video is not autoplay
17+
*/
18+
public async clickPlay(): Promise<void> {
19+
const videoPlayButtonLocator = this.page.locator(`${this.videoSelector}/following-sibling::button[contains(@class, "vjs-big-play-button")]`);
20+
// Click the play button to start the video
21+
return videoPlayButtonLocator.click();
22+
}
23+
24+
/**
25+
* Checks if video element is paused
26+
*/
27+
public async isPaused(): Promise<boolean> {
28+
return this.page.evaluate((selector: string) => {
29+
console.log('Evaluating selector in browser context:', selector); // Logs selector in browser context
30+
const xpathResult = document.evaluate(selector, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
31+
const video = xpathResult.singleNodeValue as HTMLVideoElement | null;
32+
return video.paused;
33+
}, this.videoSelector);
34+
}
35+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { vpTest } from '../fixtures/vpTest';
2+
import { expect, test } from '@playwright/test';
3+
import { waitForPageToLoadWithTimeout } from '../src/helpers/waitForPageToLoadWithTimeout';
4+
5+
/**
6+
* Testing if video on main page is playing by checking that is pause return false.
7+
* The video in the main page is not configured as autoplay so first need to click on play button.
8+
*/
9+
vpTest(`Test if video on main page is playing`, async ({ page, vpExamples }) => {
10+
await test.step('Click on play button to play video', async () => {
11+
//making sure the page is loaded
12+
await waitForPageToLoadWithTimeout(page, 5000);
13+
return vpExamples.videoMainPage.clickPlay();
14+
});
15+
await test.step('Validating that the video is playing (in case isPause is false)', async () => {
16+
expect(await vpExamples.videoMainPage.isPaused()).toEqual(false);
17+
});
18+
});

test/e2e/src/pom/mainPage.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import { Page } from '@playwright/test';
2+
import { VideoComponent } from '../../components/videoComponent';
3+
const MAIN_PAGE_VIDEO_SELECTOR = '//*[@id="player_html5_api"]';
24

35
/**
46
* Video player examples main page object
57
*/
68
export class MainPage {
79
private page: Page;
10+
public videoMainPage: VideoComponent;
811

912
constructor(page: Page) {
1013
this.page = page;
14+
this.videoMainPage = new VideoComponent(page, MAIN_PAGE_VIDEO_SELECTOR);
1115
}
1216

1317
/**

0 commit comments

Comments
 (0)