first UI integration test - phone verification + receive SMS alert flow (#900)
**What this PR does**:
Adds our first UI integration test using
[Playwright](https://playwright.dev/) and runs the test on CI. Right now
the test:
- logs into Grafana
- configures the plugin (if it isn't already)
- creates an OnCall schedule, where the current user will be OnCall
- creates an escalation chain to notify based on the newly created
OnCall schedule
- creates a webhook integration, attached to the created escalation
chain
- sends a demo alert for the new integration
- goes to the alert groups page and validates that the escalation step
to alert the OnCall user actually happened
Currently the Playwright tests are run against the 3 default headless
browsers, chromium, Firefox, and webkit. The CI job that runs these
tests is run as a matrix against 3 tagged versions of `grafana`; `main`,
`latest`, and `9.2.6`.
Secondly, it adds most of the logic for a second test which:
- logs into Grafana
- configures the plugin (if it isn't already)
- goes to the user's settings, verifies their phone number (using a tool
called [MailSlurp](https://www.mailslurp.com/))
- configures the current user's default escalation policy to send alerts
via SMS
- creates an escalation policy and configures it to send alerts to our
current user
- creates an integration and assigns the created escalation policy
- triggers a test alert + verifies that we receive the SMS alert text
(again, using MailSlurp)
**Which issue(s) this PR fixes**:
Closes #873
**Checklist**
- [x] Tests updated
- [ ] Documentation added (N/A)
- [ ] `CHANGELOG.md` updated (N/A)
2023-03-06 17:28:52 +01:00
|
|
|
import type { Locator, Page } from '@playwright/test';
|
2023-11-17 11:07:12 +01:00
|
|
|
|
2024-04-25 08:25:59 +02:00
|
|
|
import { randomInt, randomUUID } from 'crypto';
|
first UI integration test - phone verification + receive SMS alert flow (#900)
**What this PR does**:
Adds our first UI integration test using
[Playwright](https://playwright.dev/) and runs the test on CI. Right now
the test:
- logs into Grafana
- configures the plugin (if it isn't already)
- creates an OnCall schedule, where the current user will be OnCall
- creates an escalation chain to notify based on the newly created
OnCall schedule
- creates a webhook integration, attached to the created escalation
chain
- sends a demo alert for the new integration
- goes to the alert groups page and validates that the escalation step
to alert the OnCall user actually happened
Currently the Playwright tests are run against the 3 default headless
browsers, chromium, Firefox, and webkit. The CI job that runs these
tests is run as a matrix against 3 tagged versions of `grafana`; `main`,
`latest`, and `9.2.6`.
Secondly, it adds most of the logic for a second test which:
- logs into Grafana
- configures the plugin (if it isn't already)
- goes to the user's settings, verifies their phone number (using a tool
called [MailSlurp](https://www.mailslurp.com/))
- configures the current user's default escalation policy to send alerts
via SMS
- creates an escalation policy and configures it to send alerts to our
current user
- creates an integration and assigns the created escalation policy
- triggers a test alert + verifies that we receive the SMS alert text
(again, using MailSlurp)
**Which issue(s) this PR fixes**:
Closes #873
**Checklist**
- [x] Tests updated
- [ ] Documentation added (N/A)
- [ ] `CHANGELOG.md` updated (N/A)
2023-03-06 17:28:52 +01:00
|
|
|
|
|
|
|
|
type SelectorType = 'gSelect' | 'grafanaSelect';
|
|
|
|
|
type SelectDropdownValueArgs = {
|
|
|
|
|
page: Page;
|
|
|
|
|
value: string;
|
|
|
|
|
// if set, search for a dropdown that contains this text as its placeholder
|
|
|
|
|
placeholderText?: string;
|
|
|
|
|
// specifies which type of select dropdown we are dealing with (since we currently mix-and-match 3 different components...)
|
|
|
|
|
selectType?: SelectorType;
|
|
|
|
|
// if provided, use this Locator as the root of our search for the dropdown
|
|
|
|
|
startingLocator?: Locator;
|
|
|
|
|
// if true, when selecting the dropdown option, use an exact match, otherwise use a substring contains match
|
|
|
|
|
optionExactMatch?: boolean;
|
2023-07-12 22:41:44 +02:00
|
|
|
|
|
|
|
|
// if true, will press enter in the select dropdown. Some dropdowns don't show a list of options
|
|
|
|
|
// and instead the user must press enter to trigger the search
|
|
|
|
|
pressEnterInsteadOfSelectingOption?: boolean;
|
first UI integration test - phone verification + receive SMS alert flow (#900)
**What this PR does**:
Adds our first UI integration test using
[Playwright](https://playwright.dev/) and runs the test on CI. Right now
the test:
- logs into Grafana
- configures the plugin (if it isn't already)
- creates an OnCall schedule, where the current user will be OnCall
- creates an escalation chain to notify based on the newly created
OnCall schedule
- creates a webhook integration, attached to the created escalation
chain
- sends a demo alert for the new integration
- goes to the alert groups page and validates that the escalation step
to alert the OnCall user actually happened
Currently the Playwright tests are run against the 3 default headless
browsers, chromium, Firefox, and webkit. The CI job that runs these
tests is run as a matrix against 3 tagged versions of `grafana`; `main`,
`latest`, and `9.2.6`.
Secondly, it adds most of the logic for a second test which:
- logs into Grafana
- configures the plugin (if it isn't already)
- goes to the user's settings, verifies their phone number (using a tool
called [MailSlurp](https://www.mailslurp.com/))
- configures the current user's default escalation policy to send alerts
via SMS
- creates an escalation policy and configures it to send alerts to our
current user
- creates an integration and assigns the created escalation policy
- triggers a test alert + verifies that we receive the SMS alert text
(again, using MailSlurp)
**Which issue(s) this PR fixes**:
Closes #873
**Checklist**
- [x] Tests updated
- [ ] Documentation added (N/A)
- [ ] `CHANGELOG.md` updated (N/A)
2023-03-06 17:28:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
type ClickButtonArgs = {
|
|
|
|
|
page: Page;
|
2023-12-15 09:58:25 +01:00
|
|
|
buttonText: string | RegExp;
|
first UI integration test - phone verification + receive SMS alert flow (#900)
**What this PR does**:
Adds our first UI integration test using
[Playwright](https://playwright.dev/) and runs the test on CI. Right now
the test:
- logs into Grafana
- configures the plugin (if it isn't already)
- creates an OnCall schedule, where the current user will be OnCall
- creates an escalation chain to notify based on the newly created
OnCall schedule
- creates a webhook integration, attached to the created escalation
chain
- sends a demo alert for the new integration
- goes to the alert groups page and validates that the escalation step
to alert the OnCall user actually happened
Currently the Playwright tests are run against the 3 default headless
browsers, chromium, Firefox, and webkit. The CI job that runs these
tests is run as a matrix against 3 tagged versions of `grafana`; `main`,
`latest`, and `9.2.6`.
Secondly, it adds most of the logic for a second test which:
- logs into Grafana
- configures the plugin (if it isn't already)
- goes to the user's settings, verifies their phone number (using a tool
called [MailSlurp](https://www.mailslurp.com/))
- configures the current user's default escalation policy to send alerts
via SMS
- creates an escalation policy and configures it to send alerts to our
current user
- creates an integration and assigns the created escalation policy
- triggers a test alert + verifies that we receive the SMS alert text
(again, using MailSlurp)
**Which issue(s) this PR fixes**:
Closes #873
**Checklist**
- [x] Tests updated
- [ ] Documentation added (N/A)
- [ ] `CHANGELOG.md` updated (N/A)
2023-03-06 17:28:52 +01:00
|
|
|
// if provided, use this Locator as the root of our search for the button
|
|
|
|
|
startingLocator?: Locator;
|
2024-08-16 18:43:52 +02:00
|
|
|
exact?: boolean;
|
first UI integration test - phone verification + receive SMS alert flow (#900)
**What this PR does**:
Adds our first UI integration test using
[Playwright](https://playwright.dev/) and runs the test on CI. Right now
the test:
- logs into Grafana
- configures the plugin (if it isn't already)
- creates an OnCall schedule, where the current user will be OnCall
- creates an escalation chain to notify based on the newly created
OnCall schedule
- creates a webhook integration, attached to the created escalation
chain
- sends a demo alert for the new integration
- goes to the alert groups page and validates that the escalation step
to alert the OnCall user actually happened
Currently the Playwright tests are run against the 3 default headless
browsers, chromium, Firefox, and webkit. The CI job that runs these
tests is run as a matrix against 3 tagged versions of `grafana`; `main`,
`latest`, and `9.2.6`.
Secondly, it adds most of the logic for a second test which:
- logs into Grafana
- configures the plugin (if it isn't already)
- goes to the user's settings, verifies their phone number (using a tool
called [MailSlurp](https://www.mailslurp.com/))
- configures the current user's default escalation policy to send alerts
via SMS
- creates an escalation policy and configures it to send alerts to our
current user
- creates an integration and assigns the created escalation policy
- triggers a test alert + verifies that we receive the SMS alert text
(again, using MailSlurp)
**Which issue(s) this PR fixes**:
Closes #873
**Checklist**
- [x] Tests updated
- [ ] Documentation added (N/A)
- [ ] `CHANGELOG.md` updated (N/A)
2023-03-06 17:28:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const fillInInput = (page: Page, selector: string, value: string) => page.fill(selector, value);
|
|
|
|
|
|
|
|
|
|
export const fillInInputByPlaceholderValue = (page: Page, placeholderValue: string, value: string) =>
|
|
|
|
|
fillInInput(page, `input[placeholder*="${placeholderValue}"]`, value);
|
|
|
|
|
|
|
|
|
|
export const getInputByName = (page: Page, name: string): Locator => page.locator(`input[name="${name}"]`);
|
|
|
|
|
|
2024-08-16 18:43:52 +02:00
|
|
|
export const clickButton = async ({ page, buttonText, startingLocator, exact }: ClickButtonArgs): Promise<void> => {
|
2023-11-17 11:07:12 +01:00
|
|
|
const baseLocator = startingLocator || page;
|
2024-08-16 18:43:52 +02:00
|
|
|
await baseLocator.getByRole('button', { name: buttonText, disabled: false, exact }).click();
|
first UI integration test - phone verification + receive SMS alert flow (#900)
**What this PR does**:
Adds our first UI integration test using
[Playwright](https://playwright.dev/) and runs the test on CI. Right now
the test:
- logs into Grafana
- configures the plugin (if it isn't already)
- creates an OnCall schedule, where the current user will be OnCall
- creates an escalation chain to notify based on the newly created
OnCall schedule
- creates a webhook integration, attached to the created escalation
chain
- sends a demo alert for the new integration
- goes to the alert groups page and validates that the escalation step
to alert the OnCall user actually happened
Currently the Playwright tests are run against the 3 default headless
browsers, chromium, Firefox, and webkit. The CI job that runs these
tests is run as a matrix against 3 tagged versions of `grafana`; `main`,
`latest`, and `9.2.6`.
Secondly, it adds most of the logic for a second test which:
- logs into Grafana
- configures the plugin (if it isn't already)
- goes to the user's settings, verifies their phone number (using a tool
called [MailSlurp](https://www.mailslurp.com/))
- configures the current user's default escalation policy to send alerts
via SMS
- creates an escalation policy and configures it to send alerts to our
current user
- creates an integration and assigns the created escalation policy
- triggers a test alert + verifies that we receive the SMS alert text
(again, using MailSlurp)
**Which issue(s) this PR fixes**:
Closes #873
**Checklist**
- [x] Tests updated
- [ ] Documentation added (N/A)
- [ ] `CHANGELOG.md` updated (N/A)
2023-03-06 17:28:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* at a minimum must specify selectType OR placeholderText
|
|
|
|
|
* if both are specified selectType takes precedence
|
|
|
|
|
*/
|
|
|
|
|
const openSelect = async ({
|
|
|
|
|
page,
|
|
|
|
|
placeholderText,
|
|
|
|
|
selectType,
|
|
|
|
|
startingLocator,
|
2023-03-28 09:34:03 +02:00
|
|
|
}: SelectDropdownValueArgs): Promise<Locator> => {
|
first UI integration test - phone verification + receive SMS alert flow (#900)
**What this PR does**:
Adds our first UI integration test using
[Playwright](https://playwright.dev/) and runs the test on CI. Right now
the test:
- logs into Grafana
- configures the plugin (if it isn't already)
- creates an OnCall schedule, where the current user will be OnCall
- creates an escalation chain to notify based on the newly created
OnCall schedule
- creates a webhook integration, attached to the created escalation
chain
- sends a demo alert for the new integration
- goes to the alert groups page and validates that the escalation step
to alert the OnCall user actually happened
Currently the Playwright tests are run against the 3 default headless
browsers, chromium, Firefox, and webkit. The CI job that runs these
tests is run as a matrix against 3 tagged versions of `grafana`; `main`,
`latest`, and `9.2.6`.
Secondly, it adds most of the logic for a second test which:
- logs into Grafana
- configures the plugin (if it isn't already)
- goes to the user's settings, verifies their phone number (using a tool
called [MailSlurp](https://www.mailslurp.com/))
- configures the current user's default escalation policy to send alerts
via SMS
- creates an escalation policy and configures it to send alerts to our
current user
- creates an integration and assigns the created escalation policy
- triggers a test alert + verifies that we receive the SMS alert text
(again, using MailSlurp)
**Which issue(s) this PR fixes**:
Closes #873
**Checklist**
- [x] Tests updated
- [ ] Documentation added (N/A)
- [ ] `CHANGELOG.md` updated (N/A)
2023-03-06 17:28:52 +01:00
|
|
|
/**
|
|
|
|
|
* we currently mix three different dropdown components in the UI..
|
|
|
|
|
* so we need to support all of them :(
|
|
|
|
|
*/
|
|
|
|
|
const dropdownSelectors: Record<SelectorType, string> = {
|
|
|
|
|
gSelect: 'div[class*="GSelect"]',
|
|
|
|
|
grafanaSelect: `div[class*="grafana-select-value-container"] ${
|
|
|
|
|
placeholderText ? `>> text=${placeholderText} ` : ''
|
|
|
|
|
}>> ..`,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const dropdownSelector = dropdownSelectors[selectType];
|
|
|
|
|
const placeholderSelector = `text=${placeholderText}`;
|
|
|
|
|
const selector = dropdownSelector || placeholderSelector;
|
|
|
|
|
|
|
|
|
|
const selectElement: Locator = (startingLocator || page).locator(selector);
|
|
|
|
|
await selectElement.waitFor({ state: 'visible' });
|
|
|
|
|
await selectElement.click();
|
2023-03-28 09:34:03 +02:00
|
|
|
|
|
|
|
|
return selectElement;
|
first UI integration test - phone verification + receive SMS alert flow (#900)
**What this PR does**:
Adds our first UI integration test using
[Playwright](https://playwright.dev/) and runs the test on CI. Right now
the test:
- logs into Grafana
- configures the plugin (if it isn't already)
- creates an OnCall schedule, where the current user will be OnCall
- creates an escalation chain to notify based on the newly created
OnCall schedule
- creates a webhook integration, attached to the created escalation
chain
- sends a demo alert for the new integration
- goes to the alert groups page and validates that the escalation step
to alert the OnCall user actually happened
Currently the Playwright tests are run against the 3 default headless
browsers, chromium, Firefox, and webkit. The CI job that runs these
tests is run as a matrix against 3 tagged versions of `grafana`; `main`,
`latest`, and `9.2.6`.
Secondly, it adds most of the logic for a second test which:
- logs into Grafana
- configures the plugin (if it isn't already)
- goes to the user's settings, verifies their phone number (using a tool
called [MailSlurp](https://www.mailslurp.com/))
- configures the current user's default escalation policy to send alerts
via SMS
- creates an escalation policy and configures it to send alerts to our
current user
- creates an integration and assigns the created escalation policy
- triggers a test alert + verifies that we receive the SMS alert text
(again, using MailSlurp)
**Which issue(s) this PR fixes**:
Closes #873
**Checklist**
- [x] Tests updated
- [ ] Documentation added (N/A)
- [ ] `CHANGELOG.md` updated (N/A)
2023-03-06 17:28:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* notice the difference in double quotes - https://playwright.dev/docs/selectors#text-selector
|
|
|
|
|
*/
|
|
|
|
|
const textMatchSelector = (optionExactMatch: boolean, value: string): string =>
|
|
|
|
|
optionExactMatch ? `text="${value}"` : `text=${value}`;
|
|
|
|
|
|
|
|
|
|
const chooseDropdownValue = async ({ page, value, optionExactMatch = true }: SelectDropdownValueArgs): Promise<void> =>
|
|
|
|
|
page.locator(`div[id^="react-select-"][id$="-listbox"] >> ${textMatchSelector(optionExactMatch, value)}`).click();
|
|
|
|
|
|
2023-07-11 12:07:29 +02:00
|
|
|
export const selectDropdownValue = async (args: SelectDropdownValueArgs): Promise<Locator> => {
|
2023-07-12 22:41:44 +02:00
|
|
|
const { page, value, pressEnterInsteadOfSelectingOption } = args;
|
|
|
|
|
|
2023-03-28 09:34:03 +02:00
|
|
|
const selectElement = await openSelect(args);
|
2023-11-17 11:07:12 +01:00
|
|
|
await selectElement.pressSequentially(value);
|
2023-07-12 22:41:44 +02:00
|
|
|
|
|
|
|
|
if (pressEnterInsteadOfSelectingOption) {
|
|
|
|
|
await page.keyboard.press('Enter');
|
|
|
|
|
} else {
|
|
|
|
|
await chooseDropdownValue(args);
|
|
|
|
|
}
|
2023-07-11 12:07:29 +02:00
|
|
|
|
|
|
|
|
return selectElement;
|
first UI integration test - phone verification + receive SMS alert flow (#900)
**What this PR does**:
Adds our first UI integration test using
[Playwright](https://playwright.dev/) and runs the test on CI. Right now
the test:
- logs into Grafana
- configures the plugin (if it isn't already)
- creates an OnCall schedule, where the current user will be OnCall
- creates an escalation chain to notify based on the newly created
OnCall schedule
- creates a webhook integration, attached to the created escalation
chain
- sends a demo alert for the new integration
- goes to the alert groups page and validates that the escalation step
to alert the OnCall user actually happened
Currently the Playwright tests are run against the 3 default headless
browsers, chromium, Firefox, and webkit. The CI job that runs these
tests is run as a matrix against 3 tagged versions of `grafana`; `main`,
`latest`, and `9.2.6`.
Secondly, it adds most of the logic for a second test which:
- logs into Grafana
- configures the plugin (if it isn't already)
- goes to the user's settings, verifies their phone number (using a tool
called [MailSlurp](https://www.mailslurp.com/))
- configures the current user's default escalation policy to send alerts
via SMS
- creates an escalation policy and configures it to send alerts to our
current user
- creates an integration and assigns the created escalation policy
- triggers a test alert + verifies that we receive the SMS alert text
(again, using MailSlurp)
**Which issue(s) this PR fixes**:
Closes #873
**Checklist**
- [x] Tests updated
- [ ] Documentation added (N/A)
- [ ] `CHANGELOG.md` updated (N/A)
2023-03-06 17:28:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const generateRandomValue = (): string => randomUUID();
|
|
|
|
|
|
2024-04-25 08:25:59 +02:00
|
|
|
export const generateRandomValidLabel = (length = 10) => {
|
|
|
|
|
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
|
|
|
|
|
let result = '';
|
|
|
|
|
for (let i = 0; i < length; i++) {
|
|
|
|
|
const randomIndex = randomInt(0, characters.length);
|
|
|
|
|
result += characters[randomIndex];
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
};
|
|
|
|
|
|
first UI integration test - phone verification + receive SMS alert flow (#900)
**What this PR does**:
Adds our first UI integration test using
[Playwright](https://playwright.dev/) and runs the test on CI. Right now
the test:
- logs into Grafana
- configures the plugin (if it isn't already)
- creates an OnCall schedule, where the current user will be OnCall
- creates an escalation chain to notify based on the newly created
OnCall schedule
- creates a webhook integration, attached to the created escalation
chain
- sends a demo alert for the new integration
- goes to the alert groups page and validates that the escalation step
to alert the OnCall user actually happened
Currently the Playwright tests are run against the 3 default headless
browsers, chromium, Firefox, and webkit. The CI job that runs these
tests is run as a matrix against 3 tagged versions of `grafana`; `main`,
`latest`, and `9.2.6`.
Secondly, it adds most of the logic for a second test which:
- logs into Grafana
- configures the plugin (if it isn't already)
- goes to the user's settings, verifies their phone number (using a tool
called [MailSlurp](https://www.mailslurp.com/))
- configures the current user's default escalation policy to send alerts
via SMS
- creates an escalation policy and configures it to send alerts to our
current user
- creates an integration and assigns the created escalation policy
- triggers a test alert + verifies that we receive the SMS alert text
(again, using MailSlurp)
**Which issue(s) this PR fixes**:
Closes #873
**Checklist**
- [x] Tests updated
- [ ] Documentation added (N/A)
- [ ] `CHANGELOG.md` updated (N/A)
2023-03-06 17:28:52 +01:00
|
|
|
/**
|
|
|
|
|
* wait for the options to appear
|
|
|
|
|
*
|
|
|
|
|
* note that they are not rendered next to the button in the HTML output
|
|
|
|
|
* they're rendered closer to the <body> tag
|
|
|
|
|
*/
|
|
|
|
|
export const selectValuePickerValue = async (
|
|
|
|
|
page: Page,
|
|
|
|
|
valuePickerText: string,
|
|
|
|
|
optionExactMatch = true
|
|
|
|
|
): Promise<void> =>
|
|
|
|
|
(
|
|
|
|
|
await page.waitForSelector(
|
|
|
|
|
`div[class*="grafana-select-menu"] >> ${textMatchSelector(optionExactMatch, valuePickerText)}`
|
|
|
|
|
)
|
|
|
|
|
).click();
|
2024-04-25 08:25:59 +02:00
|
|
|
|
|
|
|
|
export const openDropdown = async ({ page, text }: { page: Page; text: string | RegExp }) =>
|
|
|
|
|
page.locator('div').filter({ hasText: text }).nth(1).click();
|