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: Ic1a20481c05afb05b9c29d0bd428b59615d49dc7
pull/8176/head
Neil Guertin 2024-02-07 14:01:41 -05:00 committed by Neil Guertin
parent 3bbedaac01
commit d1822e4298
2 changed files with 43 additions and 9 deletions

View File

@ -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.
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.
cy.cSetActiveFrame('#coolframe');
@ -519,7 +518,6 @@ function beforeAll(fileName, subFolder, noFileCopy, isMultiUser, subsequentLoad,
function afterAll(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.

View File

@ -1,11 +1,40 @@
/* -*- js-indent-level: 8 -*- */
/* global require cy Cypress */
/* global require cy Cypress beforeEach afterEach */
require('cypress-wait-until');
require('cypress-file-upload');
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') {
Cypress.Server.defaults({
@ -34,11 +63,14 @@ if (Cypress.env('INTEGRATION') === 'nextcloud') {
}
Cypress.on('fail', function(error) {
Cypress.log({ name:'fail:',
message: error.codeFrame.absoluteFile + ':'
+ error.codeFrame.line + ':'
+ error.codeFrame.column + '\n'
+ error.codeFrame.frame });
var message = '\n';
message += 'Test failed: ' + getFullTestName() + '\n';
message += '\n';
message += error.message + '\n';
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
//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});
}
});
function getFullTestName() {
return Cypress.spec.relative + ' / ' + Cypress.currentTest.titlePath.join(' / ');
}