-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
user_agent_override.cy.ts
50 lines (45 loc) · 1.79 KB
/
user_agent_override.cy.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
// @see https://github.com/cypress-io/cypress/issues/22953
// We modify the user agent to strip cypress and electron out of the user agent string to appear more chrome-like
// this only happens in electron and when the experimentalModifyObstructiveThirdPartyCode flag is set to true
describe('user agent override', {
browser: 'electron',
}, () => {
it('persists modified user agent after cy.visit', () => {
cy.wrap(window.navigator.userAgent).as('userAgentBefore')
cy.visit('/fixtures/primary-origin.html')
cy.wrap(window.navigator.userAgent).then((userAgentAfter) => {
cy.get('@userAgentBefore').then((userAgentBefore) => {
expect(userAgentBefore).to.equal(userAgentAfter)
})
})
})
it('persists modified user agent after cy.reload', () => {
cy.wrap(window.navigator.userAgent).as('userAgentBefore')
cy.visit('/fixtures/primary-origin.html')
cy.reload()
cy.wrap(window.navigator.userAgent).then((userAgentAfter) => {
cy.get('@userAgentBefore').then((userAgentBefore) => {
expect(userAgentBefore).to.equal(userAgentAfter)
})
})
})
it('persists modified user agent after cy.go', () => {
cy.visit('/fixtures/primary-origin.html')
cy.get('a[data-cy="cross-origin-secondary-link"]').click()
cy.origin('http://foobar.com:3500', {
args: {
userAgentBefore: window.navigator.userAgent,
},
}, ({ userAgentBefore }) => {
cy.visit('http://www.foobar.com:3500/fixtures/dom.html')
cy.go('back')
cy.wrap(window.navigator.userAgent).then((userAgentAfter) => {
expect(userAgentBefore).to.equal(userAgentAfter)
})
cy.go('forward')
cy.wrap(window.navigator.userAgent).then((userAgentAfter) => {
expect(userAgentBefore).to.equal(userAgentAfter)
})
})
})
})