diff --git a/source/api/cypress-api/cypress-log.md b/source/api/cypress-api/cypress-log.md index e5fbb855fc..784aadd22b 100644 --- a/source/api/cypress-api/cypress-log.md +++ b/source/api/cypress-api/cypress-log.md @@ -1,16 +1,11 @@ --- title: Cypress.log - --- This is the internal API for controlling what gets printed to the Command Log. Useful when writing your own {% url "custom commands" custom-commands %}. -{% note info WIP %} -This page is currently a work in progress and is not fully documented. -{% endnote %} - # Syntax ```javascript @@ -33,22 +28,37 @@ Option | Default | Description # Examples +We want the Command Log and the console in the DevTools to log specific properties of our custom command. + ```javascript -Cypress.Commands.add('myCustomCommand', (arg1, arg2) => { +Cypress.Commands.add('setSessionStorage', (key, value) => { + // urn off logging of the cy.window() to command log + cy.window({ log: false }).then((window) => { + window.sessionStorage.setItem(key, value) + }) + const log = Cypress.log({ + name: 'setSessionStorage', + // shorter name for the Command Log + displayName: 'setSS', + message: `${key}, ${value}`, consoleProps: () => { - // return an object literal which will - // be printed to the dev tools console - // on click + // return an object which will + // print to dev tools console on click return { - 'Some': 'values', - 'For': 'debugging' + 'Key': key, + 'Value': value', + 'Session Storage': window.sessionStorage } } }) }) ``` +The code above displays in the Command Log as shown below, with the console properties shown on click of the command. + +{% imgTag /img/api/Cypress.log-custom-logging-and-console.png "Custom logging of custom command" %} + # See also - {% url `Commands` custom-commands %} diff --git a/themes/cypress/source/img/api/Cypress.log-custom-logging-and-console.png b/themes/cypress/source/img/api/Cypress.log-custom-logging-and-console.png new file mode 100644 index 0000000000..88cbef37ec Binary files /dev/null and b/themes/cypress/source/img/api/Cypress.log-custom-logging-and-console.png differ