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

cy.state warning appears in console when running scripts with cy.xpath #27933

Closed
LynyrdRoss opened this issue Sep 28, 2023 · 6 comments
Closed

Comments

@LynyrdRoss
Copy link

Current behavior

I get a warning every time I run a script that involves cy.xpath:

Cypress Warning:
`cy.state('withinSubject')` has been deprecated and will be removed in a future release. You should read `cy.state('withinSubjectChain')` once at the top of your command / query, and resolve it into a value with `cy.getSubjectFromChain(withinSubjectChain)` as needed.

Desired behavior

My initial thoughts is to root out which plugin is causing this. And what I have learned in my own testing of my current plugins is @cypress/xpath.

Out project has page elements using xpath selectors. Is there any way I can get around this warning without removing the plugin?

Test code to reproduce

Repo with reproduction: https://github.com/LynyrdRoss/cypress-test-tiny/tree/cystate-problem

Cypress Version

12.17.4

Node version

16.16.0

Operating System

Windows 10

Debug Logs

No response

Other

This is the link for the plugin if it helps

@jennifer-shehane
Copy link
Member

@LynyrdRoss The cypress/xpath plugin is deprecated, so we won't be making updates to that plugin anymore. However, I don't see the use of cy.state('withinSubject') even being used in that plugin.

Do you use the cypress-testing-library plugin? I know they make a call to that here. https://github.com/testing-library/cypress-testing-library/blob/1af9f2f28b2ca62936da8a8acca81fc87e2192f7/src/utils.js#L10 That may be where the deprecation error is coming from.

@LynyrdRoss
Copy link
Author

I don't recall anyone in our team using that specific plugin. My bad for pointing out @cypress/xpath as my prime suspect. It's just that upon using cy.get, I get no cy.state warnings, but if I switch to cy.xpath, that's where all this warning comes in. Is there any alternative we can use for xpath selection?

@MikeMcC399
Copy link
Contributor

MikeMcC399 commented Sep 29, 2023

@LynyrdRoss

This was a topic that was discussed also in Discord where you can read:

@cypress/xpath is deprecated and it uses the deprecated cy.state()

$ npm install @cypress/xpath
npm WARN deprecated @cypress/xpath@2.0.3: Package no longer supported. 

If it is all still working for you, then you could consider just ignoring the warning

Cypress Warning: cy.state('withinSubject') has been deprecated and will be removed in a future release.

cy.state() has not yet been removed in the latest Cypress release 13.2.0.
*Note: this is slightly out of date now, since the latest release is 13.3.0.

  • You can check what @cypress/xpath contains by viewing the PR chore: Deprecate @cypress/xpath package #26893 which removed it or you can go back in history in this repository, which shows the line of code in the deprecated @cypress/xpath which causes the warning:

const getValue = () => {
let nodes = []
let contextNode
let withinSubject = cy.state('withinSubject')

@MikeMcC399
Copy link
Contributor

@LynyrdRoss

Is there any way I can get around this warning without removing the plugin?

No, as explained above. However you can simply ignore the warning.

I don't think that there is anything more that can be done in this issue regarding the deprecated and unsupported @cypress/xpath npm module, so I suggest to close the issue.

@LynyrdRoss
Copy link
Author

I completely understand. thanks @MikeMcC399 . At this point, it may be best to divert the use of xpath in Cypress. I'm just worried that on future releases where cy.state() is finally removed, we will be forced to adjust all object selectors created via xpath. If I can understand it correctly this is the only course of action that we have considering this has been an ongoing discussion for 4 years?

@alexsch01
Copy link
Contributor

alexsch01 commented Apr 6, 2024

This issue #29294 means that Cypress still requires xpath in order to test Salesforce lightning elements properly

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

No branches or pull requests

4 participants