Mugetsu
Mugetsu

Reputation: 1968

Cypress Command log truncate

Is it possible to truncate the Command Log for the assertion methods?

I have such test

cy.request('/').its('body').should('contain' 'somestring');

The body contains the whole page HTML as a string which results in massive pollution in the Command log in cypress which leads to memory issues. If I would like to do more assertions it will crash cypress.

How can truncate the assert log so it doesn't load the whole body in the assertion Command Log enter image description here

I've tried saving the HTML string to file and reading it so I could make an assertion like on a normal page but currently, it seems not possible in Cypress to load the local file.

Cherrio is also a thing I could potentially use to retrieve data from that HTML string but I would like to avoid using it.

Upvotes: 2

Views: 677

Answers (2)

user12697177
user12697177

Reputation:

The trick to suppressing the verbiage in the log is to pre-test the condition,

cy.request('http://example.com')
  .its('body')
  .then(body => body.includes('Example'))    // map to a boolean
  .should(result => expect(result, 'Body contains "Example"').to.be.true)

results in

assert    Body contains "Example": expected true to be true

Upvotes: 2

rohitkadam19
rohitkadam19

Reputation: 1874

As per documentation here, you can pass { log: false } to request. Check the options section on above documentation

Upvotes: 0

Related Questions