|
1 | | -import { test, expect, Locator } from '@playwright/test'; |
2 | | -import * as dotenv from 'dotenv'; |
3 | | -import { totalChartExamplesCount, chartsListWithErrors, testMatrix } from './test-matrix'; |
4 | | - |
5 | | -test.beforeEach(async ({ page }) => { |
6 | | - //Pass base URL as part of playwright command |
7 | | - //ex: npx cross-env BASE_URL='https://fluentchartstest-stage.azurewebsites.net/' npx playwright test |
8 | | - //await page.goto('http://localhost:3000/'); |
9 | | -}); |
| 1 | +/* eslint-disable no-loop-func */ |
| 2 | +import { test, expect } from '@playwright/test'; |
| 3 | +import { chartsListWithErrors, testMatrix } from './test-matrix'; |
10 | 4 |
|
11 | 5 | for (const testConfig of testMatrix) { |
12 | 6 | const theme = testConfig.theme; |
13 | 7 | const mode = testConfig.mode; |
14 | 8 | const locale = testConfig.locale; |
15 | | - //test.describe(`Declarative chart examples in ${theme} mode and ${mode} layout`, () => { |
16 | | - for (let index = testConfig.startExampleIndex; index <= testConfig.endExampleIndex; index++) { |
17 | | - const testLocaleName = locale ? `-${locale}` : ''; |
18 | | - test(`Declarative chart example ${index + 1}-${theme}-${mode} mode${testLocaleName}` , async ({ browser }) => { |
19 | | - const context = await browser.newContext({ locale: locale }); |
20 | | - const page = await context.newPage(); |
| 9 | + const testLocaleName = locale ? `-${locale}` : ''; |
| 10 | + test.describe('', () => { |
| 11 | + let context; |
| 12 | + let page; |
| 13 | + |
| 14 | + test.beforeAll(async ({ browser }) => { |
| 15 | + context = await browser.newContext({ locale }); |
| 16 | + page = await context.newPage(); |
21 | 17 | await page.goto(process.env.BASE_URL!); |
22 | | - const iframe = page.locator('#webpack-dev-server-client-overlay'); |
23 | | - if (await iframe.count() > 0) { |
24 | | - await iframe.evaluate((el) => el.remove()).catch(() => { |
25 | | - console.warn("Failed to remove overlay iframe."); |
26 | | - }); |
27 | | - } |
28 | | - await page.getByRole('combobox').first().click(); |
29 | | - const listbox = page.getByRole('listbox'); |
30 | | - await listbox.getByRole('option').locator(`text=${theme}`).click(); |
31 | | - const rtlSwitch = page.getByTestId('rtl_switch'); |
32 | | - const isCurrentlyRTL = await rtlSwitch.isChecked(); |
33 | | - if ((mode === 'RTL' && !isCurrentlyRTL) || (mode === 'LTR' && isCurrentlyRTL)) { |
34 | | - await rtlSwitch.click(); |
35 | | - } |
36 | | - const combobox = page.getByRole('combobox'); |
37 | | - await combobox.nth(1).click(); |
38 | | - const listitems = listbox.last().getByRole('option'); |
39 | | - if (!chartsListWithErrors.includes(index)) { |
40 | | - await listitems.nth(index).scrollIntoViewIfNeeded(); |
41 | | - await listitems.nth(index).click(); |
42 | | - const chart = page.getByTestId('chart-container-v9'); |
43 | | - await page.mouse.move(0, 0); // Move mouse to top-left corner |
44 | | - await expect(chart).toHaveScreenshot(); |
45 | | - await combobox.last().click(); |
46 | | - } else { |
47 | | - test.fail(); |
48 | | - } |
49 | 18 | }); |
50 | | - }; |
| 19 | + |
| 20 | + test.afterAll(async () => { |
| 21 | + await context?.close(); |
| 22 | + }); |
| 23 | + //test.describe(`Declarative chart examples in ${theme} mode and ${mode} layout`, () => { |
| 24 | + for (let index = testConfig.startExampleIndex; index <= testConfig.endExampleIndex; index++) { |
| 25 | + test(`Declarative chart example ${index + 1}-${theme}-${mode} mode${testLocaleName}` , async () => { |
| 26 | + const iframe = page.locator('#webpack-dev-server-client-overlay'); |
| 27 | + if (await iframe.count() > 0) { |
| 28 | + await iframe.evaluate((el) => el.remove()).catch(() => { |
| 29 | + console.warn("Failed to remove overlay iframe."); |
| 30 | + }); |
| 31 | + } |
| 32 | + await page.getByRole('combobox').first().click(); |
| 33 | + const listbox = page.getByRole('listbox'); |
| 34 | + await listbox.getByRole('option').locator(`text=${theme}`).click(); |
| 35 | + const rtlSwitch = page.getByTestId('rtl_switch'); |
| 36 | + const isCurrentlyRTL = await rtlSwitch.isChecked(); |
| 37 | + if ((mode === 'RTL' && !isCurrentlyRTL) || (mode === 'LTR' && isCurrentlyRTL)) { |
| 38 | + await rtlSwitch.click(); |
| 39 | + } |
| 40 | + const combobox = page.getByRole('combobox'); |
| 41 | + await combobox.nth(1).click(); |
| 42 | + const listitems = listbox.last().getByRole('option'); |
| 43 | + if (!chartsListWithErrors.includes(index)) { |
| 44 | + await listitems.nth(index).scrollIntoViewIfNeeded(); |
| 45 | + await listitems.nth(index).click(); |
| 46 | + const chart = page.getByTestId('chart-container-v9'); |
| 47 | + await page.mouse.move(0, 0); // Move mouse to top-left corner |
| 48 | + await expect(chart).toHaveScreenshot(); |
| 49 | + await combobox.last().click(); |
| 50 | + } else { |
| 51 | + test.fail(); |
| 52 | + } |
| 53 | + }); |
| 54 | + }; |
| 55 | + }); |
51 | 56 | } |
0 commit comments