cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
46.86k stars 3.17k forks source link

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

Closed LynyrdRoss closed 1 year ago

LynyrdRoss commented 1 year ago

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 commented 1 year ago

@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 commented 1 year ago

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 commented 1 year ago

@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.

https://github.com/cypress-io/cypress/blob/b71788d87df83eeb844c7e9de2ee106d2724fa9c/npm/xpath/src/index.js#L52-L55

MikeMcC399 commented 1 year ago

@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 commented 1 year ago

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 commented 6 months ago

This issue https://github.com/cypress-io/cypress/issues/29294 means that Cypress still requires xpath in order to test Salesforce lightning elements properly