mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
@grafana/e2e: improvements (#26838)
* Minor changes * Only expect login “change password” notification for default passwords * Optionally populate basic auth when adding a datasource * Optionally match screenshot when adding a panel
This commit is contained in:
@@ -3,25 +3,43 @@ import { e2e } from '../index';
|
||||
import { fromBaseUrl, getDataSourceId } from '../support/url';
|
||||
|
||||
export interface AddDataSourceConfig {
|
||||
basicAuth: boolean;
|
||||
basicAuthPassword: string;
|
||||
basicAuthUser: string;
|
||||
checkHealth: boolean;
|
||||
expectedAlertMessage: string | RegExp;
|
||||
form: Function;
|
||||
name: string;
|
||||
skipTlsVerify: boolean;
|
||||
type: string;
|
||||
}
|
||||
|
||||
// @todo this actually returns type `Cypress.Chainable`
|
||||
export const addDataSource = (config?: Partial<AddDataSourceConfig>): any => {
|
||||
const fullConfig = {
|
||||
basicAuth: false,
|
||||
basicAuthPassword: '',
|
||||
basicAuthUser: '',
|
||||
checkHealth: false,
|
||||
expectedAlertMessage: 'Data source is working',
|
||||
form: () => {},
|
||||
name: `e2e-${Date.now()}`,
|
||||
skipTlsVerify: false,
|
||||
type: 'TestData DB',
|
||||
...config,
|
||||
} as AddDataSourceConfig;
|
||||
|
||||
const { checkHealth, expectedAlertMessage, form, name, type } = fullConfig;
|
||||
const {
|
||||
basicAuth,
|
||||
basicAuthPassword,
|
||||
basicAuthUser,
|
||||
checkHealth,
|
||||
expectedAlertMessage,
|
||||
form,
|
||||
name,
|
||||
skipTlsVerify,
|
||||
type,
|
||||
} = fullConfig;
|
||||
|
||||
e2e().logToConsole('Adding data source with name:', name);
|
||||
e2e.pages.AddDataSource.visit();
|
||||
@@ -32,7 +50,39 @@ export const addDataSource = (config?: Partial<AddDataSourceConfig>): any => {
|
||||
|
||||
e2e.pages.DataSource.name().clear();
|
||||
e2e.pages.DataSource.name().type(name);
|
||||
|
||||
if (basicAuth) {
|
||||
e2e()
|
||||
.contains('label', 'Basic auth')
|
||||
.scrollIntoView()
|
||||
.click();
|
||||
e2e()
|
||||
.contains('.gf-form-group', 'Basic Auth Details')
|
||||
.should('be.visible')
|
||||
.scrollIntoView()
|
||||
.within(() => {
|
||||
if (basicAuthUser) {
|
||||
e2e()
|
||||
.get('[placeholder=user]')
|
||||
.type(basicAuthUser);
|
||||
}
|
||||
if (basicAuthPassword) {
|
||||
e2e()
|
||||
.get('[placeholder=Password]')
|
||||
.type(basicAuthPassword);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (skipTlsVerify) {
|
||||
e2e()
|
||||
.contains('label', 'Skip TLS Verify')
|
||||
.scrollIntoView()
|
||||
.click();
|
||||
}
|
||||
|
||||
form();
|
||||
|
||||
e2e.pages.DataSource.saveAndTest().click();
|
||||
e2e.pages.DataSource.alert().should('exist');
|
||||
e2e.pages.DataSource.alertMessage().contains(expectedAlertMessage); // assertion
|
||||
|
||||
@@ -10,10 +10,11 @@ export interface AddPanelConfig {
|
||||
};
|
||||
dashboardUid: string;
|
||||
dataSourceName: string;
|
||||
matchScreenshot: boolean;
|
||||
queriesForm: (config: AddPanelConfig) => void;
|
||||
panelTitle: string;
|
||||
screenshotName: string;
|
||||
visualizationName: string;
|
||||
waitForChartData: boolean;
|
||||
}
|
||||
|
||||
// @todo this actually returns type `Cypress.Chainable`
|
||||
@@ -26,14 +27,24 @@ export const addPanel = (config?: Partial<AddPanelConfig>): any =>
|
||||
},
|
||||
dashboardUid: lastAddedDashboardUid,
|
||||
dataSourceName: lastAddedDataSource,
|
||||
matchScreenshot: false,
|
||||
panelTitle: `e2e-${Date.now()}`,
|
||||
queriesForm: () => {},
|
||||
screenshotName: 'chart',
|
||||
visualizationName: 'Table',
|
||||
waitForChartData: true,
|
||||
...config,
|
||||
} as AddPanelConfig;
|
||||
|
||||
const { chartData, dashboardUid, dataSourceName, panelTitle, queriesForm, visualizationName } = fullConfig;
|
||||
const {
|
||||
chartData,
|
||||
dashboardUid,
|
||||
dataSourceName,
|
||||
matchScreenshot,
|
||||
panelTitle,
|
||||
queriesForm,
|
||||
screenshotName,
|
||||
visualizationName,
|
||||
} = fullConfig;
|
||||
|
||||
e2e.flows.openDashboard({ uid: dashboardUid });
|
||||
e2e.pages.Dashboard.Toolbar.toolbarItems('Add panel').click();
|
||||
@@ -88,6 +99,13 @@ export const addPanel = (config?: Partial<AddPanelConfig>): any =>
|
||||
// Wait for RxJS
|
||||
e2e().wait(500);
|
||||
|
||||
if (matchScreenshot) {
|
||||
e2e.components.Panels.Panel.containerByTitle(panelTitle)
|
||||
.find('.panel-content')
|
||||
.screenshot(screenshotName);
|
||||
e2e().compareScreenshots(screenshotName);
|
||||
}
|
||||
|
||||
// @todo remove `wrap` when possible
|
||||
return e2e().wrap({ config: fullConfig });
|
||||
});
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import { e2e } from '../index';
|
||||
|
||||
export const login = (username: string = 'admin', password: string = 'admin') => {
|
||||
const DEFAULT_USERNAME = 'admin';
|
||||
const DEFAULT_PASSWORD = 'admin';
|
||||
|
||||
export const login = (username = DEFAULT_USERNAME, password = DEFAULT_PASSWORD) => {
|
||||
e2e().logToConsole('Logging in with username:', username);
|
||||
e2e.pages.Login.visit();
|
||||
e2e.pages.Login.username()
|
||||
@@ -10,13 +13,11 @@ export const login = (username: string = 'admin', password: string = 'admin') =>
|
||||
e2e.pages.Login.submit().click();
|
||||
|
||||
// Local tests will have insecure credentials
|
||||
e2e()
|
||||
.url()
|
||||
.then(url => {
|
||||
e2e.pages.Login.skip()
|
||||
.should('be.visible')
|
||||
.click();
|
||||
});
|
||||
if (password === DEFAULT_PASSWORD) {
|
||||
e2e.pages.Login.skip()
|
||||
.should('be.visible')
|
||||
.click();
|
||||
}
|
||||
|
||||
e2e()
|
||||
.get('.login-page')
|
||||
|
||||
Reference in New Issue
Block a user