Skip to content

Commit

Permalink
Adding specs for all cy commands in multi-domain
Browse files Browse the repository at this point in the history
  • Loading branch information
mschile committed Jan 18, 2022
1 parent 0ef738b commit efe6316
Show file tree
Hide file tree
Showing 24 changed files with 848 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/driver/cypress/fixtures/dom.html
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@
</select>

<fieldset disabled>
<select name="fielset-disabled">
<select name="fieldset-disabled">
<option value="foo">foo</option>
<option value="bar">bar</option>
</select>
Expand Down
15 changes: 14 additions & 1 deletion packages/driver/cypress/fixtures/multi-domain.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@
<head>
</head>
<body>
<a href="http://www.foobar.com:3500/fixtures/multi-domain-secondary.html">Go to different domain</a>
<style>
a {
display: block;
}
</style>
<div>
Go to different domain:
<a data-cy="multi-domain-secondary-link"
href="http://www.foobar.com:3500/fixtures/multi-domain-secondary.html">http://www.foobar.com:3500/fixtures/multi-domain-secondary.html</a>
<a data-cy="dom-link" href="http://www.foobar.com:3500/fixtures/dom.html">http://www.foobar.com:3500/fixtures/dom.html</a>
<a data-cy="scrolling-link" href="http://www.foobar.com:3500/fixtures/scrolling.html">http://www.foobar.com:3500/fixtures/scrolling.html</a>
<a data-cy="request-link" href="http://www.foobar.com:3500/fixtures/request.html">http://www.foobar.com:3500/fixtures/request.html</a>
<a data-cy="shadow-dom-link" href="http://www.foobar.com:3500/fixtures/shadow-dom.html">http://www.foobar.com:3500/fixtures/shadow-dom.html</a>
</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ describe('src/cy/commands/actions/select', () => {
done()
})

cy.get('select[name=fielset-disabled]').select('foo')
cy.get('select[name=fieldset-disabled]').select('foo')
})

