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

Cypress 12.0.1 - contains(element,text) inside within fails #25019

Closed
swannypp opened this issue Dec 7, 2022 · 3 comments · Fixed by #25038
Closed

Cypress 12.0.1 - contains(element,text) inside within fails #25019

swannypp opened this issue Dec 7, 2022 · 3 comments · Fixed by #25038
Assignees

Comments

@swannypp
Copy link

swannypp commented Dec 7, 2022

Current behavior

I find I often target content via an element and it's text inside a container with this pattern. but it fails in cypress 12.0.1

cy.get('form').within(() => {
    cy.contains('label', text).parent().find('input').type('some text')
});

image

Desired behavior

Targeting content with a cy.contains(element, 'text') should work inside a within, as it has done with previous Cypress versions and as indicated in the documentation.

Test code to reproduce

describe('Within Test', () => {
    it('Should be able to target elements within a form', () => {
        cy.visit('https://www.demoblaze.com/');
        cy.contains('a', 'Log in').click();

        cy.get('#logInModal').within(() => {
            cy.get('form').should('be.visible');
            cy.get('label').should('be.visible');

            cy.get('form').within(() => {
                // these work
                cy.contains('Username:').should('be.visible');
                cy.contains('Username').parent().should('be.visible');
                cy.get('input').first().should('be.visible');

                // this doesn't
                cy.contains('label', 'Username').parent().find('input').type('aUsername')
            })
        })
    });
})

Cypress Version

12.0.1

Node version

v14.18.0

Operating System

macOS 12.6

Debug Logs

Other

This fault is able to be replicated easily with the given test code supplied.

@BlueWinds
Copy link
Contributor

We have some regressions around .contains() in Cy12 - looking into this now. Thank you for the clear repro!

@cypress-bot cypress-bot bot added the stage: needs review The PR code is done & tested, needs review label Dec 7, 2022
@BlueWinds
Copy link
Contributor

Looks like we have a regression around .contains() and <form> elements in particular (in addition to the other regression over at #25025). Fix in the linked PR; we're planning to get 12.0.2 out in the next day or two containing several quick fixes.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Dec 8, 2022

Released in 12.0.2.

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

@cypress-bot cypress-bot bot removed the stage: needs review The PR code is done & tested, needs review label Dec 8, 2022
@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Dec 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants