-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
base E2E test suite using playwright
- Loading branch information
1 parent
381cdee
commit 8a9417e
Showing
10 changed files
with
302 additions
and
29 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,73 @@ | ||
name: E2E Tests | ||
on: | ||
pull_request: | ||
path-ignore: | ||
- 'docs/**' | ||
branches: | ||
- main | ||
push: | ||
path-ignore: | ||
- 'docs/**' | ||
branches: | ||
- main | ||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} | ||
cancel-in-progress: true | ||
jobs: | ||
test: | ||
timeout-minutes: 60 | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Setup Go environment | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.21.6' | ||
- name: Test backend | ||
uses: magefile/mage-action@v2 | ||
with: | ||
version: latest | ||
args: coverage | ||
- name: Build backend | ||
uses: magefile/mage-action@v2 | ||
with: | ||
version: latest | ||
args: buildAll | ||
- name: Setup Node | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 20 | ||
- name: Install dependencies | ||
run: npm install -g yarn && yarn install --frozen-lockfile; | ||
- name: Spellcheck | ||
run: | | ||
yarn spellcheck; | ||
- name: Build Frontend | ||
run: | | ||
yarn build; | ||
- name: Start the docker container for E2E | ||
run: | | ||
docker-compose pull | ||
docker-compose up -d | ||
- name: Wait for grafana to start | ||
uses: nev7n/wait_for_response@v1 | ||
with: | ||
url: 'http://localhost:3000/' | ||
responseCode: 200 | ||
timeout: 20000 | ||
interval: 500 | ||
- name: Install Playwright Browsers | ||
run: yarn playwright install --with-deps | ||
- name: Run E2E tests | ||
run: yarn test:e2e | ||
- name: Run E2E artifacts | ||
uses: actions/upload-artifact@v3 | ||
if: always() | ||
with: | ||
name: playwright-report | ||
path: playwright-report/ | ||
retention-days: 30 | ||
- name: Stop the docker container | ||
if: always() | ||
run: docker-compose down |
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 |
---|---|---|
@@ -1 +1 @@ | ||
18 | ||
20 |
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,5 @@ | ||
import { test as setup } from '@grafana/plugin-e2e'; | ||
|
||
setup('authenticate', async ({ login }) => { | ||
await login(); | ||
}); |
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,80 @@ | ||
import { test, expect } from '@grafana/plugin-e2e'; | ||
import { runQuery } from './query'; | ||
|
||
test('test type:json source:url', async ({ page, panelEditPage }) => { | ||
await panelEditPage.datasource.set('Infinity'); | ||
await panelEditPage.setVisualization('Table'); | ||
const queryEditorRow = await panelEditPage.getQueryEditorRow('A'); | ||
|
||
let frames = await runQuery(page, panelEditPage, queryEditorRow, {}); | ||
expect(frames.results['A'].frames[0].schema.name).toBe('A'); | ||
expect(frames.results['A'].frames[0].schema.meta.custom.query.parser).toBe(''); // Ensure the parser type passed correctly | ||
expect(frames.results['A'].frames[0].schema.meta.custom.data[0].country).toBe('USA'); // Ensure schema meta have actual data to be passed to the frontend | ||
await expect(page.getByText('Patricia Lebsack')).toBeVisible(); // Ensure actual data rendered | ||
|
||
frames = await runQuery(page, panelEditPage, queryEditorRow, { parser: 'backend' }); | ||
expect(frames.results['A'].frames[0].schema.name).toBe('A'); | ||
expect(frames.results['A'].frames[0].schema.meta.custom.query.parser).toBe('backend'); // Ensure the parser type passed correctly | ||
expect(frames.results['A'].frames[0].data.values[1][0]).toBe('USA'); // Ensure actual data frames being returned | ||
await expect(page.getByText('Patricia Lebsack')).toBeVisible(); // Ensure actual data rendered | ||
|
||
frames = await runQuery(page, panelEditPage, queryEditorRow, { parser: 'uql' }); | ||
expect(frames.results['A'].frames[0].schema.name).toBe('A'); | ||
expect(frames.results['A'].frames[0].schema.meta.custom.query.parser).toBe('uql'); // Ensure the parser type passed correctly | ||
expect(frames.results['A'].frames[0].schema.meta.custom.data[0].country).toBe('USA'); // Ensure schema meta have actual data to be passed to the frontend | ||
await expect(page.getByText('Patricia Lebsack')).toBeVisible(); // Ensure actual data rendered | ||
|
||
frames = await runQuery(page, panelEditPage, queryEditorRow, { parser: 'groq' }); | ||
expect(frames.results['A'].frames[0].schema.name).toBe('A'); | ||
expect(frames.results['A'].frames[0].schema.meta.custom.query.parser).toBe('groq'); // Ensure the parser type passed correctly | ||
expect(frames.results['A'].frames[0].schema.meta.custom.data[0].country).toBe('USA'); // Ensure schema meta have actual data to be passed to the frontend | ||
await expect(page.getByText('Patricia Lebsack')).toBeVisible(); // Ensure actual data rendered | ||
}); | ||
|
||
test('test type:csv source:url', async ({ page, panelEditPage }) => { | ||
await panelEditPage.datasource.set('Infinity'); | ||
await panelEditPage.setVisualization('Table'); | ||
const queryEditorRow = await panelEditPage.getQueryEditorRow('A'); | ||
|
||
let frames = await runQuery(page, panelEditPage, queryEditorRow, { type: 'csv', url: 'https://github.com/grafana/grafana-infinity-datasource/blob/main/testdata/users.csv' }); | ||
expect(frames.results['A'].frames[0].schema.name).toBe('A'); | ||
expect(frames.results['A'].frames[0].schema.meta.custom.query.parser).toBe(''); // Ensure the parser type passed correctly | ||
expect((frames.results['A'].frames[0].schema.meta.custom.data || '').startsWith('name,age,country,occupation,salary')).toBeTruthy(); // Ensure schema meta have actual data to be passed to the frontend | ||
await expect(page.getByText('Patricia Lebsack')).toBeVisible(); // Ensure actual data rendered | ||
|
||
frames = await runQuery(page, panelEditPage, queryEditorRow, { type: 'csv', url: 'https://github.com/grafana/grafana-infinity-datasource/blob/main/testdata/users.csv', parser: 'backend' }); | ||
expect(frames.results['A'].frames[0].schema.name).toBe('A'); | ||
expect(frames.results['A'].frames[0].schema.meta.custom.query.parser).toBe('backend'); // Ensure the parser type passed correctly | ||
expect(frames.results['A'].frames[0].data.values[1][0]).toBe('USA'); // Ensure actual data frames being returned | ||
await expect(page.getByText('Patricia Lebsack')).toBeVisible(); // Ensure actual data rendered | ||
|
||
frames = await runQuery(page, panelEditPage, queryEditorRow, { type: 'csv', url: 'https://github.com/grafana/grafana-infinity-datasource/blob/main/testdata/users.csv', parser: 'uql' }); | ||
expect(frames.results['A'].frames[0].schema.name).toBe('A'); | ||
expect(frames.results['A'].frames[0].schema.meta.custom.query.parser).toBe('uql'); // Ensure the parser type passed correctly | ||
expect((frames.results['A'].frames[0].schema.meta.custom.data || '').startsWith('name,age,country,occupation,salary')).toBeTruthy(); // Ensure schema meta have actual data to be passed to the frontend | ||
await expect(page.getByText('Patricia Lebsack')).toBeVisible(); // Ensure actual data rendered | ||
}); | ||
|
||
test('test type:xml source:url', async ({ page, panelEditPage }) => { | ||
await panelEditPage.datasource.set('Infinity'); | ||
await panelEditPage.setVisualization('Table'); | ||
const queryEditorRow = await panelEditPage.getQueryEditorRow('A'); | ||
|
||
let frames = await runQuery(page, panelEditPage, queryEditorRow, { type: 'xml', url: 'https://github.com/grafana/grafana-infinity-datasource/blob/main/testdata/users.xml' }); | ||
expect(frames.results['A'].frames[0].schema.name).toBe('A'); | ||
expect(frames.results['A'].frames[0].schema.meta.custom.query.parser).toBe(''); // Ensure the parser type passed correctly | ||
expect((frames.results['A'].frames[0].schema.meta.custom.data || '').includes('<name>Leanne Graham</name')).toBeTruthy(); // Ensure schema meta have actual data to be passed to the frontend | ||
// await expect(page.getByText('Patricia Lebsack')).toBeVisible(); // Ensure actual data rendered | ||
|
||
frames = await runQuery(page, panelEditPage, queryEditorRow, { type: 'xml', url: 'https://github.com/grafana/grafana-infinity-datasource/blob/main/testdata/users.xml', parser: 'backend' }); | ||
expect(frames.results['A'].frames[0].schema.name).toBe('A'); | ||
expect(frames.results['A'].frames[0].schema.meta.custom.query.parser).toBe('backend'); // Ensure the parser type passed correctly | ||
expect(frames.results['A'].frames[0].data.values[0][0].includes('Leanne Graham')).toBeTruthy(); // Ensure actual data frames being returned | ||
// await expect(page.getByText('Patricia Lebsack')).toBeVisible(); // Ensure actual data rendered | ||
|
||
frames = await runQuery(page, panelEditPage, queryEditorRow, { type: 'xml', url: 'https://github.com/grafana/grafana-infinity-datasource/blob/main/testdata/users.xml', parser: 'uql' }); | ||
expect(frames.results['A'].frames[0].schema.name).toBe('A'); | ||
expect(frames.results['A'].frames[0].schema.meta.custom.query.parser).toBe('uql'); // Ensure the parser type passed correctly | ||
expect((frames.results['A'].frames[0].schema.meta.custom.data || '').includes('<name>Leanne Graham</name')).toBeTruthy(); // Ensure schema meta have actual data to be passed to the frontend | ||
// await expect(page.getByText('Patricia Lebsack')).toBeVisible(); // Ensure actual data rendered | ||
}); |
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,33 @@ | ||
import { Page, Locator } from '@playwright/test'; | ||
import { PanelEditPage, expect } from '@grafana/plugin-e2e'; | ||
|
||
export const runQuery = async (page: Page, panelEditPage: PanelEditPage, locator: Locator, query: Record<string, any>) => { | ||
if (query.type) { | ||
const typeDropdown = await locator.locator(`[data-testid='infinity-query-field-wrapper-type'] input`); | ||
await typeDropdown.clear(); | ||
await typeDropdown.fill(query.type || 'json'); | ||
await page.keyboard.press('Enter'); | ||
} | ||
if (query.source) { | ||
const sourceDropdown = await locator.locator(`[data-testid='infinity-query-field-wrapper-source'] input`); | ||
await sourceDropdown.clear(); | ||
await sourceDropdown.fill(query.source || 'url'); | ||
await page.keyboard.press('Enter'); | ||
} | ||
if (query.parser) { | ||
const parserDropdown = await locator.locator(`[data-testid='infinity-query-field-wrapper-parser'] input`); | ||
await parserDropdown.clear(); | ||
await parserDropdown.fill(query.parser || 'simple'); | ||
await page.keyboard.press('Enter'); | ||
} | ||
if (query.url) { | ||
const urlTextBox = await locator.locator(`[data-testid='infinity-query-field-wrapper-url'] input`); | ||
await urlTextBox.clear(); | ||
await urlTextBox.fill(query.url || 'https://github.com/grafana/grafana-infinity-datasource/blob/main/testdata/users.json'); | ||
await page.keyboard.press('Enter'); | ||
} | ||
const res = await panelEditPage.refreshPanel(); | ||
await expect(panelEditPage).not.toHavePanelError(); | ||
const frames = await res.json(); | ||
return frames; | ||
}; |
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,25 @@ | ||
import { defineConfig, devices } from '@playwright/test'; | ||
|
||
export default defineConfig({ | ||
testDir: './e2e', | ||
fullyParallel: true, | ||
forbidOnly: !!process.env.CI, // eslint-disable-line no-undef | ||
retries: process.env.CI ? 2 : 0, // eslint-disable-line no-undef | ||
workers: process.env.CI ? 1 : undefined, // eslint-disable-line no-undef | ||
reporter: 'list', | ||
use: { | ||
baseURL: 'http://localhost:3000', | ||
trace: 'on-first-retry', | ||
}, | ||
projects: [ | ||
{ | ||
name: 'authenticate', | ||
testMatch: [/.*auth\.setup\.ts/], | ||
}, | ||
{ | ||
name: 'query', | ||
use: { ...devices['Desktop Chrome'], storageState: 'playwright/.auth/user.json' }, | ||
dependencies: ['authenticate'], | ||
}, | ||
], | ||
}); |
Oops, something went wrong.