From 19e9e01178f230b200451d4686ca96f7d4f3b752 Mon Sep 17 00:00:00 2001 From: Steven Vachon Date: Fri, 7 Aug 2020 15:38:44 -0400 Subject: [PATCH] @grafana/e2e: improvements (#26838) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- .../grafana-e2e/src/flows/addDataSource.ts | 52 ++++++++++++++++++- packages/grafana-e2e/src/flows/addPanel.ts | 24 +++++++-- packages/grafana-e2e/src/flows/login.ts | 17 +++--- 3 files changed, 81 insertions(+), 12 deletions(-) diff --git a/packages/grafana-e2e/src/flows/addDataSource.ts b/packages/grafana-e2e/src/flows/addDataSource.ts index 5b4c299bbe6..c47b2849d87 100644 --- a/packages/grafana-e2e/src/flows/addDataSource.ts +++ b/packages/grafana-e2e/src/flows/addDataSource.ts @@ -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): 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): 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 diff --git a/packages/grafana-e2e/src/flows/addPanel.ts b/packages/grafana-e2e/src/flows/addPanel.ts index 8e4b403ba7d..f06ac010032 100644 --- a/packages/grafana-e2e/src/flows/addPanel.ts +++ b/packages/grafana-e2e/src/flows/addPanel.ts @@ -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): 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): 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 }); }); diff --git a/packages/grafana-e2e/src/flows/login.ts b/packages/grafana-e2e/src/flows/login.ts index 218f3d5b3a6..34e906cfed6 100644 --- a/packages/grafana-e2e/src/flows/login.ts +++ b/packages/grafana-e2e/src/flows/login.ts @@ -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')