Cypress: Is there a way to highlight/border a specific element when taking a cypress screenshot?

Created on 14 Jan 2019  路  2Comments  路  Source: cypress-io/cypress

Hey there, we're using cypress's great screenshot functionality to generate documentation for our apps. It would be nice to be able to highlight (or put a red border around or have an arrow pointing to) a certain element while taking a full page screenshot. It would be nice if the method would also work when taking a cropped screenshot or a screenshot of a larger containing element.

For example, in the following screenshot, it would be nice to be able to have say the "Submit" button get a red outline:
image

Does anyone know of a good way of doing this? Is this possible right now or does cypress need to add some functionality to make this happen. Thanks!

question

Most helpful comment

@tnrich you can do it yourself. For example we highlight elements the tests have interacted with in https://www.cypress.io/blog/2018/12/20/element-coverage/ Of course in your case this is much simpler

cy.get('button#my-button')
  .then($button => {
    $button.css('border', '1px solid magenta')
  })
cy.screenshot('press this button')

All 2 comments

@tnrich you can do it yourself. For example we highlight elements the tests have interacted with in https://www.cypress.io/blog/2018/12/20/element-coverage/ Of course in your case this is much simpler

cy.get('button#my-button')
  .then($button => {
    $button.css('border', '1px solid magenta')
  })
cy.screenshot('press this button')

Thanks very much @bahmutov !!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jennifer-shehane picture jennifer-shehane  路  3Comments

scottcrowe picture scottcrowe  路  3Comments

SecondFlight picture SecondFlight  路  3Comments

carloscheddar picture carloscheddar  路  3Comments

brian-mann picture brian-mann  路  3Comments