Skip to content

Commit 2e52b6f

Browse files
author
Jan Waś
committed
Make e2e test locators more generic
1 parent bde0f1c commit 2e52b6f

File tree

2 files changed

+20
-22
lines changed

2 files changed

+20
-22
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: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,49 @@
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) {
23-
await page.getByTestId('data-testid Datasource HTTP settings url').fill('http://trino:8080');
22+
await page.getByLabel('Datasource HTTP settings url').fill('http://trino:8080');
2423
await page.locator('div').filter({hasText: /^Impersonate logged in userAccess token$/}).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 runQueryAndCheckResults(page: Page) {
39-
await page.getByLabel(EXPORT_DATA).click();
38+
await page.getByText(EXPLORE_DATA).click();
4039
await page.getByTestId('data-testid TimePicker Open Button').click();
41-
await page.getByTestId('data-testid Time Range from field').fill('1995-01-01');
42-
await page.getByTestId('data-testid Time Range to field').fill('1995-12-31');
40+
await page.getByLabel('Time Range from field').fill('1995-01-01');
41+
await page.getByLabel('Time Range to field').fill('1995-12-31');
4342
await page.getByTestId('data-testid TimePicker submit button').click();
44-
await page.locator('div').filter({hasText: /^Format asChoose$/}).locator('svg').click();
45-
await page.getByRole('option', {name: 'Table'}).click();
46-
await page.getByTestId('data-testid Code editor container').click();
43+
await page.getByLabel('Format as').click();
44+
await page.getByText('Table', { exact: true }).click();
4745
await page.getByTestId('data-testid RefreshPicker run button').click();
48-
await expect(page.getByTestId('data-testid table body')).toContainText(/.*1995-01-19 0.:00:005703857F.*/);
46+
await expect(page.getByTestId('data-testid table body')).toContainText(/.*1995-01-19 0.:00:00.*/);
4947
}
5048

5149
test('test with access token', async ({ page }) => {
@@ -66,13 +64,13 @@ test('test client credentials flow with wrong credentials', async ({ page }) =>
6664
await login(page);
6765
await goToTrinoSettings(page);
6866
await setupDataSourceWithClientCredentials(page, "some-wrong-client");
69-
await expect(page.getByLabel(EXPORT_DATA)).toHaveCount(0);
67+
await expect(page.getByText(EXPLORE_DATA)).toHaveCount(0);
7068
});
7169

7270
test('test client credentials flow with configured access token', async ({ page }) => {
7371
await login(page);
7472
await goToTrinoSettings(page);
7573
await page.locator('div').filter({hasText: /^Access token$/}).locator('input[type="password"]').fill('aaa');
7674
await setupDataSourceWithClientCredentials(page, GRAFANA_CLIENT);
77-
await expect(page.getByLabel(EXPORT_DATA)).toHaveCount(0);
75+
await expect(page.getByText(EXPLORE_DATA)).toHaveCount(0);
7876
});

0 commit comments

Comments
 (0)