Commit c5304265 by Hugo Häggmark Committed by GitHub

e2e: Adds better log information during test runs (#20987)

* e2e: Adds log output when you use a selector

* e2e: Adds more log output

* Refactor: Changes after PR comments
parent 6efadc9d
...@@ -10,6 +10,12 @@ module.exports = on => { ...@@ -10,6 +10,12 @@ module.exports = on => {
// }); // });
on('file:preprocessor', cypressTypeScriptPreprocessor); on('file:preprocessor', cypressTypeScriptPreprocessor);
on('task', { on('task', {
compareSnapshotsPlugin compareSnapshotsPlugin,
});
on('task', {
log(args) {
args.optional ? console.log(args.message, args.optional) : console.log(args.message);
return null;
},
}); });
}; };
...@@ -21,3 +21,7 @@ Cypress.Commands.add('compareSnapshot', (args: CompareSnapshotArgs) => { ...@@ -21,3 +21,7 @@ Cypress.Commands.add('compareSnapshot', (args: CompareSnapshotArgs) => {
} }
}); });
}); });
Cypress.Commands.add('logToConsole', (message: string, optional?: any) => {
cy.task('log', { message, optional });
});
...@@ -3,5 +3,6 @@ ...@@ -3,5 +3,6 @@
declare namespace Cypress { declare namespace Cypress {
interface Chainable { interface Chainable {
compareSnapshot(args: CompareSnapshotArgs): void; compareSnapshot(args: CompareSnapshotArgs): void;
logToConsole(message: string, optional?: any): void;
} }
} }
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
"devDependencies": { "devDependencies": {
"@cypress/webpack-preprocessor": "4.1.1", "@cypress/webpack-preprocessor": "4.1.1",
"blink-diff": "1.0.13", "blink-diff": "1.0.13",
"cypress": "3.6.1",
"rollup": "1.6.0", "rollup": "1.6.0",
"rollup-plugin-commonjs": "9.2.1", "rollup-plugin-commonjs": "9.2.1",
"rollup-plugin-node-resolve": "4.0.1", "rollup-plugin-node-resolve": "4.0.1",
...@@ -37,5 +36,8 @@ ...@@ -37,5 +36,8 @@
"ts-loader": "6.2.1", "ts-loader": "6.2.1",
"typescript": "3.7.2" "typescript": "3.7.2"
}, },
"types": "src/index.ts" "types": "src/index.ts",
"dependencies": {
"cypress": "3.7.0"
}
} }
...@@ -2,9 +2,11 @@ import { e2e } from '../index'; ...@@ -2,9 +2,11 @@ import { e2e } from '../index';
import { Url } from '../support/url'; import { Url } from '../support/url';
export const addDashboard = async (): Promise<{ dashboardTitle: string; uid: string }> => { export const addDashboard = async (): Promise<{ dashboardTitle: string; uid: string }> => {
e2e().logToConsole('Adding dashboard');
e2e.pages.AddDashboard.visit(); e2e.pages.AddDashboard.visit();
const dashboardTitle = e2e.flows.saveNewDashboard(); const dashboardTitle = e2e.flows.saveNewDashboard();
e2e().logToConsole('Added dashboard with title:', dashboardTitle);
return new Promise(resolve => { return new Promise(resolve => {
e2e() e2e()
......
...@@ -2,7 +2,7 @@ import { e2e } from '../index'; ...@@ -2,7 +2,7 @@ import { e2e } from '../index';
export const addDataSource = (pluginName?: string): string => { export const addDataSource = (pluginName?: string): string => {
pluginName = pluginName || 'TestData DB'; pluginName = pluginName || 'TestData DB';
e2e().logToConsole('Adding data source with pluginName:', pluginName);
e2e.pages.AddDataSource.visit(); e2e.pages.AddDataSource.visit();
e2e.pages.AddDataSource.dataSourcePlugins(pluginName).click(); e2e.pages.AddDataSource.dataSourcePlugins(pluginName).click();
...@@ -12,6 +12,7 @@ export const addDataSource = (pluginName?: string): string => { ...@@ -12,6 +12,7 @@ export const addDataSource = (pluginName?: string): string => {
e2e.pages.DataSource.saveAndTest().click(); e2e.pages.DataSource.saveAndTest().click();
e2e.pages.DataSource.alert().should('exist'); e2e.pages.DataSource.alert().should('exist');
e2e.pages.DataSource.alertMessage().should('contain.text', 'Data source is working'); e2e.pages.DataSource.alertMessage().should('contain.text', 'Data source is working');
e2e().logToConsole('Added data source with name:', dataSourceName);
return dataSourceName; return dataSourceName;
}; };
...@@ -2,6 +2,7 @@ import { Url } from '../support/url'; ...@@ -2,6 +2,7 @@ import { Url } from '../support/url';
import { e2e } from '../index'; import { e2e } from '../index';
export const deleteDashboard = (dashBoardUid: string) => { export const deleteDashboard = (dashBoardUid: string) => {
e2e().logToConsole('Deleting dashboard with uid:', dashBoardUid);
e2e().request('DELETE', Url.fromBaseUrl(`/api/dashboards/uid/${dashBoardUid}`)); e2e().request('DELETE', Url.fromBaseUrl(`/api/dashboards/uid/${dashBoardUid}`));
/* https://github.com/cypress-io/cypress/issues/2831 /* https://github.com/cypress-io/cypress/issues/2831
......
...@@ -2,6 +2,7 @@ import { Url } from '../support/url'; ...@@ -2,6 +2,7 @@ import { Url } from '../support/url';
import { e2e } from '../index'; import { e2e } from '../index';
export const deleteDataSource = (dataSourceName: string) => { export const deleteDataSource = (dataSourceName: string) => {
e2e().logToConsole('Deleting data source with name:', dataSourceName);
e2e().request('DELETE', Url.fromBaseUrl(`/api/datasources/name/${dataSourceName}`)); e2e().request('DELETE', Url.fromBaseUrl(`/api/datasources/name/${dataSourceName}`));
/* https://github.com/cypress-io/cypress/issues/2831 /* https://github.com/cypress-io/cypress/issues/2831
......
import { e2e } from '../index'; import { e2e } from '../index';
export const login = (username: string, password: string) => { export const login = (username: string, password: string) => {
e2e().logToConsole('Trying to login with:', { username, password });
e2e.pages.Login.visit(); e2e.pages.Login.visit();
e2e.pages.Login.username().type(username); e2e.pages.Login.username().type(username);
e2e.pages.Login.password().type(password); e2e.pages.Login.password().type(password);
e2e.pages.Login.submit().click(); e2e.pages.Login.submit().click();
e2e().logToConsole('Logged in with', { username, password });
}; };
...@@ -20,15 +20,22 @@ export const pageFactory = <S extends Selectors>({ url, selectors }: PageFactory ...@@ -20,15 +20,22 @@ export const pageFactory = <S extends Selectors>({ url, selectors }: PageFactory
const value = selectors[key]; const value = selectors[key];
if (typeof value === 'string') { if (typeof value === 'string') {
// @ts-ignore // @ts-ignore
pageObjects[key] = () => e2e().get(Selector.fromAriaLabel(value)); pageObjects[key] = () => {
e2e().logToConsole('Retrieving Selector:', value);
return e2e().get(Selector.fromAriaLabel(value));
};
} }
if (typeof value === 'function') { if (typeof value === 'function') {
// @ts-ignore // @ts-ignore
pageObjects[key] = (text?: string) => { pageObjects[key] = (text?: string) => {
if (!text) { if (!text) {
return e2e().get(value()); const selector = value();
e2e().logToConsole('Retrieving Selector:', selector);
return e2e().get(selector);
} }
return e2e().get(Selector.fromAriaLabel(value(text))); const selector = value(text);
e2e().logToConsole('Retrieving Selector:', selector);
return e2e().get(Selector.fromAriaLabel(selector));
}; };
} }
}); });
......
{ {
"extends": "../tsconfig.json", "extends": "../tsconfig.json",
"include": ["src/**/*.ts"], "include": ["src/**/*.ts", "./cypress/support/index.d.ts"],
"exclude": ["dist", "node_modules"], "exclude": ["dist", "node_modules"],
"compilerOptions": { "compilerOptions": {
"types": ["cypress"], "types": ["cypress"],
......
...@@ -7932,10 +7932,10 @@ cyclist@^1.0.1: ...@@ -7932,10 +7932,10 @@ cyclist@^1.0.1:
resolved "https://registry.yarnpkg.com/cyclist/-/cyclist-1.0.1.tgz#596e9698fd0c80e12038c2b82d6eb1b35b6224d9" resolved "https://registry.yarnpkg.com/cyclist/-/cyclist-1.0.1.tgz#596e9698fd0c80e12038c2b82d6eb1b35b6224d9"
integrity sha1-WW6WmP0MgOEgOMK4LW6xs1tiJNk= integrity sha1-WW6WmP0MgOEgOMK4LW6xs1tiJNk=
cypress@3.6.1: cypress@3.7.0:
version "3.6.1" version "3.7.0"
resolved "https://registry.yarnpkg.com/cypress/-/cypress-3.6.1.tgz#4420957923879f60b7a5146ccbf81841a149b653" resolved "https://registry.yarnpkg.com/cypress/-/cypress-3.7.0.tgz#e2cd71b87b6ce0d4c72c6ea25da1005d75c1f231"
integrity sha512-6n0oqENdz/oQ7EJ6IgESNb2M7Bo/70qX9jSJsAziJTC3kICfEMmJUlrAnP9bn+ut24MlXQST5nRXhUP5nRIx6A== integrity sha512-o+vfRxqAba8TduelzfZQ4WHmj2yNEjaoO2EuZ8dZ9pJpuW+WGtBGheKIp6zkoQsp8ZgFe8OoHh1i2mY8BDnMAw==
dependencies: dependencies:
"@cypress/listr-verbose-renderer" "0.4.1" "@cypress/listr-verbose-renderer" "0.4.1"
"@cypress/xvfb" "1.2.4" "@cypress/xvfb" "1.2.4"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment