Cypress test logging improvements
Print full test name in beforeEach and afterEach Hide xhr requests Hide repeated actual and expected values on passed assertions Add information to failure message Signed-off-by: Neil Guertin <neil.guertin@collabora.com> Change-Id: Ic1a20481c05afb05b9c29d0bd428b59615d49dc7pull/8176/head
parent
3bbedaac01
commit
d1822e4298
|
@ -510,7 +510,6 @@ function reload(fileName, subFolder, noFileCopy, isMultiUser, subsequentLoad, ha
|
||||||
|
|
||||||
// noRename - whether or not to give the file a unique name, if noFileCopy is false.
|
// noRename - whether or not to give the file a unique name, if noFileCopy is false.
|
||||||
function beforeAll(fileName, subFolder, noFileCopy, isMultiUser, subsequentLoad, hasInteractionBeforeLoad, noRename) {
|
function beforeAll(fileName, subFolder, noFileCopy, isMultiUser, subsequentLoad, hasInteractionBeforeLoad, noRename) {
|
||||||
cy.log('Starting test: ' + Cypress.spec.relative + ' / ' + Cypress.currentTest.titlePath.join(' / '));
|
|
||||||
// Set defaults here in order to remove checks from cy.cGet function.
|
// Set defaults here in order to remove checks from cy.cGet function.
|
||||||
cy.cSetActiveFrame('#coolframe');
|
cy.cSetActiveFrame('#coolframe');
|
||||||
|
|
||||||
|
@ -519,7 +518,6 @@ function beforeAll(fileName, subFolder, noFileCopy, isMultiUser, subsequentLoad,
|
||||||
|
|
||||||
function afterAll(fileName, testState) {
|
function afterAll(fileName, testState) {
|
||||||
closeDocument(fileName, testState);
|
closeDocument(fileName, testState);
|
||||||
cy.log('Finished test: ' + Cypress.spec.relative + ' / ' + Cypress.currentTest.titlePath.join(' / '));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This method is intended to call after each test case.
|
// This method is intended to call after each test case.
|
||||||
|
|
|
@ -1,11 +1,40 @@
|
||||||
/* -*- js-indent-level: 8 -*- */
|
/* -*- js-indent-level: 8 -*- */
|
||||||
/* global require cy Cypress */
|
/* global require cy Cypress beforeEach afterEach */
|
||||||
|
|
||||||
require('cypress-wait-until');
|
require('cypress-wait-until');
|
||||||
require('cypress-file-upload');
|
require('cypress-file-upload');
|
||||||
import installLogsCollector from 'cypress-terminal-report/src/installLogsCollector';
|
import installLogsCollector from 'cypress-terminal-report/src/installLogsCollector';
|
||||||
|
|
||||||
installLogsCollector();
|
|
||||||
|
beforeEach(function() {
|
||||||
|
cy.log('Starting test: ' + getFullTestName());
|
||||||
|
});
|
||||||
|
|
||||||
|
// This afterEach must be before installLogsCollector, otherwise the
|
||||||
|
// cypress-terminal-report afterEach gets called first, and so this log does
|
||||||
|
// not get printed
|
||||||
|
afterEach(function() {
|
||||||
|
cy.log('Finishing test: ' + getFullTestName());
|
||||||
|
});
|
||||||
|
|
||||||
|
installLogsCollector({
|
||||||
|
// Filter xhr requests from log
|
||||||
|
filterLog: function(log) {
|
||||||
|
var type = log[0];
|
||||||
|
return type !== 'cy:xhr';
|
||||||
|
},
|
||||||
|
// Filter assertion values when assertion passes
|
||||||
|
processLog: function(log) {
|
||||||
|
var type = log[0];
|
||||||
|
var message = log[1];
|
||||||
|
var severity = log[2];
|
||||||
|
if (type == 'cy:command' && message.startsWith('assert') && severity !== 'error') {
|
||||||
|
return [type,message.split('\n')[0],severity];
|
||||||
|
} else {
|
||||||
|
return log;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if (Cypress.env('INTEGRATION') === 'php-proxy') {
|
if (Cypress.env('INTEGRATION') === 'php-proxy') {
|
||||||
Cypress.Server.defaults({
|
Cypress.Server.defaults({
|
||||||
|
@ -34,11 +63,14 @@ if (Cypress.env('INTEGRATION') === 'nextcloud') {
|
||||||
}
|
}
|
||||||
|
|
||||||
Cypress.on('fail', function(error) {
|
Cypress.on('fail', function(error) {
|
||||||
Cypress.log({ name:'fail:',
|
var message = '\n';
|
||||||
message: error.codeFrame.absoluteFile + ':'
|
message += 'Test failed: ' + getFullTestName() + '\n';
|
||||||
+ error.codeFrame.line + ':'
|
message += '\n';
|
||||||
+ error.codeFrame.column + '\n'
|
message += error.message + '\n';
|
||||||
+ error.codeFrame.frame });
|
message += '\n';
|
||||||
|
message += error.codeFrame.absoluteFile + ':' + error.codeFrame.line + ':' + error.codeFrame.column + '\n';
|
||||||
|
message += error.codeFrame.frame;
|
||||||
|
Cypress.log({name: 'fail:', message: message});
|
||||||
|
|
||||||
//https://stackoverflow.com/a/63519375/1592055
|
//https://stackoverflow.com/a/63519375/1592055
|
||||||
//returning false here prevents Cypress from failing the test */
|
//returning false here prevents Cypress from failing the test */
|
||||||
|
@ -154,3 +186,7 @@ Cypress.Commands.add('cGet', function(selector, options) {
|
||||||
.its('0.contentDocument', {log: false});
|
.its('0.contentDocument', {log: false});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function getFullTestName() {
|
||||||
|
return Cypress.spec.relative + ' / ' + Cypress.currentTest.titlePath.join(' / ');
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue