Reputation: 23487
Currently I am trying to create a test like the following...
cy.get(".communications-icon")
.should("have.css", "background-color")
.not("eq", "rgb(232, 238, 242)");
But when I run the test I get...
cy.not() failed because it requires a DOM element.
The subject received was:
> rgba(0, 0, 0, 0)
How do I check to make sure an element doesn't have a particular BG color?
Upvotes: 1
Views: 2641
Reputation: 31
You can not use .not()
directly like cy.not()
.
We can use it on DOM elements like Cy.get('id').not('.class')
basically it is used for filtering elements.
For your case have u tried using this
cy.get('.communications-icon').should('have.css', 'background-color').and('eq', 'rgb(232, 238, 242)')
Upvotes: 0
Reputation: 4430
Add the value as a third parameter, and prefix not
inside the assertion
cy.get(".communications-icon")
.should("not.have.css", "background-color", "rgb(232, 238, 242)")
or equivalent
cy.get(".communications-icon")
.should("have.css", "background-color")
.and("not.eq", "rgb(232, 238, 242)")
.not()
command is valid syntax but it's the opposite of .filter()
command and it requires one or more elements passed from the previous line.
The .should("have.css", "background-color")
changes the subject from an element to the color string "rgb(232, 238, 242)"
.
Upvotes: 4