-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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 snapshotting causes attributeChangedCallback
to be triggered on custom elements
#7187
Cypress snapshotting causes attributeChangedCallback
to be triggered on custom elements
#7187
Comments
You can recreate this by running the following test: it("customElement", () => {
cy.visit("https://benjaminknauer.gitlab.io/cypress-custom-elements-bug");
cy.get(".nonExistentElement").should("be.visible");
});
I am fairly confident that this is related to this line of code in Cypress where we are calling If I comment out this line - the https://github.com/cypress-io/cypress/blob/develop/packages/driver/src/cy/snapshots.js#L150 I'm not sure why clone causes the WorkaroundTurn off snapshotting of tests by setting |
attributeChangedCallback
to be triggered on custom elements
Please note that the |
in our case, the custom element triggers an XHR so the problem is particularly bad |
The code for this is done in cypress-io/cypress#8080, but has yet to be released. |
Released in This comment thread has been locked. If you are still experiencing this issue after upgrading to |
The documentation advertises that all websites can be tested with cypress. Unfortunately, I cannot confirm this for websites that use custom elements (https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements).
During the checks for elements with Cypress, the custom elements are apparently cloned or newly created. This means that the constructor of the custom element and possibly the
attributeChangedCallback
is called.The functionality of the application is unfortunately changed by the Cypress tests! If, for example, a global variable is written in these lifecycle methods, a fetch request is executed, or the like, this happens several times in the test.
Here is a cypress project through which this behavior can be reproduced:
https://gitlab.com/benjaminknauer/cypress-custom-elements-bug
The project runs tests against this page, which contains a custom element that prints calls of the lifecycle methods to the console: https://benjaminknauer.gitlab.io/cypress-custom-elements-bug/
Best regards
Benjamin
Current behavior:
Custom element lifecycle methods are called several times.
The execution of the tests influences the application.
Desired behavior:
Custom element lifecycle methods should be called just once. The execution of the application should not be affected by the tests.
Test code to reproduce
Project with cypress tests
https://gitlab.com/benjaminknauer/cypress-custom-elements-bug
Site with a custom element to run test against:
https://benjaminknauer.gitlab.io/cypress-custom-elements-bug/
Versions
Cypress 4.5.0 / Chrome / Fedora 30
The text was updated successfully, but these errors were encountered: