Skip to content

Commit

Permalink
fix: make sure scrollTo, window, document, title, go, reload, locatio…
Browse files Browse the repository at this point in the history
…n, hash, and url commands can communicate with the AUT
  • Loading branch information
AtofStryker committed Jan 10, 2025
1 parent 0e8a766 commit eb2f31f
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ context('cy.origin viewport', { browser: '!webkit' }, () => {

cy.window().its('innerHeight').should('eq', 480)
cy.window().its('innerWidth').should('eq', 320)
})

cy.window().then((win) => {
win.location.href = 'http://www.idp.com:3500/fixtures/primary-origin.html'
cy.window().then((win) => {
win.location.href = 'http://www.idp.com:3500/fixtures/primary-origin.html'
})
})

cy.origin('http://www.idp.com:3500', () => {
Expand Down
3 changes: 3 additions & 0 deletions packages/driver/src/cy/commands/actions/scroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,9 @@ export default (Commands, Cypress, cy, state) => {
const subjectChain = cy.subjectChain()

const ensureScrollability = () => {
// Make sure the scroll command can communicate with the AUT
Cypress.ensure.commandCanCommunicateWithAUT(cy)

try {
subject = cy.getSubjectFromChain(subjectChain)

Expand Down
9 changes: 9 additions & 0 deletions packages/driver/src/cy/commands/location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import $errUtils from '../../cypress/error_utils'

export default (Commands, Cypress, cy) => {
Commands.addQuery('url', function url (options: Partial<Cypress.UrlOptions> = {}) {
// Make sure the url command can communicate with the AUT.
// otherwise, it yields an empty string
Cypress.ensure.commandCanCommunicateWithAUT(cy)
this.set('timeout', options.timeout)

Cypress.log({ message: '', hidden: options.log === false, timeout: options.timeout })
Expand All @@ -16,6 +19,8 @@ export default (Commands, Cypress, cy) => {
})

Commands.addQuery('hash', function url (options: Partial<Cypress.Loggable & Cypress.Timeoutable> = {}) {
// Make sure the hash command can communicate with the AUT.
Cypress.ensure.commandCanCommunicateWithAUT(cy)
this.set('timeout', options.timeout)

Cypress.log({ message: '', hidden: options.log === false, timeout: options.timeout })
Expand All @@ -26,6 +31,10 @@ export default (Commands, Cypress, cy) => {
Commands.addQuery('location', function location (key, options: Partial<Cypress.Loggable & Cypress.Timeoutable> = {}) {
// normalize arguments allowing key + options to be undefined
// key can represent the options

// Make sure the location command can communicate with the AUT.
// otherwise the command just yields 'null' and the reason may be unclear to the user.
Cypress.ensure.commandCanCommunicateWithAUT(cy)
if (_.isObject(key)) {
options = key
}
Expand Down
7 changes: 7 additions & 0 deletions packages/driver/src/cy/commands/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,10 @@ export default (Commands, Cypress, cy, state, config) => {
cleanup()
}

// Make sure the reload command can communicate with the AUT.
// if we failed for any other reason, we need to display the correct error to the user.
Cypress.ensure.commandCanCommunicateWithAUT(cy)

return null
})
},
Expand Down Expand Up @@ -700,6 +704,9 @@ export default (Commands, Cypress, cy, state, config) => {
cleanup()
}

// Make sure the go command can communicate with the AUT.
Cypress.ensure.commandCanCommunicateWithAUT(cy)

return null
})
}
Expand Down
7 changes: 7 additions & 0 deletions packages/driver/src/cy/commands/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,18 @@ export default (Commands, Cypress, cy, state) => {
}

Commands.addQuery('title', function title (options: Partial<Cypress.Loggable & Cypress.Timeoutable> = {}) {
// Make sure the window command can communicate with the AUT.
// otherwise, it yields an empty string
Cypress.ensure.commandCanCommunicateWithAUT(cy)
this.set('timeout', options.timeout)
Cypress.log({ timeout: options.timeout, hidden: options.log === false })

return () => (state('document')?.title || '')
})

Commands.addQuery('window', function windowFn (options: Partial<Cypress.Loggable & Cypress.Timeoutable> = {}) {
// Make sure the window command can communicate with the AUT.
Cypress.ensure.commandCanCommunicateWithAUT(cy)
this.set('timeout', options.timeout)
Cypress.log({
hidden: options.log === false,
Expand All @@ -114,6 +119,8 @@ export default (Commands, Cypress, cy, state) => {
})

Commands.addQuery('document', function documentFn (options: Partial<Cypress.Loggable & Cypress.Timeoutable> = {}) {
// Make sure the document command can communicate with the AUT.
Cypress.ensure.commandCanCommunicateWithAUT(cy)
this.set('timeout', options.timeout)
Cypress.log({
hidden: options.log === false,
Expand Down
6 changes: 3 additions & 3 deletions packages/graphql/schemas/cloud.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ type CloudProjectNotFound {
}

union CloudProjectResult =
CloudProject
| CloudProject
| CloudProjectNotFound
| CloudProjectUnauthorized

Expand Down Expand Up @@ -456,7 +456,7 @@ type CloudProjectSpec implements Node {
}

union CloudProjectSpecFlakyResult =
CloudFeatureNotEnabled
| CloudFeatureNotEnabled
| CloudProjectSpecFlakyStatus

type CloudProjectSpecFlakyStatus {
Expand Down Expand Up @@ -500,7 +500,7 @@ type CloudProjectSpecNotFound {
}

union CloudProjectSpecResult =
CloudProjectSpec
| CloudProjectSpec
| CloudProjectSpecNotFound
| CloudProjectUnauthorized

Expand Down

0 comments on commit eb2f31f

Please sign in to comment.