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

fix: .contains() selects proper elements when inside a <form> #25038

Merged
merged 4 commits into from Dec 7, 2022

Conversation

BlueWinds
Copy link
Contributor

User facing changelog

In 12.0.0, we had a regression around .contains() where if the subject was a <form> element, it would only consider the first <input> element in the form, rather than every child. This PR fixes the regression.

Additional details

In addition to the added driver test, this test demonstrates the issue "in the wild":

    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').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')
            })
        })
    });

Steps to test

How has the user experience changed?

PR Tasks

  • Have tests been added/updated?
  • Has the original issue (or this PR, if no issue exists) been tagged with a release in ZenHub? (user-facing changes only)
  • [n/a] Has a PR for user-facing changes been opened in cypress-documentation?
  • [n/a] Have API changes been updated in the type definitions?

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Dec 7, 2022

Thanks for taking the time to open a PR!

@lmiller1990 lmiller1990 self-requested a review December 7, 2022 20:54
@BlueWinds
Copy link
Contributor Author

I tested this in conjunction with #25035 before pulling it into its own branch / PR, so they definitely work cleanly together.

@cypress
Copy link

cypress bot commented Dec 7, 2022



Test summary

24860 0 2489 0Flakiness 23


Run details

Project cypress
Status Passed
Commit a7bb162
Started Dec 7, 2022 9:55 PM
Ended Dec 7, 2022 10:13 PM
Duration 17:57 💡
OS Linux Debian -
Browser Multiple

View run in Cypress Dashboard ➡️


Flakiness

cypress/e2e/e2e/origin/cookie_behavior.cy.ts Flakiness
1 ... > same site / cross origin > XMLHttpRequest > sets cookie on same-site request if withCredentials is true, and attaches to same-site request if withCredentials is true
2 ... > same site / cross origin > fetch > sets same-site cookies if "include" credentials option is specified from request, but does not attach same-site cookies to request by default (same-origin)
3 ... > same site / cross origin > XMLHttpRequest > sets cookie on same-site request if withCredentials is true, and attaches to same-site request if withCredentials is true
4 ... > same site / cross origin > fetch > sets same-site cookies if "include" credentials option is specified from request, but does not attach same-site cookies to request by default (same-origin)
5 ... > same site / cross origin > XMLHttpRequest > sets cookie on same-site request if withCredentials is true, and attaches to same-site request if withCredentials is true
This comment includes only the first 5 flaky tests. See all 23 flaky tests in the Cypress Dashboard.

This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard

Copy link
Member

@emilyrohrbough emilyrohrbough left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are there issues with scoping form inputs to the withinsubject and then running commands within that?

@BlueWinds
Copy link
Contributor Author

BlueWinds commented Dec 7, 2022

are there issues with scoping form inputs to the withinsubject and then running commands within that?

Scoping .contains() to a <form> with .within() hits the exact same logic - and runs into the exact same issue - as having a <form> as the subject.

I tend not to like writing multiple tests where there are multiple ways a user could encounter the same regression.

@BlueWinds BlueWinds merged commit 79f743e into develop Dec 7, 2022
@BlueWinds BlueWinds deleted the issue-25019-contains-in-form-elements branch December 7, 2022 22:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cypress 12.0.1 - contains(element,text) inside within fails
5 participants