Skip to content

Commit d19c3b8

Browse files
Jan WaśFlgado
authored andcommitted
Make e2e test locators more generic
1 parent a20b25f commit d19c3b8

File tree

2 files changed

+19
-21
lines changed

2 files changed

+19
-21
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ jobs:
9797
- uses: actions/upload-artifact@v4
9898
if: ${{ !cancelled() }}
9999
with:
100-
name: playwright-report
100+
name: playwright-report-${{ matrix.grafana }}
101101
path: playwright-report/
102102
retention-days: 5
103103

src/e2e.test.ts

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,37 @@
11
import { test, expect, Page } from '@playwright/test';
22

33
const GRAFANA_CLIENT = 'grafana-client';
4-
const EXPORT_DATA = 'Explore data';
4+
const EXPLORE_DATA = 'Explore';
55

66
async function login(page: Page) {
77
await page.goto('http://localhost:3000/login');
8-
await page.getByTestId('data-testid Username input field').fill('admin');
9-
await page.getByTestId('data-testid Password input field').fill('admin');
10-
await page.getByTestId('data-testid Login button').click();
11-
await page.getByTestId('data-testid Skip change password button').click();
8+
await page.getByLabel('Username input field').fill('admin');
9+
await page.getByLabel('Password input field').fill('admin');
10+
await page.getByLabel('Login button').click();
11+
await page.getByLabel('Skip change password button').click();
1212
}
1313

1414
async function goToTrinoSettings(page: Page) {
15-
await page.getByTestId('data-testid Toggle menu').click();
15+
await page.getByLabel('Toggle menu').click();
1616
await page.getByRole('link', {name: 'Connections'}).click();
1717
await page.getByRole('link', {name: 'Trino'}).click();
18-
await page.locator('.css-1yhi3xa').click();
19-
await page.getByRole('button', {name: 'Add new data source'}).click();
18+
await page.getByText('Create a Trino data source').click();
2019
}
2120

2221
async function setupDataSourceWithAccessToken(page: Page) {
2322
await page.getByTestId('data-testid Datasource HTTP settings url').fill('http://trino:8080');
2423
await page.locator('div').filter({hasText: /^Impersonate logged in user$/}).getByLabel('Toggle switch').click();
2524
await page.locator('div').filter({hasText: /^Access token$/}).locator('input[type="password"]').fill('aaa');
26-
await page.getByTestId('data-testid Data source settings page Save and Test button').click();
25+
await page.getByLabel('Data source settings page Save and Test button').click();
2726
}
2827

2928
async function setupDataSourceWithClientCredentials(page: Page, clientId: string) {
30-
await page.getByTestId('data-testid Datasource HTTP settings url').fill('http://trino:8080');
29+
await page.getByLabel('Datasource HTTP settings url').fill('http://trino:8080');
3130
await page.locator('div').filter({hasText: /^Token URL$/}).locator('input').fill('http://keycloak:8080/realms/trino-realm/protocol/openid-connect/token');
3231
await page.locator('div').filter({hasText: /^Client id$/}).locator('input').fill(clientId);
3332
await page.locator('div').filter({hasText: /^Client secret$/}).locator('input[type="password"]').fill('grafana-secret');
3433
await page.locator('div').filter({hasText: /^Impersonation user$/}).locator('input').fill('service-account-grafana-client');
35-
await page.getByTestId('data-testid Data source settings page Save and Test button').click();
34+
await page.getByLabel('Data source settings page Save and Test button').click();
3635
}
3736

3837
async function setupDataSourceWithClientTags(page: Page, clientTags: string) {
@@ -44,16 +43,15 @@ async function setupDataSourceWithClientTags(page: Page, clientTags: string) {
4443
}
4544

4645
async function runQueryAndCheckResults(page: Page) {
47-
await page.getByLabel(EXPORT_DATA).click();
46+
await page.getByText(EXPLORE_DATA).click();
4847
await page.getByTestId('data-testid TimePicker Open Button').click();
49-
await page.getByTestId('data-testid Time Range from field').fill('1995-01-01');
50-
await page.getByTestId('data-testid Time Range to field').fill('1995-12-31');
48+
await page.getByLabel('Time Range from field').fill('1995-01-01');
49+
await page.getByLabel('Time Range to field').fill('1995-12-31');
5150
await page.getByTestId('data-testid TimePicker submit button').click();
52-
await page.locator('div').filter({hasText: /^Format asChoose$/}).locator('svg').click();
53-
await page.getByRole('option', {name: 'Table'}).click();
54-
await page.getByTestId('data-testid Code editor container').click();
51+
await page.getByLabel('Format as').click();
52+
await page.getByText('Table', { exact: true }).click();
5553
await page.getByTestId('data-testid RefreshPicker run button').click();
56-
await expect(page.getByTestId('data-testid table body')).toContainText(/.*1995-01-19 0.:00:005703857F.*/);
54+
await expect(page.getByTestId('data-testid table body')).toContainText(/.*1995-01-19 0.:00:00.*/);
5755
}
5856

5957
test('test with access token', async ({ page }) => {
@@ -74,15 +72,15 @@ test('test client credentials flow with wrong credentials', async ({ page }) =>
7472
await login(page);
7573
await goToTrinoSettings(page);
7674
await setupDataSourceWithClientCredentials(page, "some-wrong-client");
77-
await expect(page.getByLabel(EXPORT_DATA)).toHaveCount(0);
75+
await expect(page.getByText(EXPLORE_DATA)).toHaveCount(0);
7876
});
7977

8078
test('test client credentials flow with configured access token', async ({ page }) => {
8179
await login(page);
8280
await goToTrinoSettings(page);
8381
await page.locator('div').filter({hasText: /^Access token$/}).locator('input[type="password"]').fill('aaa');
8482
await setupDataSourceWithClientCredentials(page, GRAFANA_CLIENT);
85-
await expect(page.getByLabel(EXPORT_DATA)).toHaveCount(0);
83+
await expect(page.getByText(EXPLORE_DATA)).toHaveCount(0);
8684
});
8785

8886
test('test with client tags', async ({ page }) => {

0 commit comments

Comments
 (0)