[Fixed] Using Cypress, how would I write a simple test to check that a logo image exists on a page


specifically, I would like to test that the logo appears on the home page of the app. I guess I am not sure what I should use to look for the image.

I tried

it('has a logo', function () {
    cy.get('img').should('contains' , 'My-Logo.png')

instead of cy.get I also tried to just use


but it also fails.

I wasn’t sure what element I should use or if I should be using get, but it fails. When I look at the source code for the web page, the logo is hidden within the javascript (nodeJS, vueJS,and expressJS application) and I noticed the javascript seems to add a sequence of numbers and letters to the image when I go to the image page even though the image name in the assets folder does not have it on there. My-Logo.d63b7f9.png.


I figured out the solution on my own.

cy.get('form').find('img').should('have.attr', 'src').should('include','My-Logo')

I inspected the element and found the <img src... line was embedded within a <form>. I could do a cy.get('form') and pass, but could not do a cy.get('img') to pass. So then I chained them together and it passed. I am not sure why I cannot just simply add the second should statement, but it failed when I tried to just run:


I am not entirely sure why, but it needed the first “should” statement. I got around VUE adding the sequence of numbers and letters by just asking for the name of the file without the extension. I hope this maybe helps someone else as the documentation did not seem to cover this.

Leave a Reply

(*) Required, Your email will not be published