-
Notifications
You must be signed in to change notification settings - Fork 3.4k
feat: support snapshots and console props within multi-domain #20949
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
feat: support snapshots and console props within multi-domain #20949
Conversation
|
Thanks for taking the time to open a PR!
|
further progress with getters cleaned up log/snapshot serialization attempt to pass and hydrate value state of serialized dom elements temp commit traversal dom by some stretch of a miracle this is working... still somehow working after massive performance issues with full tree serialization, fix here is to just attach values to inputs for reifying on primary now we are cookin test WIP tests WIP working multi-domain actions snapshots tests added more tests to verify snapshots add tests and refactor certain tests to make simpler added misc snapshot tests add navigation snapshot placeholder add network request snapshot tests add shadow querying snapshot tests update test names added snapshot querying spec added screenshot snapshot test add spies,clocks, and stubs tests implement snapshot tests for traversal commands rename local storeage snapshot tests to fit convention add viewport snapshot tests rename snapshot traversal to fit naming convention add snapshot waiting tests added window snapshot tests implement navigation snapshot tests now that sinon proxy issues internal to log are now fixed refactor multi-domain snapshot tests to leverage utility method over redefining in each spec
…ryDomainCommunicator
…oleProps sometimes being a function)
…out the functions we are invoking
…mpt to serialize bluebird promises
…s to what is going on in this 'here be dragons' code
a597d05 to
42186f1
Compare
…e snapshot processing for cross origin
b06f58b to
be4bc19
Compare
Test summaryRun details
View run in 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 |
…nto md-support-snapshots-and-console-props
|
I think I have all comments addressed (hopefully I didn't miss anything). I am going to lok into the firefox 93 serialization errors and see if I can have an update soon! |
…s the document is in a cross origin context in the primary, which means accessing any elements will not work
User facing changelog
N/A
Additional details
The goal of this PR is to get snapshots and consoleProps working from within the
cy.origincontext after the spec file has been run inopenmode. Currently, snapshots do NOT work within multi origin since snapshots are captured within the specbridge for the cross origin aspect of the test.running the
basic_login_specwith snapshotsrunning the
basic_login_specwith consolePropsMethods Explored for Multi Origin Snapshotting/ConsoleProps
Having the spec bridge render the snapshot and consoleProps on request from the runner
This is a bit of a complicated problem, mostly relating the the nature of dealing with CORS policy and
postMessage()serialization. Because of these known issues, the first technique to get this working was exploring the path of least resistance and attempting to ask the appropriate spec bridge for the snapshot after spec has been run for the pinned snapshot, and have the specbridge show the appropriate snapshot and print out theconsoleProps. Sounds easy enough, right? Well, not quite.When attempting this method, I ran into the following problems:
BASE_URL/ primary domain. The AUTiframesrcattribute fits the origin policy of myBASE_URLprimary domain.https://www.foobar.comwith a correspondingcy.origin(). The AUTiframehas now changed it'ssrcattribute to fit an origin policy pertaining tohttps://www.foobar.com.BASE_URLprimary domain. My spec now finishes.https://www.foobar.comas well as the command log'sconsolePropsfor the given snapshot. I ask the spec bridge to render this log's snapshot on the page. This ultimately fails because theAUTis in a different origin, and thedocumentthe spec bridge has access to is stale, IE, detached. I would need to set thesrcon the AUT to the proper origin that needs to render the snapshot, which triggers aloadevent. I would then need to try andstopsaid load event with window.stop(), which would need to be invoked in the origin that has ownership of the resource. This causes race conditions for content being loaded on the page, leading to "flickering" and a few other odd experiences, as well as some performance issues. This would also require pretty significant intervention of how we handle page load events, since the page never exactly loads when westopthe load early.Serializing the DOM/consoleProps
This lead me to believe that another course of action needed to be taken. Instead of trying to ask the spec bridge to render snapshots and passing around AUT ownership, I figured it might make sense to explore trying to serialize the DOM for the given snapshot, as well as the
consolePropsfor the log message. This happens while the test runs, as opposed to on request. When a cross-origin log is then pinned, we can set thesrctoabout:blankeffectively by removing it, which occurs incredibly fast and fit's the same-origin policy of the runner. We then take our cross origin snapshot that has been reified, along with it'sconsoleProps, and display it on the page. This happens quickly as the snapshot has been reified and stored in the primary domain.The strange caveat to this method is if our spec ends in a cross origin state. In this case, we ask the appropriate spec bridge to take a snapshot of what is currently on the page, and sent it back to the runner to store as 'final state'. This snapshot is then rendered when a snapshot is not active or unpinned, but is rendered in a same origin context.
The
consoleProps, in order to match the correct element on the page, need to be calculated AFTER the snapshot is thrown on the page. When real time serialization occurs while the test is running, theseconsolePropelements are defined asES6 gettersthat lazily calculate the values output. This means the output is calculated when the consoleProps are invoked in the console, which is AFTER the snapshot has been rendered.For DOM element serialization, two methods were explored:
innerHTMLof the DOM element. This method is performant and simple, but lacks stateful representation of the element in multiple cases. In an attempt to remedy the state issues, certain characteristics of the element are stored alongside its HTML. Since consoleProp/snapshots that are being serialized back to the primary are all copies, we can inject values into the HTML to make the DOM seem more stateful. EX: setting thevalueattribute forinputelements in the DOM to accurately represent the state of the input at that time when the snapshot is rendered in the primary. This is not a fullproof method and is a bit naive, but the hybrid approach allows us to obtain decent performance benefits as well as most important stateful items. It is also a lot more deterministic compared to other approaches, even though the solution isn't super elegant. This is the implementation that exists in this PR.Known Issues with this implementation
There are still some stateful issues being worked out that need to be addressed, such as :
*
selectelements having the correct selected option at snapshot time. There are likely other stateful DOM issues present that need to be discovered* XHR requests, when presented with fully qualified URLs, take snapshots of the primary domain document, when they should be taking snapshots of the "active" domain
* Some snapshots, in transition to the new origin, take snapshots of the old origin. This is likely a race condition from when the
cy.originfunction is invoked vs when the new origin is actually loaded. This issue is commonCy-in-Cy Tests
Since cy-in-cy tests are not available until the 10.x.x release, none are added in this branch. The
snapshotsdirectory tries to validate the correct state of the consoleProps against itself. This isn't create because we can't actually see the DOM element output from the consoleProps matched against the snapshot on the page. When available, several cy-in-cy tests should be added to verify correct snapshot behavior. It will also make surfacing and solving known issues a bit clearer.How has the user experience changed?
User's can now see snapshots within
cy.origininvocations.PR Tasks
cypress-documentation?type definitions?cypress.schema.json?