it('throws when optgroup is disabled', (done) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
// @ts-ignore / session support is needed for visiting about:blank between tests
context('multi-domain actions', { experimentalSessionSupport: true, experimentalMultiDomain: true }, () => {
beforeEach(() => {
cy.visit('/fixtures/multi-domain.html')
})

it('.type()', () => {
cy.get('a[data-cy="dom-link"]').click()

cy.switchToDomain('foobar.com', () => {
cy.get('#input').type('foo').should('have.value', 'foo')
})
})

it('.focus()', () => {
cy.get('a[data-cy="dom-link"]').click()

cy.switchToDomain('foobar.com', () => {
cy.get('#input').focus()
})
})

it('.blur()', () => {
cy.get('a[data-cy="dom-link"]').click()

cy.switchToDomain('foobar.com', () => {
cy.get('#input').type('foo').blur()
})
})

it('.clear()', () => {
cy.get('a[data-cy="dom-link"]').click()

cy.switchToDomain('foobar.com', () => {
cy.get('#input')
.type('foo').should('have.value', 'foo')
.clear().should('have.value', '')
})
})

it('.submit()', (done) => {
cy.get('a[data-cy="dom-link"]').click()

cy.switchToDomain('foobar.com', done, () => {
Cypress.once('form:submitted', (e) => done())
cy.get('#input-type-submit').submit()
})
})

it('.click()', (done) => {
cy.get('a[data-cy="dom-link"]').click()

cy.switchToDomain('foobar.com', done, () => {
const $btn = cy.$$('#button')

$btn.on('click', (e) => done())
cy.get('#button').click()
})
})

it('.dblclick()', (done) => {
cy.get('a[data-cy="dom-link"]').click()

cy.switchToDomain('foobar.com', done, () => {
const $btn = cy.$$('#button')

$btn.on('dblclick', () => done())
cy.get('#button').dblclick()
})
})

it('.rightclick()', (done) => {
cy.get('a[data-cy="dom-link"]').click()

cy.switchToDomain('foobar.com', done, () => {
const el = cy.$$('#button')

el.on('contextmenu', () => done())

cy.get('#button').rightclick()
})
})

it('.check()', () => {
cy.get('a[data-cy="dom-link"]').click()

cy.switchToDomain('foobar.com', () => {
cy.get(':checkbox[name="colors"][value="blue"]')
.check().should('be.checked')
})
})

it('.uncheck()', () => {
cy.get('a[data-cy="dom-link"]').click()

cy.switchToDomain('foobar.com', () => {
cy.get(':checkbox[name="colors"][value="blue"]')
.check().should('be.checked')
.uncheck().should('not.be.checked')
})
})

it('.select()', () => {
cy.get('a[data-cy="dom-link"]').click()

cy.switchToDomain('foobar.com', () => {
cy.get('select[name="foods"]')
.select('Japanese').should('have.value', 'Japanese')
})
})

it('.scrollIntoView()', () => {
cy.get('a[data-cy="scrolling-link"]').click()

cy.switchToDomain('foobar.com', () => {
cy.get('#scroll-into-view-vertical h5')
.should('not.be.visible')
.scrollIntoView().should('be.visible')
})
})

it('.scrollTo()', () => {
cy.get('a[data-cy="scrolling-link"]').click()

cy.switchToDomain('foobar.com', () => {
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')
})
})

it('.trigger()', (done) => {
cy.get('a[data-cy="dom-link"]').click()

cy.switchToDomain('foobar.com', done, () => {
const $btn = cy.$$('#button')

$btn.on('click', (e) => done())
cy.get('#button').trigger('click')
})
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// @ts-ignore / session support is needed for visiting about:blank between tests
context('multi-domain aliasing', { experimentalSessionSupport: true, experimentalMultiDomain: true }, () => {
beforeEach(() => {
cy.visit('/fixtures/multi-domain.html')
cy.get('a[data-cy="dom-link"]').click()
})

it('.as()', () => {
cy.switchToDomain('foobar.com', () => {
cy.get(':checkbox[name="colors"][value="blue"]').as('checkbox')
cy.get('@checkbox').click().should('be.checked')
})
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// @ts-ignore / session support is needed for visiting about:blank between tests
context('multi-domain assertions', { experimentalSessionSupport: true, experimentalMultiDomain: true }, () => {
beforeEach(() => {
cy.visit('/fixtures/multi-domain.html')
cy.get('a[data-cy="dom-link"]').click()
})

it('.should() and .and()', () => {
cy.switchToDomain('foobar.com', () => {
cy.get(':checkbox[name="colors"][value="blue"]')
.should('not.be.checked').and('not.be.disabled')
})
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// @ts-ignore / session support is needed for visiting about:blank between tests
context('multi-domain connectors', { experimentalSessionSupport: true, experimentalMultiDomain: true }, () => {
beforeEach(() => {
cy.visit('/fixtures/multi-domain.html')
cy.get('a[data-cy="dom-link"]').click()
})

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

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

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

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

cy.wrap(arr).spread((foo, bar, baz) => {
expect(foo).to.eq('foo')
expect(bar).to.eq('bar')
expect(baz).to.eq('baz')
})
})
})

it('.then()', () => {
cy.switchToDomain('foobar.com', () => {
cy.get('#by-id>input').then(($list) => {
expect($list).to.have.length(3)
})
})
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// @ts-ignore / session support is needed for visiting about:blank between tests
// FIXME: hangs
context.skip('multi-domain cookies', { experimentalSessionSupport: true, experimentalMultiDomain: true }, () => {
beforeEach(() => {
cy.visit('/fixtures/multi-domain.html')
cy.get('a[data-cy="multi-domain-secondary-link"]').click()
})

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

cy.setCookie('foo', 'bar')

cy.getCookie('foo').should('have.property', 'value', 'bar')
cy.getCookies().should('have.length', 1)
})
})

it('.clearCookie()', () => {
cy.switchToDomain('foobar.com', () => {
cy.setCookie('foo', 'bar')
cy.getCookie('foo').should('not.be.null')
cy.clearCookie('foo')
cy.getCookie('foo').should('be.null')
})
})

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

cy.getCookies().should('have.length', 2)
cy.clearCookies()
cy.getCookies().should('be.empty')
})
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// @ts-ignore / session support is needed for visiting about:blank between tests
context('multi-domain files', { experimentalSessionSupport: true, experimentalMultiDomain: true }, () => {
beforeEach(() => {
cy.visit('/fixtures/multi-domain.html')
cy.get('a[data-cy="multi-domain-secondary-link"]').click()
cy.stub(Cypress, 'backend').callThrough()
})

// FIXME: CypressError: `cy.fixture()` timed out waiting `undefinedms` to receive a fixture. No fixture was ever sent by the server.
// at eval (webpack:///../driver/src/cy/commands/fixtures.ts?:89:85)
it.skip('.fixture()', () => {
cy.switchToDomain('foobar.com', () => {
cy.fixture('example.json').then((json) => {
expect(json).to.be.an('object')
expect(json.example).to.be.true
})
})
})

// FIXME: CypressError: `cy.readFile("cypress/fixtures/multi-domain.json")` timed out after waiting `undefinedms`.
// at eval (webpack:///../driver/src/cy/commands/files.ts?:59:89)
it.skip('.readFile()', () => {
cy.switchToDomain('foobar.com', () => {
cy.readFile('cypress/fixtures/example.json').then((json) => {
expect(json).to.be.an('object')
expect(json.example).to.be.true
})
})
})

// FIXME: Cypress.backend.resolves is not a function
// Works when not using switchToDomain
it.skip('.writeFile()', () => {
cy.switchToDomain('foobar.com', () => {
// @ts-ignore
Cypress.backend.resolves({
contents: JSON.stringify({ foo: 'bar' }),
filePath: 'foo.json',
})

cy.writeFile('foo.json', JSON.stringify({ foo: 'bar' })).then(() => {
expect(Cypress.backend).to.be.calledWith(
'write:file',
'foo.json',
JSON.stringify({ foo: 'bar' }),
{
encoding: 'utf8',
flag: 'w',
},
)
})
})
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// @ts-ignore / session support is needed for visiting about:blank between tests
context('multi-domain local storage', { experimentalSessionSupport: true, experimentalMultiDomain: true }, () => {
beforeEach(() => {
cy.visit('/fixtures/multi-domain.html')
cy.get('a[data-cy="multi-domain-secondary-link"]').click()
})

it('.clearLocalStorage()', () => {
cy.switchToDomain('foobar.com', () => {
cy.window().then((win) => {
win.localStorage.setItem('foo', 'bar')
expect(win.localStorage.getItem('foo')).to.eq('bar')
})

cy.clearLocalStorage().should((localStorage) => {
cy.window().then((win) => {
expect(localStorage.length).to.eq(0)
expect(win.localStorage.getItem('foo')).to.be.null
})
})
})
})
})

0 comments on commit efe6316

Please sign in to comment.