Skip to content

Commit

Permalink
pass testInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
sunker committed Feb 22, 2024
1 parent 4e28537 commit 54cf814
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 26 deletions.
8 changes: 6 additions & 2 deletions packages/plugin-e2e/src/fixtures/annotationEditPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ type AnnotationEditPageFixture = TestFixture<
PluginFixture & PluginOptions & PlaywrightCombinedArgs
>;

const annotationEditPage: AnnotationEditPageFixture = async ({ page, selectors, grafanaVersion, request }, use) => {
const annotationPage = new AnnotationPage({ page, selectors, grafanaVersion, request });
const annotationEditPage: AnnotationEditPageFixture = async (
{ page, selectors, grafanaVersion, request },
use,
testInfo
) => {
const annotationPage = new AnnotationPage({ page, selectors, grafanaVersion, request, testInfo });
await annotationPage.goto();
const annotationEditPage = await annotationPage.clickAddNew();
await use(annotationEditPage);
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-e2e/src/fixtures/explorePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { PlaywrightCombinedArgs } from './types';

type ExplorePageFixture = TestFixture<ExplorePage, PluginFixture & PluginOptions & PlaywrightCombinedArgs>;

const explorePage: ExplorePageFixture = async ({ page, selectors, grafanaVersion, request }, use) => {
const explorePage = new ExplorePage({ page, selectors, grafanaVersion, request });
const explorePage: ExplorePageFixture = async ({ page, selectors, grafanaVersion, request }, use, testInfo) => {
const explorePage = new ExplorePage({ page, selectors, grafanaVersion, request, testInfo });
await explorePage.goto();
await use(explorePage);
};
Expand Down
8 changes: 6 additions & 2 deletions packages/plugin-e2e/src/fixtures/newDashboardPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ import { PlaywrightCombinedArgs } from './types';

type NewDashboardPageFixture = TestFixture<DashboardPage, PluginFixture & PluginOptions & PlaywrightCombinedArgs>;

const newDashboardPage: NewDashboardPageFixture = async ({ page, request, selectors, grafanaVersion }, use) => {
const newDashboardPage = new DashboardPage({ page, selectors, grafanaVersion, request });
const newDashboardPage: NewDashboardPageFixture = async (
{ page, request, selectors, grafanaVersion },
use,
testInfo
) => {
const newDashboardPage = new DashboardPage({ page, selectors, grafanaVersion, request, testInfo });
await newDashboardPage.goto();
await use(newDashboardPage);
};
Expand Down
8 changes: 6 additions & 2 deletions packages/plugin-e2e/src/fixtures/variableEditPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ import { PlaywrightCombinedArgs } from './types';

type VariableEditPageFixture = TestFixture<VariableEditPage, PluginFixture & PluginOptions & PlaywrightCombinedArgs>;

const variableEditPage: VariableEditPageFixture = async ({ page, selectors, grafanaVersion, request }, use) => {
const variablePage = new VariablePage({ page, selectors, grafanaVersion, request });
const variableEditPage: VariableEditPageFixture = async (
{ page, selectors, grafanaVersion, request },
use,
testInfo
) => {
const variablePage = new VariablePage({ page, selectors, grafanaVersion, request, testInfo });
await variablePage.goto();
const variableEditPage = await variablePage.clickAddNew();
await use(variableEditPage);
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-e2e/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Locator, PlaywrightTestArgs, Response } from '@playwright/test';
import { Locator, PlaywrightTestArgs, Response, TestInfo } from '@playwright/test';

import { E2ESelectors } from './e2e-selectors/types';

/**
* The context object passed to page object models
*/
export type PluginTestCtx = { grafanaVersion: string; selectors: E2ESelectors } & Pick<
export type PluginTestCtx = { grafanaVersion: string; selectors: E2ESelectors; testInfo: TestInfo } & Pick<
PlaywrightTestArgs,
'page' | 'request'
>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ test.describe('panel edit page', () => {
grafanaVersion,
request,
readProvisionedDashboard,
}) => {
}, testInfo) => {
const dashboard = await readProvisionedDashboard({ fileName: 'redshift.json' });
const panelEditPage = new PanelEditPage({ page, selectors, grafanaVersion, request }, { dashboard, id: '3' });
const panelEditPage = new PanelEditPage(
{ page, selectors, grafanaVersion, request, testInfo },
{ dashboard, id: '3' }
);
await panelEditPage.goto();
await panelEditPage.setVisualization('Table');
await expect(panelEditPage.panel.locator).toBeVisible();
Expand All @@ -24,9 +27,12 @@ test.describe('panel edit page', () => {
grafanaVersion,
request,
readProvisionedDashboard,
}) => {
}, testInfo) => {
const dashboard = await readProvisionedDashboard({ fileName: 'google-sheets.json' });
const panelEditPage = new PanelEditPage({ page, selectors, grafanaVersion, request }, { dashboard, id: '1' });
const panelEditPage = new PanelEditPage(
{ page, selectors, grafanaVersion, request, testInfo },
{ dashboard, id: '1' }
);
await panelEditPage.goto();
await panelEditPage.setVisualization('Time series');
await panelEditPage.toggleTableView();
Expand All @@ -36,18 +42,30 @@ test.describe('panel edit page', () => {
});

test.describe('dashboard page', () => {
test('getting panel by title', async ({ page, selectors, grafanaVersion, request, readProvisionedDashboard }) => {
test('getting panel by title', async ({
page,
selectors,
grafanaVersion,
request,
readProvisionedDashboard,
}, testInfo) => {
const dashboard = await readProvisionedDashboard({ fileName: 'redshift.json' });
const dashboardPage = new DashboardPage({ page, selectors, grafanaVersion, request }, dashboard);
const dashboardPage = new DashboardPage({ page, selectors, grafanaVersion, request, testInfo }, dashboard);
await dashboardPage.goto();
const panel = await dashboardPage.getPanelByTitle('Basic table example');
await expect(panel.fieldNames).toContainText(['time', 'temperature', 'humidity', 'environment']);
await expect(panel.data).toContainText(['25', '32', 'staging']);
});

test('getting panel by id', async ({ page, selectors, grafanaVersion, request, readProvisionedDashboard }) => {
test('getting panel by id', async ({
page,
selectors,
grafanaVersion,
request,
readProvisionedDashboard,
}, testInfo) => {
const dashboard = await readProvisionedDashboard({ fileName: 'redshift.json' });
const dashboardPage = new DashboardPage({ page, selectors, grafanaVersion, request }, dashboard);
const dashboardPage = new DashboardPage({ page, selectors, grafanaVersion, request, testInfo }, dashboard);
await dashboardPage.goto();
const panel = await dashboardPage.getPanelById('3');
await expect(panel.fieldNames).toContainText(['time', 'temperature', 'humidity', 'environment']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ test('custom variable editor query runner should return data when valid query fr
selectors,
grafanaVersion,
readProvisionedDashboard,
}) => {
}, testInfo) => {
const provision = await readProvisionedDashboard({ fileName: 'redshift.json' });
const variableEditPage = new VariableEditPage(
{ request, page, selectors, grafanaVersion },
{ request, page, selectors, grafanaVersion, testInfo },
{ dashboard: { uid: provision.uid }, id: '2' }
);
await variableEditPage.goto();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { test, expect, PanelEditPage } from '../../../../src';

test('variable interpolation', async ({ readProvisionedDashboard, request, page, selectors, grafanaVersion }) => {
test('variable interpolation', async ({
readProvisionedDashboard,
request,
page,
selectors,
grafanaVersion,
}, testInfo) => {
const dashboard = await readProvisionedDashboard({ fileName: 'redshift.json' });
const panelEditPage = new PanelEditPage(
{ request, page, selectors, grafanaVersion },
{ request, page, selectors, grafanaVersion, testInfo },
{
id: '5',
dashboard,
Expand All @@ -24,10 +30,10 @@ test('variable interpolation (navigate to panel from dashboard)', async ({
page,
selectors,
grafanaVersion,
}) => {
}, testInfo) => {
const dashboard = await readProvisionedDashboard({ fileName: 'redshift.json' });
const panelEditPage = new PanelEditPage(
{ request, page, selectors, grafanaVersion },
{ request, page, selectors, grafanaVersion, testInfo },
{
id: '5',
dashboard,
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-e2e/tests/as-admin-user/panel/panel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ test('open a clock panel in a provisioned dashboard and set time format to "12 h
request,
grafanaVersion,
readProvisionedDashboard,
}) => {
}, testInfo) => {
const dashboard = await readProvisionedDashboard({ fileName: 'clock-panel.json' });
const args = { dashboard: { uid: dashboard.uid }, id: '5' };
const panelEditPage = await new PanelEditPage({ page, selectors, grafanaVersion, request }, args);
const panelEditPage = await new PanelEditPage({ page, selectors, grafanaVersion, request, testInfo }, args);
await panelEditPage.goto();
await expect(panelEditPage.getVisualizationName()).toHaveText('Clock');
await panelEditPage.collapseSection('Clock');
Expand Down

0 comments on commit 54cf814

Please sign in to comment.