-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
testCdpCommands.js
139 lines (122 loc) · 3.55 KB
/
testCdpCommands.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
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
const path = require('path');
const assert = require('assert');
const MockServer = require('../../../lib/mockserver.js');
const Mocks = require('../../../lib/command-mocks');
const mockery = require('mockery');
const common = require('../../../common.js');
const {settings} = common;
const NightwatchClient = common.require('index.js');
describe('cdp commands test', function() {
beforeEach(function(done) {
mockery.enable({useCleanCache: true, warnOnReplace: false, warnOnUnregistered: false});
this.server = MockServer.init();
this.server.on('listening', () => {
done();
});
});
afterEach(function(done) {
mockery.deregisterAll();
mockery.resetCache();
mockery.disable();
this.server.close(function() {
done();
});
});
it('reset cdp connection after each session is created', function() {
const testsPath = [path.join(__dirname, '../../../apidemos/cdp')];
let resetConnectionCalled = 0;
mockery.registerMock('../transport/selenium-webdriver/cdp.js', {
getConnection: function(...args) {
return Promise.resolve();
},
resetConnection: function() {
resetConnectionCalled += 1;
}
});
Mocks
.createNewW3CSession({
persist: true,
browserName: 'chrome',
postdata: {
capabilities: {firstMatch: [{}], alwaysMatch: {browserName: 'chrome', 'goog:chromeOptions': {}}}
}
})
.navigateTo({url: 'http://localhost', persist: true});
const globals = {
calls: 0,
waitForConditionPollInterval: 50,
waitForConditionTimeout: 120,
retryAssertionTimeout: 1000,
reporter(results) {
// cdp connection is reset once for each session (two test suites).
assert.strictEqual(resetConnectionCalled, 2);
if (results.lastError) {
throw results.lastError;
}
}
};
return NightwatchClient.runTests(testsPath, settings({
desiredCapabilities: {
browserName: 'chrome'
},
selenium_host: null,
output: false,
skip_testcases_on_fail: false,
globals
}));
});
it('reset cdp connection after each selenium session is created', function() {
const testsPath = [path.join(__dirname, '../../../apidemos/cdp')];
let resetConnectionCalled = 0;
Mocks
.createChromeSession({
headless: false,
times: 2
});
MockServer.addMock({
url: '/wd/hub/session/13521-10219-202/url',
method: 'POST',
postdata: JSON.stringify({
url: 'http://localhost'
}),
response: {
value: null
},
times: 2
});
mockery.registerMock('../transport/selenium-webdriver/cdp.js', {
getConnection: function(...args) {
return Promise.resolve();
},
resetConnection: function() {
resetConnectionCalled += 1;
}
});
const globals = {
calls: 0,
waitForConditionPollInterval: 50,
waitForConditionTimeout: 120,
retryAssertionTimeout: 1000,
reporter(results) {
// cdp connection is reset once for each session (two test suites).
assert.strictEqual(resetConnectionCalled, 2);
if (results.lastError) {
throw results.lastError;
}
}
};
return NightwatchClient.runTests(testsPath, settings({
desiredCapabilities: {
browserName: 'chrome'
},
selenium: {
host: 'localhost',
port: 10195,
start_process: false
},
output: false,
skip_testcases_on_fail: false,
globals
}));
});
});