id | title | hide_title | sidebar_label | description | keywords | url | site_name | slug | ||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
cypress-detailed-command-logs |
Detailed Command Logs for Cypress |
true |
Cypress Detailed Command Logs |
Learn how to generate detailed command logs for the test reports of cypress framework testing on lambdatest and download the reports from the dashboard. |
|
LambdaTest |
cypress-detailed-command-logs/ |
The Detailed Command Logs feature provides a comprehensive record of all Cypress commands and their results, both in the console and in a file. This functionality is ideal for debugging and troubleshooting, enabling you to pinpoint specific logs quickly and effectively.
The logs are presented in an easy-to-read, human-readable format using the cypress-terminal-report plugin. Below are the steps to implement this feature for Cypress versions below and above 10.
Before proceeding, ensure that you have installed Cypress and the cypress-terminal-report plugin.
In your package.json
or lambdatest-config.json
file, add the appropriate version of cypress-terminal-report as a dependency:
"cypress-terminal-report": "4.1.3"
"cypress-terminal-report": "^5.3.2"
- In the
lambdatest-config.json
, enable detailed command logs by adding the following setting:
NOTE:- You will be able to see this tab only when you use this capability detailed_command_logs in run_settings in lambdatest-config.json
"run_settings": {
"detailed_command_logs": true,
"downloads": "./cypress/results"
}
- Open the
cypress/plugins/index.js
file in your project. - Add the following code to install and configure the cypress-terminal-report plugin:
const installLogsPrinter = require('cypress-terminal-report/src/installLogsPrinter')
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
installLogsPrinter(on, {
printLogsToFile: 'always',
outputRoot: 'cypress/results/detailCommandLogs',
outputTarget: {
'detailCommandLogs.json': 'json',
},
})
}
To display detailed logs in the terminal, update the installLogsPrinter
with the printLogsToConsole: 'always'
code:
module.exports = (on, config) => {
installLogsPrinter(on, {
printLogsToConsole: 'always', // Enables logs in the terminal
printLogsToFile: 'always',
outputRoot: 'cypress/results/detailCommandLogs',
outputTarget: {
'detailCommandLogs.json': 'json',
},
});
};
- Navigate to
cypress/support/index.js
. - Add the following code to install the log collector:
const installLogsCollector = require('cypress-terminal-report/src/installLogsCollector')
installLogsCollector()
- Open
cypress.config.js
in your project. - Add the following code to configure the plugin:
const { defineConfig } = require("cypress");
const installLogsPrinter = require("cypress-terminal-report/src/installLogsPrinter");
module.exports = defineConfig({
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
installLogsPrinter(on, {
printLogsToFile:"always",
outputRoot: 'cypress/results/detailCommandLogs',
outputTarget: {
'detailCommandLogs.json': 'json',
}
});
},
},
});
If you need logs in the terminal, update the code like this:
const { defineConfig } = require("cypress");
const installLogsPrinter = require("cypress-terminal-report/src/installLogsPrinter");
module.exports = defineConfig({
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
installLogsPrinter(on, {
printLogsToConsole: 'always'
printLogsToFile:"always",
outputRoot: 'cypress/results/detailCommandLogs',
outputTarget: {
'detailCommandLogs.json': 'json',
}
});
},
},
});
- Open
cypress/support/e2e.js
. - Add the following code to install the log collector:
import installLogsCollector from 'cypress-terminal-report/src/installLogsCollector'
installLogsCollector()
Once the Cypress tests are executed, you can view the detailed command logs in the "Detailed Command Logs" tab on the test details page.
For more information, visit Artefacts For A Cypress Project
<img loading="lazy" src={require('../assets/images/cypress/detailed-cypress-logs.png').default} alt="Image" className="doc_img"/>