A. The font-weight value should be a string: '700'.
B. The selector '#header' is invalid and should be '.header'.
C. The method 'have.css' should be replaced with 'css'.
D. The assertion should use 'expect' instead of 'should'.
Solution
Step 1: Check the type of CSS value in assertion
Cypress expects the CSS value as a string, so 700 should be '700'.
Step 2: Verify other parts of the command
The selector '#header' is valid, and 'should' with 'have.css' is correct syntax.
Final Answer:
The font-weight value should be a string: '700'. -> Option A
Quick Check:
CSS values must be strings in assertions [OK]
Hint: Always quote CSS values in Cypress assertions [OK]
Common Mistakes:
Passing numbers instead of strings for CSS values
Changing valid selectors unnecessarily
Confusing assertion methods in Cypress
5. You want to verify that a button with class .submit-btn has a border radius of 5 pixels and a background color that is not transparent. Which Cypress code correctly asserts both styles?
hard
A. cy.get('.submit-btn').should('have.css', 'border-radius', '5px').and('have.css', 'background-color').not('transparent')
B. cy.get('.submit-btn').should('have.css', 'border-radius', '5px').and('have.css', 'background-color', 'rgba(0, 0, 0, 0)')
C. cy.get('.submit-btn').should('have.css', 'border-radius', '5px').and('have.css', 'background-color').should(value => expect(value).not.to.equal('rgba(0, 0, 0, 0)'))
D. cy.get('.submit-btn').should('have.css', 'border-radius', 5).and('have.css', 'background-color', 'transparent')"
Solution
Step 1: Assert border-radius with correct value and type
Use should('have.css', 'border-radius', '5px') to check border radius as a string with units.
Step 2: Assert background-color is not transparent
Since 'transparent' can be represented as 'rgba(0, 0, 0, 0)', use a callback assertion to check the value is not equal to that.
Step 3: Review options for correctness
cy.get('.submit-btn').should('have.css', 'border-radius', '5px').and('have.css', 'background-color').should(value => expect(value).not.to.equal('rgba(0, 0, 0, 0)')) uses a callback with should and expect to verify background-color is not transparent, which is correct.