-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
me-17957: test if video on autoplay on scroll page is playing (#763)
* vp test: test if video on autoplay on scroll page is playing * vp test: remove waitForTimeout and use expect toPass * vp test: remove waitForTimeout and use expect toPass * vp test: added BaseComponent and modified accordingly
- Loading branch information
Showing
5 changed files
with
109 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { Locator, Page } from '@playwright/test'; | ||
|
||
/** | ||
* Base component constructor interface | ||
* | ||
* selector is optional in order to allow default selector usage. | ||
* For example: | ||
* | ||
* constructor(dataProps: IBaseComponent) { | ||
* const baseComponentProps: IBaseComponent = dataProps; | ||
* baseComponentProps.selector = dataProps?.selector ?? "//*<SOME DEFAULT SELECTOR>"; | ||
* super(baseComponentProps); | ||
* ... | ||
* } | ||
*/ | ||
export interface IBaseComponent { | ||
page: Page; | ||
selector: string; | ||
parentSelector?: string; | ||
iframeSelector?: string; | ||
} | ||
/** | ||
* Base class for an POM component class | ||
* such as buttons, dropList, etc | ||
*/ | ||
export class BaseComponent { | ||
get locator(): Locator { | ||
return this._locator; | ||
} | ||
|
||
get props(): IBaseComponent { | ||
return this._props; | ||
} | ||
|
||
private readonly _locator: Locator; | ||
private readonly _props: IBaseComponent; | ||
|
||
constructor(basePageProps: IBaseComponent) { | ||
if (!basePageProps.selector) { | ||
throw Error(`Missing selector in basePageProps`); | ||
} | ||
const elementSelector: string = basePageProps.parentSelector ? `${basePageProps.parentSelector}${basePageProps.selector}` : basePageProps.selector; | ||
|
||
this._props = basePageProps; | ||
this._locator = basePageProps.iframeSelector | ||
? basePageProps.page.frameLocator(basePageProps.iframeSelector).locator(elementSelector) | ||
: basePageProps.page.locator(elementSelector); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { vpTest } from '../fixtures/vpTest'; | ||
import { expect, test } from '@playwright/test'; | ||
import { waitForPageToLoadWithTimeout } from '../src/helpers/waitForPageToLoadWithTimeout'; | ||
import { getLinkByName } from '../testData/pageLinksData'; | ||
import { ExampleLinkName } from '../testData/ExampleLinkNames'; | ||
|
||
// Link to autoplay on scroll page | ||
const link = getLinkByName(ExampleLinkName.AutoplayOnScroll); | ||
/** | ||
* Testing if video on autoplay on scroll page is playing. | ||
* First making sure that video is not playing before scrolling. | ||
* Then, scroll until video element is visible and make sure video is playing by checking that is pause return false. | ||
*/ | ||
vpTest(`Test if video on autoplay on scroll page is playing as expected`, async ({ page, pomPages }) => { | ||
await test.step('Navigate to autoplay on scroll page by clicking on link', async () => { | ||
await pomPages.mainPage.clickLinkByName(link.name); | ||
await waitForPageToLoadWithTimeout(page, 5000); | ||
}); | ||
await test.step('Validating that the video is not playing before scrolling (in case isPause is true)', async () => { | ||
expect(await pomPages.autoplayOnScrollPage.autoplayOnScrollVideoComponent.isPaused()).toEqual(true); | ||
}); | ||
await test.step('Scroll until the video element is visible', async () => { | ||
await pomPages.autoplayOnScrollPage.autoplayOnScrollVideoComponent.locator.scrollIntoViewIfNeeded(); | ||
}); | ||
await test.step('Validating that the video is auto playing after scrolling (in case isPause is false)', async () => { | ||
await expect(async () => { | ||
expect(await pomPages.autoplayOnScrollPage.autoplayOnScrollVideoComponent.isPaused()).toEqual(false); | ||
}).toPass({ intervals: [500], timeout: 3000 }); | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Page } from '@playwright/test'; | ||
import { VideoComponent } from '../../components/videoComponent'; | ||
import { BasePage } from './BasePage'; | ||
const AUTOPLAY_ON_SCROLL_PAGE_VIDEO_SELECTOR = '//*[@id="player_html5_api"]'; | ||
|
||
/** | ||
* Video player examples autoplay on scroll page object | ||
*/ | ||
export class AutoplayOnScrollPage extends BasePage { | ||
public autoplayOnScrollVideoComponent: VideoComponent; | ||
|
||
constructor(page: Page) { | ||
super(page); | ||
this.autoplayOnScrollVideoComponent = new VideoComponent(page, AUTOPLAY_ON_SCROLL_PAGE_VIDEO_SELECTOR); | ||
} | ||
} |