how I can use cypress.screenshot() to capture my application's favicon

Viewed 153

For UI Testing purpose I would like to take a screenshot of my application's favicon , I am using cy.screenshot('Application', { capture: 'fullPage' }) but it is not capturing the favicon

2 Answers

You can assert the favicon is available like so:

it('assert favicon', () => {
 cy.visit('www.reactjs.org').document().its('head').find('link[rel="icon"]').should('have.attr', 'href').should('eq', '/favicon.ico')
});

The example above is using React's official webpage for the assertion, but you can customize the code for your use case.

Most probably it seems that cypress is executing the screenshot before favicon has been loaded. Have you tried just using a timeout before screenshot?

cy.wait(2500).then(cy.screenshot('Application', { capture: 'fullPage' }));
Related