Skip to content

Commit f998715

Browse files
authored
fix flaky tests (#877)
* fix flaky tests * update * update * update * update * update * update * update * update
1 parent 5b7c57a commit f998715

8 files changed

Lines changed: 36 additions & 17 deletions

File tree

.github/workflows/e2e_pr.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Video Player PR
1+
name: Playwright Tests
22

33
on:
44
workflow_dispatch:
@@ -33,6 +33,9 @@ jobs:
3333
- name: Set Deploy Preview URL
3434
run: echo "PREVIEW_URL=https://deploy-preview-${{ env.PR_NUMBER }}--cld-vp-esm-pages.netlify.app" >> $GITHUB_ENV
3535

36+
- name: Install Playwright Browsers
37+
run: npx playwright install --with-deps
38+
3639
- name: E2E tests
3740
run: npm run test:e2e
3841
env:

test/e2e/components/videoComponent.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,19 @@ export class VideoComponent extends BaseComponent {
2323
*/
2424
public async isPaused(): Promise<boolean> {
2525
return this.props.page.evaluate((selector: string) => {
26-
console.log('Evaluating selector in browser context:', selector); // Logs selector in browser context
27-
const xpathResult = document.evaluate(selector, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
28-
const video = xpathResult.singleNodeValue as HTMLVideoElement | null;
29-
return video.paused;
26+
const video = document.evaluate(
27+
selector,
28+
document,
29+
null,
30+
XPathResult.FIRST_ORDERED_NODE_TYPE,
31+
null
32+
).singleNodeValue as HTMLVideoElement | null;
33+
34+
if (!video) {
35+
throw new Error(`Video element with id "${selector}" not found`);
36+
}
37+
return video.paused;
38+
3039
}, this.props.selector);
3140
}
3241

@@ -37,9 +46,10 @@ export class VideoComponent extends BaseComponent {
3746
* timeout - Optional. The maximum time (in milliseconds) to wait for the validation. Defaults to 3000ms if not provided.
3847
* Pass `true` if the video is expected to be playing, or `false` if it is expected to be paused.
3948
*/
40-
public async validateVideoIsPlaying(expectedPlaying: boolean, timeout: number = 3000): Promise<void> {
49+
public async validateVideoIsPlaying(expectedPlaying: boolean, timeout: number = 6000): Promise<void> {
4150
await expect(async () => {
42-
expect(await this.isPaused()).not.toEqual(expectedPlaying);
51+
const isPaused = await this.isPaused();
52+
expect(isPaused).not.toEqual(expectedPlaying);
4353
}).toPass({ intervals: [500], timeout });
4454
}
4555
}

test/e2e/playwright.config.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { defineConfig, devices } from '@playwright/test';
44
* See https://playwright.dev/docs/test-configuration.
55
*/
66
export default defineConfig({
7-
timeout: 150000,
7+
timeout: 60000,
88
/* Run tests in files in parallel */
99
fullyParallel: true,
1010
/* Fail the build on CI if you accidentally left test.only in the source code. */
@@ -13,6 +13,8 @@ export default defineConfig({
1313
retries: process.env.CI ? 2 : 0,
1414
/* Opt out of parallel tests on CI. */
1515
workers: 5,
16+
/* Max failures to continue the test run */
17+
maxFailures: 15,
1618
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
1719
reporter: [['list'], ['html', { open: 'never' }]],
1820
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
@@ -24,6 +26,7 @@ export default defineConfig({
2426
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
2527
trace: 'retain-on-failure',
2628
screenshot: 'only-on-failure',
29+
video: 'retain-on-failure',
2730
},
2831

2932
/* Configure projects for major browsers */

test/e2e/specs/NonESM/linksConsolErros.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ for (const link of LINKS) {
1414
await pomPages.mainPage.clickLinkByName(link.name);
1515
await waitForPageToLoadWithTimeout(page, 5000);
1616
expect(page.url()).toContain(link.endpoint);
17-
handleCommonBrowsersErrors(link.name, consoleErrors);
17+
await expect(async () => {
18+
handleCommonBrowsersErrors(link.name, consoleErrors);
19+
}).toPass({intervals: [1000]});
1820
});
1921
}
2022

test/e2e/specs/NonESM/visualSearchPage.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ vpTest(`Test if video on visual search page is playing as expected`, async ({ pa
1818
await pomPages.visualSearchPage.visualSearchPlaylistVideoComponent.locator.scrollIntoViewIfNeeded();
1919
});
2020

21-
await test.step('Click play button on visual search video', async () => {
21+
await test.step('Click play button on visual search plugin video', async () => {
2222
await pomPages.visualSearchPage.visualSearchVideoComponent.clickPlay();
2323
});
2424

25-
await test.step('Validating that visual search video is playing', async () => {
25+
await test.step('Validating that visual search plugin video is playing', async () => {
2626
await pomPages.visualSearchPage.visualSearchVideoComponent.validateVideoIsPlaying(true);
2727
});
2828

29-
await test.step('Click play button on playlist video', async () => {
29+
await test.step('Click play button on mixed content video', async () => {
3030
await pomPages.visualSearchPage.visualSearchPlaylistVideoComponent.clickPlay();
3131
});
3232

33-
await test.step('Validating that visual search playlist video is playing', async () => {
33+
await test.step('Validating that visual mixed content video is playing', async () => {
3434
await pomPages.visualSearchPage.visualSearchPlaylistVideoComponent.validateVideoIsPlaying(true);
3535
});
3636
});

test/e2e/specs/Setup/global.setup.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import { ESM_URL } from '../../testData/esmUrl';
77
/**
88
* Ensures the esm deploy is ready by checking the 'Adaptive Streaming' link is visible at ESM_URL.
99
*/
10-
test('global setup', async ({ page }) => {
10+
test('Global Setup', async ({ page }) => {
11+
test.slow();
1112
if (ESM_URL) {
1213
const link: ExampleLinkType = {
1314
name: ExampleLinkName.AdaptiveStreaming,

test/e2e/specs/commonSpecs/vastAndVpaidPage.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ export async function testVastAndVpaidPageVideoIsPlaying(page: Page, pomPages: P
1313
});
1414
//Sending timeout of 12 seconds to wait until the ad finishes (10 sec) and the video will start
1515
await test.step('Validating that single video with ads is playing', async () => {
16-
await pomPages.vastAndVpaidPage.singleVideoWithAdsVideoComponent.validateVideoIsPlaying(true, 12000);
16+
await pomPages.vastAndVpaidPage.singleVideoWithAdsVideoComponent.validateVideoIsPlaying(true, 20000);
1717
});
1818
await test.step('Validating that playlist with ads video is playing', async () => {
19-
await pomPages.vastAndVpaidPage.playlistWithAdsVideoComponent.validateVideoIsPlaying(true, 12000);
19+
await pomPages.vastAndVpaidPage.playlistWithAdsVideoComponent.validateVideoIsPlaying(true, 20000);
2020
});
2121
}

test/e2e/specs/commonSpecs/vr360VideosPageVideoPlaying.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ export async function testVr360PageVideoIsPlaying(page: Page, pomPages: PageMana
1212
return pomPages.vr360VideosPage.vr360VideoComponent.clickPlay();
1313
});
1414
await test.step('Validating that 360 video is playing', async () => {
15-
await pomPages.vr360VideosPage.vr360VideoComponent.validateVideoIsPlaying(true, 6000);
15+
await pomPages.vr360VideosPage.vr360VideoComponent.validateVideoIsPlaying(true, 12000);
1616
});
1717
}

0 commit comments

Comments
 (0)