-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
multi_domain_cypress_api.spec.ts
241 lines (203 loc) · 7.45 KB
/
multi_domain_cypress_api.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
const { assertLogLength } = require('../../../support/utils')
describe('cy.origin Cypress API', () => {
beforeEach(() => {
cy.visit('/fixtures/multi-domain.html')
cy.get('a[data-cy="cross-origin-secondary-link"]').click()
})
context('Commands', () => {
it('adds a custom command', () => {
cy.origin('http://foobar.com:3500', () => {
// @ts-ignore
Cypress.Commands.add('foo', () => 'bar')
// @ts-ignore
cy.foo().should('equal', 'bar')
})
// persists added command through spec bridge
cy.origin('http://foobar.com:3500', () => {
// @ts-ignore
cy.foo().should('equal', 'bar')
})
})
it('overwrites an existing command in the spec bridge', () => {
cy.origin('http://foobar.com:3500', () => {
// @ts-ignore
Cypress.Commands.overwrite('foo', () => 'baz')
// @ts-ignore
cy.foo().should('equal', 'baz')
})
// persists overwritten command through spec bridge
cy.origin('http://foobar.com:3500', () => {
// @ts-ignore
cy.foo().should('equal', 'baz')
})
})
})
context('Keyboard', () => {
it('does NOT sync defaults', () => {
const defaults = Cypress.Keyboard.defaults({
keystrokeDelay: 30,
})
cy.origin('http://foobar.com:3500', { args: defaults }, (primaryKeyboardDefaults) => {
const crossOriginKeyboardDefaults = Cypress.Keyboard.defaults({})
expect(crossOriginKeyboardDefaults).to.not.deep.equal(primaryKeyboardDefaults)
})
})
it('allows a user to configure defaults', () => {
cy.origin('http://foobar.com:3500', () => {
const crossOriginKeyboardDefaults = Cypress.Keyboard.defaults({
keystrokeDelay: 60,
})
expect(crossOriginKeyboardDefaults).to.deep.include({
keystrokeDelay: 60,
})
})
// persists default configuration changes through spec bridge
cy.origin('http://foobar.com:3500', () => {
const crossOriginKeyboardDefaults = Cypress.Keyboard.defaults({})
expect(crossOriginKeyboardDefaults).to.deep.include({
keystrokeDelay: 60,
})
})
})
})
context('Screenshot', () => {
it('does NOT sync defaults', () => {
Cypress.Screenshot.defaults({
blackout: ['foo'],
overwrite: true,
onBeforeScreenshot: () => undefined,
onAfterScreenshot: () => undefined,
})
cy.origin('http://foobar.com:3500', () => {
const crossOriginScreenshotDefaults = Cypress.Screenshot.defaults({})
expect(crossOriginScreenshotDefaults).to.not.deep.include({
blackout: ['foo'],
overwrite: true,
onBeforeScreenshot: () => undefined,
onAfterScreenshot: () => undefined,
})
})
})
it('allows a user to configure defaults', () => {
cy.origin('http://foobar.com:3500', () => {
const crossOriginScreenshotDefaults = Cypress.Screenshot.defaults({
blackout: ['foo'],
overwrite: true,
})
expect(crossOriginScreenshotDefaults).to.deep.include({
blackout: ['foo'],
overwrite: true,
})
})
// persists default configuration changes through spec bridge
cy.origin('http://foobar.com:3500', () => {
const crossOriginScreenshotDefaults = Cypress.Screenshot.defaults({})
expect(crossOriginScreenshotDefaults).to.deep.include({
blackout: ['foo'],
overwrite: true,
})
})
})
})
context('dom', () => {
it('provides a sanity check that the dom API exists on Cypress.*', () => {
cy.origin('http://foobar.com:3500', () => {
cy.get('[data-cy="dom-check"]').then(($el) => {
expect(Cypress.dom.isAttached($el)).to.be.true
})
})
})
})
// TODO: Before implementing, understand how Cypress.session.* and cy.session() are supposed to function within the context of cy.origin
context.skip('session', () => {
it('clearAllSavedSessions() functions as expected', () => {
cy.origin('http://foobar.com:3500', () => {
Cypress.session.clearAllSavedSessions()
})
})
})
context('properties', () => {
it('has arch property synced from primary', () => {
cy.origin('http://foobar.com:3500', { args: Cypress.arch }, (theArch) => {
expect(Cypress.arch).to.equal(theArch)
})
})
it('has browser property synced from primary', () => {
cy.origin('http://foobar.com:3500', { args: Cypress.browser }, (theBrowser) => {
expect(Cypress.browser).to.deep.equal(theBrowser)
})
})
it('has currentTest property synced from primary', () => {
cy.origin('http://foobar.com:3500', { args: Cypress.currentTest }, (theCurrentTest) => {
expect(Cypress.currentTest).to.deep.equal(theCurrentTest)
})
})
it('has platform property synced from primary', () => {
cy.origin('http://foobar.com:3500', { args: Cypress.platform }, (thePlatform) => {
expect(Cypress.platform).to.equal(thePlatform)
})
})
it('has testingType property synced from primary', () => {
cy.origin('http://foobar.com:3500', { args: Cypress.testingType }, (theTestingType) => {
expect(Cypress.testingType).to.deep.equal(theTestingType)
})
})
it('has spec property synced from primary', () => {
cy.origin('http://foobar.com:3500', { args: Cypress.spec }, (theSpec) => {
expect(Cypress.spec).to.deep.equal(theSpec)
})
})
})
context('methods', () => {
it('isCy()', () => {
cy.origin('http://foobar.com:3500', () => {
expect(Cypress.isCy(cy)).to.be.true
})
})
it('isBrowser()', () => {
cy.origin('http://foobar.com:3500', { args: Cypress.browser }, (theBrowser) => {
expect(Cypress.isBrowser(theBrowser.name)).to.equal(true)
})
})
it('log()', () => {
const logs: Cypress.Log[] = []
cy.on('log:added', (attrs, log: Cypress.Log) => {
logs.push(log)
})
cy.origin('http://foobar.com:3500', () => {
Cypress.log({
name: 'log',
message: 'test log',
})
})
.then(() => {
assertLogLength(logs, 3)
expect(logs[1].get('name')).to.equal('log')
expect(logs[1].get('message')).to.equal('test log')
})
})
})
context('not supported', () => {
it('throws an error when a user attempts to configure Cypress.Server.defaults() inside of cy.origin', (done) => {
cy.on('fail', (err) => {
expect(err.message).to.equal('`Cypress.Server.*` has been deprecated and use is not supported in the `cy.origin()` callback. Consider using `cy.intercept()` (outside of the callback) instead.')
expect(err.docsUrl).to.equal('https://on.cypress.io/intercept')
done()
})
cy.origin('http://foobar.com:3500', () => {
Cypress.Server.defaults({})
})
})
it('throws an error when a user attempts to configure Cypress.Cookies.preserveOnce() inside of cy.origin', (done) => {
cy.on('fail', (err) => {
expect(err.message).to.equal('`Cypress.Cookies.preserveOnce` use is not supported in the `cy.origin()` callback. Consider using `cy.session()` (outside of the callback) instead.')
expect(err.docsUrl).to.equal('https://on.cypress.io/session')
done()
})
cy.origin('http://foobar.com:3500', () => {
// @ts-ignore
Cypress.Cookies.preserveOnce({})
})
})
})
})