Skip to content

Commit

Permalink
Add a better example of Cypress.log (cypress-io#2581)
Browse files Browse the repository at this point in the history
  • Loading branch information
jennifer-shehane authored Mar 6, 2020
1 parent 01d0f40 commit 1888562
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions source/api/cypress-api/cypress-log.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 %}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1888562

Please sign in to comment.