question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

.should('not.have.css') assertion is passing even though the condition is false

See original GitHub issue

Current behavior

I am trying to write a method which waits for the splash screen of my application to disappear before continuing.

The HTML in my app has a <div> element representing the splash screen which gains the attribute style='display:none;' when the app has loaded.

The <div> element has display: block;as default - I’m getting cypress to assert that this css has been removed but it seems to pass the assertion anyway for should('exist').and('not.have.css', 'display', 'block'):

image

The negative assert that begins with ‘expected undefined’ is happening because cypress is trying to access the next part of the test, elements that don’t exist, when I want it to wait until the splash screen is hidden

Furthermore there is a second .and() assertion which is never called here either.

Desired behavior

I would expect .and.('not.have.css', 'display', 'block') to keep retrying until the element does not have display: block;

Test code to reproduce

I can’t provide the HTML template of any code due to my organisation, but basically it is as follows: when the splash screen is displayed : <div id='pre-load-section'></div> // when app is loading (the ‘display’ style is set to ‘block’ as default) when the splash screen is not displayed <div id='pre-load-section' style='display:none;'> // when the app loads

My method in cypress:

export const SPLASH_PAGE_SELECTOR: string = 'div#pre-load-section';

export const ensureSplashPageNotDisplayed: () => void = () => {
  cy.get(SPLASH_PAGE_SELECTOR)
    .should('exist')
    .and('not.have.css', 'display', 'block')
    .and('have.css', 'display', 'none');
};

Versions

Cypress version: 6.3.0 Browser/version: Chrome 87 Operating System: macOS Big Sur 11.1

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jennifer-shehanecommented, Feb 27, 2021

Right now there doesn’t seem to be enough information to reproduce the problem on our end. We’ll have to close this issue until we can reproduce it. This does not mean that your issue is not happening - it just means that we do not have a path to move forward.

Please comment in this issue with a reproducible example and we will consider reopening the issue. Here are some tips for providing a Short, Self Contained, Correct, Example and our own Troubleshooting Cypress guide.

0reactions
mdodds93commented, Jan 27, 2021

@bahmutov I have tried to create a new repo and set up a similar environment but cypress worked exactly as I would like it to (can’t believe I’m complaining about that).

Unfortunately, I would not be authorised by my organisation to share any of the app code with you on github

Read more comments on GitHub >

github_iconTop Results From Across the Web

Assertions | Cypress Documentation
The test below may still falsely pass if the application behaves unexpectedly, like adding a blank Todo, instead of adding the new Todo...
Read more >
What are Cypress Assertions and How to use ... - Tools QA
Assertions are the validation steps that determine whether the specified step of the automated test case succeeded or not.
Read more >
Why is Cypress saying my element is detached after just ...
Timed out retrying: cy.click() failed because this element is detached from the DOM. <th scope="row" data-automation-id="taskItem" aria-invalid= ...
Read more >
Conditional testing | Cypress examples (v9.7.0) - Gleb Bahmutov
Imagine we want to pass the test if the element does not exist or is invisible. We will use Cypress.dom utility methods and...
Read more >
Assertions in TestNG - Selenium Easy
if not it will fail the test with the given message. Assert.assertTrue(condition) :- It takes one boolean arguments and checks that a condition...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found