-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
/
Copy pathoffline._cy.js
81 lines (72 loc) · 2.16 KB
/
offline._cy.js
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
// https://github.com/cypress-io/cypress-example-recipes/blob/master/examples/server-communication__offline/cypress/integration/offline-spec.js
const goOffline = () => {
cy.log('**go offline**')
.then(() => {
return Cypress.automation('remote:debugger:protocol', {
command: 'Network.enable',
});
})
.then(() => {
return Cypress.automation('remote:debugger:protocol', {
command: 'Network.emulateNetworkConditions',
params: {
offline: true,
latency: -1,
downloadThroughput: -1,
uploadThroughput: -1,
},
});
});
};
const goOnline = () => {
// disable offline mode, otherwise we will break our tests :)
cy.log('**go online**')
.then(() => {
// https://chromedevtools.github.io/devtools-protocol/1-3/Network/#method-emulateNetworkConditions
return Cypress.automation('remote:debugger:protocol', {
command: 'Network.emulateNetworkConditions',
params: {
offline: false,
latency: -1,
downloadThroughput: -1,
uploadThroughput: -1,
},
});
})
.then(() => {
return Cypress.automation('remote:debugger:protocol', {
command: 'Network.disable',
});
});
};
describe('offline', () => {
describe('site', { browser: '!firefox' }, () => {
// make sure we get back online, even if a test fails
// otherwise the Cypress can lose the browser connection
beforeEach(goOnline);
afterEach(goOnline);
it('shows /migrate/ page', () => {
const url = '/migrate/';
const text = 'Migrate';
cy.visit(url);
cy.get('h1').contains(text);
goOffline();
cy.visit(url);
cy.get('h1').contains(text);
// click `guides` link
cy.get('a[title="guides"]').click();
cy.get('h1').contains('Guides');
});
it('open print dialog when accessing /printable url', () => {
const url = '/migrate/printable';
cy.visit(url, {
onBeforeLoad: (win) => {
cy.stub(win, 'print');
},
});
cy.window().then((win) => {
expect(win.print).to.be.calledOnce;
});
});
});
});