You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: rework window bound commands to use automation clients (#31862)
* spike: cut over cy.url(), cy.hash(), cy.location(), cy.reload(), cy.go(), and cy.title() all to use the automation client to subvert the cross-origin boundary
refactor backend client
* chore: add unit tests for cy url, hash, location, title, reload, and go changes to make it easier to test minor behavior changes
bump cache
* fix issues with cy in cy tests. refactor aut discovery code as the frame tree gets stale on reload
* update comments from code review
---------
Co-authored-by: Jennifer Shehane <[email protected]>
Copy file name to clipboardExpand all lines: cli/CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -19,6 +19,7 @@ _Released 07/01/2025 (PENDING)_
19
19
**Features:**
20
20
21
21
- [`tsx`](https://tsx.is/) is now used in all cases to run the Cypress config, replacing [ts-node](https://github.com/TypeStrong/ts-node) for TypeScript and Node for commonjs/ESM. This should allow for more interoperability for users who are using any variant of ES Modules. Addresses [#8090](https://github.com/cypress-io/cypress/issues/8090), [#15724](https://github.com/cypress-io/cypress/issues/15724), [#21805](https://github.com/cypress-io/cypress/issues/21805), [#22273](https://github.com/cypress-io/cypress/issues/22273), [#22747](https://github.com/cypress-io/cypress/issues/22747), [#23141](https://github.com/cypress-io/cypress/issues/23141), [#25958](https://github.com/cypress-io/cypress/issues/25958), [#25959](https://github.com/cypress-io/cypress/issues/25959), [#26606](https://github.com/cypress-io/cypress/issues/26606), [#27359](https://github.com/cypress-io/cypress/issues/27359), [#27450](https://github.com/cypress-io/cypress/issues/27450), [#28442](https://github.com/cypress-io/cypress/issues/28442), [#30318](https://github.com/cypress-io/cypress/issues/30318), [#30718](https://github.com/cypress-io/cypress/issues/30718), [#30907](https://github.com/cypress-io/cypress/issues/30907), [#30915](https://github.com/cypress-io/cypress/issues/30915), [#30925](https://github.com/cypress-io/cypress/issues/30925), [#30954](https://github.com/cypress-io/cypress/issues/30954) and [#31185](https://github.com/cypress-io/cypress/issues/31185).
22
+
- [`cy.url()`](https://docs.cypress.io/api/commands/url), [`cy.hash()`](https://docs.cypress.io/api/commands/hash), [`cy.go()`](https://docs.cypress.io/api/commands/go), [`cy.reload()`](https://docs.cypress.io/api/commands/reload), [`cy.title()`](https://docs.cypress.io/api/commands/title), and [`cy.location()`](https://docs.cypress.io/api/commands/location) now use the automation client (CDP for Chromium browsers and WebDriver BiDi for Firefox) to return the appropriate values from the commands to the user instead of the window object. This is to avoid cross origin issues with [`cy.origin()`](https://docs.cypress.io/api/commands/origin) so these commands can be invoked anywhere inside a Cypress test without having to worry about origin access issues. Experimental Webkit still will use the window object to retrieve these values. Also, [`cy.window()`](https://docs.cypress.io/api/commands/window) will always return the current window object, regardless of origin restrictions. Not every property from the window object will be accessible depending on the origin context. Addresses [#31196](https://github.com/cypress-io/cypress/issues/31196).
expect(err.message).to.include(`The command was expected to run against origin \`http://localhost:3500\` but the application is at origin \`http://www.foobar.com:3500\`.`)
196
-
expect(err.message).to.include(`This commonly happens when you have either not navigated to the expected origin or have navigated away unexpectedly.`)
197
-
expect(err.message).to.include(`Using \`cy.origin()\` to wrap the commands run on \`http://www.foobar.com:3500\` will likely fix this issue.`)
198
-
expect(err.message).to.include(`cy.origin('http://www.foobar.com:3500', () => {\`\n\` <commands targeting http://www.foobar.com:3500 go here>\`\n\`})`)
199
-
200
-
// make sure that the secondary origin failures do NOT show up as spec failures or AUT failures
201
-
expect(err.message).not.to.include(`The following error originated from your test code, not from Cypress`)
202
-
expect(err.message).not.to.include(`The following error originated from your application code, not from Cypress`)
203
-
done()
204
-
}
205
-
206
-
it('.get()',{defaultCommandTimeout: 50},(done)=>{
207
-
cy.on('fail',(err)=>{
208
-
expect(err.message).to.include(`Timed out retrying after 50ms:`)
209
-
assertOriginFailure(err,done)
210
-
})
211
-
212
-
cy.get('a[data-cy="dom-link"]').click()
213
-
cy.get('#button')
214
-
})
215
-
191
+
// With Cypress 15, window() will work always without cy.origin().
192
+
// However, users may not have access to the AUT window object, so cy.window() yielded window objects
193
+
// may return cross-origin errors.
194
+
context('cross-origin AUT commands working with cy.origin()',()=>{
216
195
it('.window()',(done)=>{
217
-
cy.on('fail',(err)=>{
218
-
assertOriginFailure(err,done)
219
-
})
220
-
221
196
cy.get('a[data-cy="dom-link"]').click()
222
-
cy.window()
223
-
})
224
-
225
-
it('.document()',(done)=>{
226
-
cy.on('fail',(err)=>{
227
-
assertOriginFailure(err,done)
197
+
cy.window().then((win)=>{
198
+
// The window is in a cross-origin state, but users are able to yield the command
199
+
// as well as basic accessible properties
200
+
expect(win.length).to.equal(2)
201
+
try{
202
+
// but cannot access cross-origin properties
203
+
win[0].location.href
204
+
}catch(e){
205
+
expect(e.name).to.equal('SecurityError')
206
+
if(Cypress.isBrowser('firefox')){
207
+
expect(e.message).to.include('Permission denied to get property "href" on cross-origin object')
208
+
}else{
209
+
expect(e.message).to.include('Blocked a frame with origin "http://localhost:3500" from accessing a cross-origin frame.')
expect(err.message).to.include(`The command was expected to run against origin \`http://localhost:3500\` but the application is at origin \`http://www.foobar.com:3500\`.`)
261
+
expect(err.message).to.include(`This commonly happens when you have either not navigated to the expected origin or have navigated away unexpectedly.`)
262
+
expect(err.message).to.include(`Using \`cy.origin()\` to wrap the commands run on \`http://www.foobar.com:3500\` will likely fix this issue.`)
263
+
expect(err.message).to.include(`cy.origin('http://www.foobar.com:3500', () => {\`\n\` <commands targeting http://www.foobar.com:3500 go here>\`\n\`})`)
265
264
266
-
cy.get('a[data-cy="dom-link"]').click()
267
-
cy.location()
268
-
})
265
+
// make sure that the secondary origin failures do NOT show up as spec failures or AUT failures
266
+
expect(err.message).not.to.include(`The following error originated from your test code, not from Cypress`)
267
+
expect(err.message).not.to.include(`The following error originated from your application code, not from Cypress`)
268
+
done()
269
+
}
269
270
270
-
it('.go()',(done)=>{
271
+
it('.get()',{defaultCommandTimeout: 50},(done)=>{
271
272
cy.on('fail',(err)=>{
273
+
expect(err.message).to.include(`Timed out retrying after 50ms:`)
0 commit comments