Skip to content
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

chore: (multi-domain) support origin and domain name in switchToDomain #20564

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cli/types/cypress.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1911,7 +1911,7 @@ declare namespace Cypress {
* cy.get('h1').should('equal', 'Example Domain')
* })
*/
switchToDomain(domain: string, fn: () => void): Chainable
switchToDomain(originOrDomain: string, fn: () => void): Chainable
/**
* Enables running Cypress commands in a secondary domain
* @see https://on.cypress.io/switchToDomain
Expand All @@ -1921,7 +1921,7 @@ declare namespace Cypress {
* expect(foo).to.equal('foo')
* })
*/
switchToDomain<T>(domain: string, data: T[], fn: (data: T[]) => void): Chainable
switchToDomain<T>(originOrDomain: string, data: T[], fn: (data: T[]) => void): Chainable

/**
* Run a task in Node via the plugins file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ describe('basic login', { experimentalSessionSupport: true }, () => {
it('logs in with idp redirect', () => {
cy.visit('/fixtures/auth/index.html') // Establishes Primary Domain
cy.get('[data-cy="login-idp"]').click() // Takes you to idp.com
cy.switchToDomain('idp.com', () => {
cy.switchToDomain('http://idp.com:3500', () => {
cy.get('[data-cy="username"]').type('BJohnson')
cy.get('[data-cy="login"]').click()
}) // Trailing edge wait, waiting to return to the primary domain
Expand All @@ -24,7 +24,7 @@ describe('basic login', { experimentalSessionSupport: true }, () => {
win.location.href = 'http://www.idp.com:3500/fixtures/auth/idp.html'
})

cy.switchToDomain('idp.com', () => {
cy.switchToDomain('http://idp.com:3500', () => {
cy.get('[data-cy="username"]').type('FJohnson')
cy.get('[data-cy="login"]').click()
})
Expand All @@ -39,7 +39,7 @@ describe('basic login', { experimentalSessionSupport: true }, () => {
it.skip('visits foobar first', () => {
cy.visit('http://www.foobar.com:3500/fixtures/auth/index.html') // Establishes Primary Domain
cy.get('[data-cy="login-idp"]').click() // Takes you to idp.com
cy.switchToDomain('idp.com', () => {
cy.switchToDomain('http://idp.com:3500', () => {
cy.get('[data-cy="username"]').type('BJohnson')
cy.get('[data-cy="login"]').click()
}) // Trailing edge wait, waiting to return to the primary domain
Expand Down Expand Up @@ -182,9 +182,9 @@ describe('Multi-step Auth', { experimentalSessionSupport: true }, () => {
cy.visit('/fixtures/auth/index.html')
cy.get('[data-cy="login-with-approval"]').click() // takes you to foobar.com.../approval
cy.url() //fail
cy.switchToDomain('foobar.com', () => { // Parent Domain is localhost
cy.switchToDomain('http://foobar.com:3500', () => { // Parent Domain is localhost
cy.get('[data-cy="approve-orig"]').click() // takes you to idp.com
cy.switchToDomain('idp.com', () => { // Parent domain is foobar.com
cy.switchToDomain('http://idp.com:3500', () => { // Parent domain is foobar.com
cy.get('[data-cy="username"]').type('MarkyMark')
cy.get('[data-cy="login"]').click() // Takes you back to localhost
}) // Does not wait on foobar.com because there are no subsequent commands (would wait forever)
Expand Down Expand Up @@ -220,7 +220,7 @@ describe('Multi-step Auth', { experimentalSessionSupport: true }, () => {
cy.createDomain('foobar.com', { primaryDomain: 'localhost' }, () => { // Parent Domain is localhost
cy.visit('http://www.foobar.com:3500/fixtures/auth/approval.html')
cy.get('[data-cy="approve-orig"]').click() // takes you to idp.com
cy.switchToDomain('idp.com', () => { // Parent domain is foobar.com
cy.switchToDomain('http://idp.com:3500', () => { // Parent domain is foobar.com
cy.get('[data-cy="username"]').type('MarkyMark')
cy.get('[data-cy="login"]').click() // Takes you back to localhost
}) // Does not wait on foobar.com because there are no subsequent commands (would wait forever)
Expand All @@ -236,9 +236,9 @@ describe('Multi-step Auth', { experimentalSessionSupport: true }, () => {
it.skip('final auth redirects back to approval page - nested', () => {
cy.visit('/fixtures/auth/index.html')
cy.get('[data-cy="login-with-approval"]').click() // takes you to foobar.com.../approval
cy.switchToDomain('foobar.com', () => { // Parent Domain is localhost
cy.switchToDomain('http://foobar.com:3500', () => { // Parent Domain is localhost
cy.get('[data-cy="approve-me"]').click() // takes you to idp.com
cy.switchToDomain('idp.com', () => { // Parent domain is foobar.com
cy.switchToDomain('http://idp.com:3500', () => { // Parent domain is foobar.com
cy.get('[data-cy="username"]').type('MarkyMark')
cy.get('[data-cy="login"]').click() // Takes you back to foobar.com.../approval
}) // Waits on foobar because there are subsequent commands
Expand All @@ -256,16 +256,16 @@ describe('Multi-step Auth', { experimentalSessionSupport: true }, () => {
it.skip('final auth redirects back to approval page - flat', () => {
cy.visit('/fixtures/auth/index.html')
cy.get('[data-cy="login-with-approval"]').click() // takes you to foobar.com.../approval
cy.switchToDomain('foobar.com', () => { // Parent Domain is localhost
cy.switchToDomain('http://foobar.com:3500', () => { // Parent Domain is localhost
cy.get('[data-cy="approve-orig"]').click() // takes you to idp.com
}) // waits on localhost forever, this breaks

cy.switchToDomain('idp.com', () => { // Parent Domain is localhost
cy.switchToDomain('http://idp.com:3500', () => { // Parent Domain is localhost
cy.get('[data-cy="username"]').type('MarkyMark')
cy.get('[data-cy="login"]').click() // Takes you back to foobar.com.../approval
}) // waits on foobar forever, this breaks

cy.switchToDomain('foobar.com', () => { // Parent Domain is localhost
cy.switchToDomain('http://foobar.com:3500', () => { // Parent Domain is localhost
cy.get('[data-cy="login-success"]').click() // Takes you back to localhost
}) // Waits on localhost because there are subsequent commands

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ context('multi-domain actions', { experimentalSessionSupport: true }, () => {
it('.type()', () => {
cy.get('a[data-cy="dom-link"]').click()

cy.switchToDomain('foobar.com', () => {
cy.switchToDomain('http://foobar.com:3500', () => {
cy.get('#input').type('foo')
.should('have.value', 'foo')
})
Expand All @@ -16,7 +16,7 @@ context('multi-domain actions', { experimentalSessionSupport: true }, () => {
it('.focus()', () => {
cy.get('a[data-cy="dom-link"]').click()

cy.switchToDomain('foobar.com', () => {
cy.switchToDomain('http://foobar.com:3500', () => {
cy.get('#input').focus()
.should('be.focused')
})
Expand All @@ -25,7 +25,7 @@ context('multi-domain actions', { experimentalSessionSupport: true }, () => {
it('.blur()', () => {
cy.get('a[data-cy="dom-link"]').click()

cy.switchToDomain('foobar.com', () => {
cy.switchToDomain('http://foobar.com:3500', () => {
cy.get('#input').type('foo').blur()
.should('not.be.focused')
})
Expand All @@ -34,7 +34,7 @@ context('multi-domain actions', { experimentalSessionSupport: true }, () => {
it('.clear()', () => {
cy.get('a[data-cy="dom-link"]').click()

cy.switchToDomain('foobar.com', () => {
cy.switchToDomain('http://foobar.com:3500', () => {
cy.get('#input')
.type('foo').should('have.value', 'foo')
.clear().should('have.value', '')
Expand All @@ -44,7 +44,7 @@ context('multi-domain actions', { experimentalSessionSupport: true }, () => {
it('.submit()', () => {
cy.get('a[data-cy="dom-link"]').click()

cy.switchToDomain('foobar.com', () => {
cy.switchToDomain('http://foobar.com:3500', () => {
const afterFormSubmitted = new Promise<void>((resolve) => {
cy.once('form:submitted', resolve)
})
Expand All @@ -57,7 +57,7 @@ context('multi-domain actions', { experimentalSessionSupport: true }, () => {
it('.click()', () => {
cy.get('a[data-cy="dom-link"]').click()

cy.switchToDomain('foobar.com', () => {
cy.switchToDomain('http://foobar.com:3500', () => {
cy.get('#button').then(($btn) => {
const onClick = new Promise<void>((resolve) => {
$btn.on('click', () => resolve())
Expand All @@ -72,7 +72,7 @@ context('multi-domain actions', { experimentalSessionSupport: true }, () => {
it('.dblclick()', () => {
cy.get('a[data-cy="dom-link"]').click()

cy.switchToDomain('foobar.com', () => {
cy.switchToDomain('http://foobar.com:3500', () => {
cy.get('#button').then(($btn) => {
const afterDblClick = new Promise<void>((resolve) => {
$btn.on('dblclick', () => resolve())
Expand All @@ -87,7 +87,7 @@ context('multi-domain actions', { experimentalSessionSupport: true }, () => {
it('.rightclick()', () => {
cy.get('a[data-cy="dom-link"]').click()

cy.switchToDomain('foobar.com', () => {
cy.switchToDomain('http://foobar.com:3500', () => {
cy.get('#button').then(($btn) => {
const afterContextmenu = new Promise<void>((resolve) => {
$btn.on('contextmenu', () => resolve())
Expand All @@ -102,7 +102,7 @@ context('multi-domain actions', { experimentalSessionSupport: true }, () => {
it('.check()', () => {
cy.get('a[data-cy="dom-link"]').click()

cy.switchToDomain('foobar.com', () => {
cy.switchToDomain('http://foobar.com:3500', () => {
cy.get(':checkbox[name="colors"][value="blue"]')
.check().should('be.checked')
})
Expand All @@ -111,7 +111,7 @@ context('multi-domain actions', { experimentalSessionSupport: true }, () => {
it('.uncheck()', () => {
cy.get('a[data-cy="dom-link"]').click()

cy.switchToDomain('foobar.com', () => {
cy.switchToDomain('http://foobar.com:3500', () => {
cy.get(':checkbox[name="colors"][value="blue"]')
.check().should('be.checked')
.uncheck().should('not.be.checked')
Expand All @@ -121,7 +121,7 @@ context('multi-domain actions', { experimentalSessionSupport: true }, () => {
it('.select()', () => {
cy.get('a[data-cy="dom-link"]').click()

cy.switchToDomain('foobar.com', () => {
cy.switchToDomain('http://foobar.com:3500', () => {
cy.get('select[name="foods"]')
.select('Japanese').should('have.value', 'Japanese')
})
Expand All @@ -130,7 +130,7 @@ context('multi-domain actions', { experimentalSessionSupport: true }, () => {
it('.scrollIntoView()', () => {
cy.get('a[data-cy="scrolling-link"]').click()

cy.switchToDomain('foobar.com', () => {
cy.switchToDomain('http://foobar.com:3500', () => {
cy.get('#scroll-into-view-vertical h5')
.should('not.be.visible')
.scrollIntoView().should('be.visible')
Expand All @@ -140,7 +140,7 @@ context('multi-domain actions', { experimentalSessionSupport: true }, () => {
it('.scrollTo()', () => {
cy.get('a[data-cy="scrolling-link"]').click()

cy.switchToDomain('foobar.com', () => {
cy.switchToDomain('http://foobar.com:3500', () => {
cy.get('#scroll-into-view-vertical h5').should('not.be.visible')
cy.get('#scroll-into-view-vertical').scrollTo(0, 300)
cy.get('#scroll-into-view-vertical h5').should('be.visible')
Expand All @@ -150,7 +150,7 @@ context('multi-domain actions', { experimentalSessionSupport: true }, () => {
it('.trigger()', () => {
cy.get('a[data-cy="dom-link"]').click()

cy.switchToDomain('foobar.com', () => {
cy.switchToDomain('http://foobar.com:3500', () => {
cy.get('#button').then(($btn) => {
const afterClick = new Promise<void>((resolve) => {
$btn.on('click', () => resolve())
Expand All @@ -165,7 +165,7 @@ context('multi-domain actions', { experimentalSessionSupport: true }, () => {
it('.selectFile()', () => {
cy.get('a[data-cy="files-form-link"]').click()

cy.switchToDomain('foobar.com', () => {
cy.switchToDomain('http://foobar.com:3500', () => {
cy.wrap(Cypress.Buffer.from('foo')).as('foo')

cy.get('#basic')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ context('multi-domain aliasing', { experimentalSessionSupport: true }, () => {
})

it('.as()', () => {
cy.switchToDomain('foobar.com', () => {
cy.switchToDomain('http://foobar.com:3500', () => {
cy.get(':checkbox[name="colors"][value="blue"]').as('checkbox')
cy.get('@checkbox').click().should('be.checked')
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ context('multi-domain assertions', { experimentalSessionSupport: true }, () => {
})

it('.should() and .and()', () => {
cy.switchToDomain('foobar.com', () => {
cy.switchToDomain('http://foobar.com:3500', () => {
cy.get(':checkbox[name="colors"][value="blue"]')
.should('not.be.checked').and('not.be.disabled')
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@ context('multi-domain connectors', { experimentalSessionSupport: true }, () => {
})

it('.each()', () => {
cy.switchToDomain('foobar.com', () => {
cy.switchToDomain('http://foobar.com:3500', () => {
cy.get('#by-name>[name="colors"]').each(($element, index) => {
expect($element.prop('type')).to.equal('checkbox')
})
})
})

it('.its()', () => {
cy.switchToDomain('foobar.com', () => {
cy.switchToDomain('http://foobar.com:3500', () => {
cy.get('#by-id>input').its('length').should('eq', 3)
})
})

it('.invoke()', () => {
cy.switchToDomain('foobar.com', () => {
cy.switchToDomain('http://foobar.com:3500', () => {
cy.get('#button').invoke('text').should('eq', 'button')
})
})

it('.spread()', () => {
cy.switchToDomain('foobar.com', () => {
cy.switchToDomain('http://foobar.com:3500', () => {
const arr = ['foo', 'bar', 'baz']

cy.wrap(arr).spread((foo, bar, baz) => {
Expand All @@ -38,7 +38,7 @@ context('multi-domain connectors', { experimentalSessionSupport: true }, () => {
})

it('.then()', () => {
cy.switchToDomain('foobar.com', () => {
cy.switchToDomain('http://foobar.com:3500', () => {
cy.get('#by-id>input').then(($list) => {
expect($list).to.have.length(3)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ context('multi-domain cookies', { experimentalSessionSupport: true }, () => {
})

it('.getCookie(), .getCookies(), and .setCookie()', () => {
cy.switchToDomain('foobar.com', () => {
cy.switchToDomain('http://foobar.com:3500', () => {
cy.getCookies().should('be.empty')

cy.setCookie('foo', 'bar')
Expand All @@ -17,7 +17,7 @@ context('multi-domain cookies', { experimentalSessionSupport: true }, () => {
})

it('.clearCookie()', () => {
cy.switchToDomain('foobar.com', () => {
cy.switchToDomain('http://foobar.com:3500', () => {
cy.setCookie('foo', 'bar')
cy.getCookie('foo').should('not.be.null')
cy.clearCookie('foo')
Expand All @@ -26,7 +26,7 @@ context('multi-domain cookies', { experimentalSessionSupport: true }, () => {
})

it('.clearCookies()', () => {
cy.switchToDomain('foobar.com', () => {
cy.switchToDomain('http://foobar.com:3500', () => {
cy.setCookie('foo', 'bar')
cy.setCookie('faz', 'baz')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ context('multi-domain files', { experimentalSessionSupport: true }, () => {
})

it('.fixture()', () => {
cy.switchToDomain('foobar.com', () => {
cy.switchToDomain('http://foobar.com:3500', () => {
cy.fixture('example.json').then((json) => {
expect(json).to.be.an('object')
expect(json.example).to.be.true
Expand All @@ -15,7 +15,7 @@ context('multi-domain files', { experimentalSessionSupport: true }, () => {
})

it('.readFile()', () => {
cy.switchToDomain('foobar.com', () => {
cy.switchToDomain('http://foobar.com:3500', () => {
cy.readFile('cypress/fixtures/example.json').then((json) => {
expect(json).to.be.an('object')
expect(json.example).to.be.true
Expand All @@ -24,7 +24,7 @@ context('multi-domain files', { experimentalSessionSupport: true }, () => {
})

it('.writeFile()', () => {
cy.switchToDomain('foobar.com', () => {
cy.switchToDomain('http://foobar.com:3500', () => {
const contents = JSON.stringify({ foo: 'bar' })

cy.stub(Cypress, 'backend').resolves({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ context('multi-domain local storage', { experimentalSessionSupport: true }, () =
})

it('.clearLocalStorage()', () => {
cy.switchToDomain('foobar.com', () => {
cy.switchToDomain('http://foobar.com:3500', () => {
cy.window().then((win) => {
win.localStorage.setItem('foo', 'bar')
expect(win.localStorage.getItem('foo')).to.equal('bar')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ context('multi-domain location', { experimentalSessionSupport: true }, () => {
})

it('.hash()', () => {
cy.switchToDomain('foobar.com', () => {
cy.switchToDomain('http://foobar.com:3500', () => {
cy.hash().should('be.empty')
})
})

it('.location()', () => {
cy.switchToDomain('foobar.com', () => {
cy.switchToDomain('http://foobar.com:3500', () => {
cy.location().should((location) => {
expect(location.href).to.equal('http://www.foobar.com:3500/fixtures/multi-domain-secondary.html')
expect(location.origin).to.equal('http://www.foobar.com:3500')
Expand All @@ -21,8 +21,8 @@ context('multi-domain location', { experimentalSessionSupport: true }, () => {
})

it('.url()', () => {
cy.switchToDomain('foobar.com', () => {
cy.url().should('eq', 'http://www.foobar.com:3500/fixtures/multi-domain-secondary.html')
cy.switchToDomain('http://foobar.com:3500', () => {
cy.url().should('equal', 'http://www.foobar.com:3500/fixtures/multi-domain-secondary.html')
})
})
})
Loading