Skip to content

Commit 83d2319

Browse files
committed
Make test generic to work on old and new grafana version
1 parent 2e52b6f commit 83d2319

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

src/e2e.test.ts

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,45 +5,48 @@ const EXPLORE_DATA = 'Explore';
55

66
async function login(page: Page) {
77
await page.goto('http://localhost:3000/login');
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();
8+
await page.getByPlaceholder('email or username').fill('admin');
9+
await page.getByPlaceholder('password').fill('admin');
10+
await page.getByRole('button', { name: 'Login button' }).or(page.getByRole('button', { name: 'Log in' })).click();
11+
await page.getByRole('button', { name: /skip/i }).click();
1212
}
1313

1414
async function goToTrinoSettings(page: Page) {
15-
await page.getByLabel('Toggle menu').click();
16-
await page.getByRole('link', {name: 'Connections'}).click();
17-
await page.getByRole('link', {name: 'Trino'}).click();
18-
await page.getByText('Create a Trino data source').click();
15+
await page.getByRole('button', { name: /toggle menu|open menu/i }).click();
16+
await page.getByText('Connections').click();
17+
await page.getByText(/add.*connection|connect data/i).first().click();
18+
await page.getByText('Trino').click();
19+
await page.getByRole('button', { name: /add new data source|create.*trino.*data source/i }).click();
1920
}
2021

2122
async function setupDataSourceWithAccessToken(page: Page) {
22-
await page.getByLabel('Datasource HTTP settings url').fill('http://trino:8080');
23-
await page.locator('div').filter({hasText: /^Impersonate logged in userAccess token$/}).getByLabel('Toggle switch').click();
23+
await page.getByPlaceholder('http://localhost:8080').fill('http://trino:8080');
24+
await page.locator('div').filter({hasText: /^Impersonate logged in userAccess token$/}).locator('label').nth(1).click();
2425
await page.locator('div').filter({hasText: /^Access token$/}).locator('input[type="password"]').fill('aaa');
25-
await page.getByLabel('Data source settings page Save and Test button').click();
26+
await page.getByRole('button', { name: /save.*test/i }).click();
2627
}
2728

2829
async function setupDataSourceWithClientCredentials(page: Page, clientId: string) {
29-
await page.getByLabel('Datasource HTTP settings url').fill('http://trino:8080');
30+
await page.getByPlaceholder('http://localhost:8080').fill('http://trino:8080');
3031
await page.locator('div').filter({hasText: /^Token URL$/}).locator('input').fill('http://keycloak:8080/realms/trino-realm/protocol/openid-connect/token');
3132
await page.locator('div').filter({hasText: /^Client id$/}).locator('input').fill(clientId);
3233
await page.locator('div').filter({hasText: /^Client secret$/}).locator('input[type="password"]').fill('grafana-secret');
3334
await page.locator('div').filter({hasText: /^Impersonation user$/}).locator('input').fill('service-account-grafana-client');
34-
await page.getByLabel('Data source settings page Save and Test button').click();
35+
await page.getByRole('button', { name: /save.*test/i }).click();
3536
}
3637

3738
async function runQueryAndCheckResults(page: Page) {
3839
await page.getByText(EXPLORE_DATA).click();
40+
await page.locator('textarea[aria-label*="Editor content"]').click();
3941
await page.getByTestId('data-testid TimePicker Open Button').click();
40-
await page.getByLabel('Time Range from field').fill('1995-01-01');
41-
await page.getByLabel('Time Range to field').fill('1995-12-31');
42+
const timeInputs = page.locator('input[value*="now"], input[value*="00:00:00"]');
43+
await timeInputs.first().fill('1995-01-01');
44+
await timeInputs.last().fill('1995-12-31');
4245
await page.getByTestId('data-testid TimePicker submit button').click();
43-
await page.getByLabel('Format as').click();
44-
await page.getByText('Table', { exact: true }).click();
45-
await page.getByTestId('data-testid RefreshPicker run button').click();
46-
await expect(page.getByTestId('data-testid table body')).toContainText(/.*1995-01-19 0.:00:00.*/);
46+
await page.locator('[role="combobox"][aria-label="Format as"]').click();
47+
await page.locator('[id^="react-select"][id$="option-1"]').waitFor();
48+
await page.locator('[id^="react-select"][id$="option-1"]').click();
49+
await expect(page.locator('[role="table"][aria-label="Explore Table"]').getByText(/1995-01-\d+/).first()).toBeVisible();
4750
}
4851

4952
test('test with access token', async ({ page }) => {

0 commit comments

Comments
 (0)