5

I have a div in which I load dynamic image depending if the user clicks on a button.

<div style="background-image: url('myimage.png')"></div>

so far this is my test:

cy.get('label').first().click();

cy.get('.bg-cover').should('have.css', 'background-image');

But how can I check if the background src changes.

kimfs
  • 83
  • 2
  • 9
  • Check this https://stackoverflow.com/questions/2157963/is-it-possible-to-listen-to-a-style-change-event – Ali Azimi Sep 23 '20 at 08:37
  • 2
    Have you tried `.should('have.css', 'background-image', "url('myimage.png')");`? – dork Sep 23 '20 at 08:40
  • @dork the image url can be dynamic, that is why I need to check wether the image exists and the url changes on click – kimfs Sep 23 '20 at 08:54

1 Answers1

12

I'm not sure you already resolved this, but I leave my solution for other

cy.get('.bg-cover')
  .should('have.css', 'background-image')
  .and('include', 'myimage.png')
Njoker
  • 121
  • 3