-
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
feat: support snapshots and console props within multi-domain #20949
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.origin
context after the spec file has been run inopen
mode. 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_spec
with snapshotsrunning the
basic_login_spec
with 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 AUTiframe
src
attribute fits the origin policy of myBASE_URL
primary domain.https://www.foobar.com
with a correspondingcy.origin()
. The AUTiframe
has now changed it'ssrc
attribute to fit an origin policy pertaining tohttps://www.foobar.com
.BASE_URL
primary domain. My spec now finishes.https://www.foobar.com
as well as the command log'sconsoleProps
for the given snapshot. I ask the spec bridge to render this log's snapshot on the page. This ultimately fails because theAUT
is in a different origin, and thedocument
the spec bridge has access to is stale, IE, detached. I would need to set thesrc
on the AUT to the proper origin that needs to render the snapshot, which triggers aload
event. I would then need to try andstop
said 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 westop
the 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
consoleProps
for 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 thesrc
toabout:blank
effectively 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, theseconsoleProp
elements are defined asES6 getters
that 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:
innerHTML
of 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 thevalue
attribute forinput
elements 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 :
*
select
elements 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.origin
function 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
snapshots
directory 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.origin
invocations.PR Tasks
cypress-documentation
?type definitions
?cypress.schema.json
?