Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot combine within, should, and contains commands as expected #5183

Closed
erwinheitzman opened this issue Sep 23, 2019 · 3 comments · Fixed by #8699
Closed

Cannot combine within, should, and contains commands as expected #5183

erwinheitzman opened this issue Sep 23, 2019 · 3 comments · Fixed by #8699

Comments

@erwinheitzman
Copy link

erwinheitzman commented Sep 23, 2019

Current behavior:

Taken this example:

cy.get(`article`).within(() => cy.get(`h1`)).should(`have.text`, `My Blog Post`);
cy.contains(`span`, `Hello World!`).should(`exist`);

The first assertion passes but the second assertion fails. This is because it looks for article span instead of span.

Desired behavior:

Taken this example:

cy.get(`article`).within(() => cy.get(`h1`)).should(`have.text`, `My Blog Post`);
cy.contains(`span`, `Hello World!`).should(`exist`);

I expect that it looks for span instead of article span and I expect both assertions to pass.

Steps to reproduce: (app code and test code)

<article class='post'>
    <h1>My Blog Post</h1>
</article>

<div>
    <span>Hello World!</span
</div>
cy.get(`article`).within(() => cy.get(`h1`)).should(`have.text`, `My Blog Post`);
cy.contains(`span`, `Hello World!`).should(`exist`);

Versions

Cypress: 3.4.1
OS: MacOS Mojave 10.14.5
Browser: Electron 61 + Chrome 77

@jennifer-shehane
Copy link
Member

jennifer-shehane commented Sep 23, 2019

I can recreate this - this is not the documented behavior of these commands. This seems possibly related to these 2 issues about incorrect scope: #4757 #4921

<!DOCTYPE html>
<html>
<body>
<article class='post'>
    <h1>My Blog Post</h1>
</article>
<span>Hello World!</span> 
</body>
</html>
it('scope', () => {
  cy.visit('index.html')
  cy.get('article').within(() => {
    cy.get('h1')
  })
    .should('have.text', '\n    My Blog Post\n  ');
  cy.contains('Hello World!').should('be.visible');
})

Screen Shot 2020-06-17 at 3 12 25 PM

@cypress-bot cypress-bot bot added the stage: ready for work The issue is reproducible and in scope label Sep 23, 2019
@jennifer-shehane jennifer-shehane changed the title Cannot combine within and should commands as expected Cannot combine within, should, and contains commands as expected Sep 23, 2019
@cypress-bot cypress-bot bot added stage: work in progress There is an open PR for this issue [WIP] and removed stage: ready for work The issue is reproducible and in scope labels Sep 25, 2019
@cypress-bot cypress-bot bot added stage: ready for work The issue is reproducible and in scope and removed stage: work in progress There is an open PR for this issue [WIP] labels Feb 26, 2020
@cypress-bot cypress-bot bot added stage: work in progress There is an open PR for this issue [WIP] stage: needs review The PR code is done & tested, needs review and removed stage: ready for work The issue is reproducible and in scope stage: work in progress There is an open PR for this issue [WIP] labels Sep 30, 2020
@cypress-bot cypress-bot bot added stage: pending release There is a closed PR for this issue and removed stage: needs review The PR code is done & tested, needs review labels Oct 6, 2020
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Oct 6, 2020

The code for this is done in cypress-io/cypress#8699, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Oct 14, 2020

Released in 5.4.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v5.4.0, please open a new issue.

@cypress-bot cypress-bot bot removed the stage: pending release There is a closed PR for this issue label Oct 14, 2020
@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Oct 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
2 participants