forked from appium/WebDriverAgent
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebdriveragent-specs.js
More file actions
412 lines (353 loc) · 14.6 KB
/
webdriveragent-specs.js
File metadata and controls
412 lines (353 loc) · 14.6 KB
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
import { BOOTSTRAP_PATH } from '../../lib/utils';
import { WebDriverAgent } from '../../lib/webdriveragent';
import * as utils from '../../lib/utils';
import path from 'path';
import _ from 'lodash';
import sinon from 'sinon';
const fakeConstructorArgs = {
device: 'some sim',
platformVersion: '9',
host: 'me',
port: '5000',
realDevice: false
};
const defaultAgentPath = path.resolve(BOOTSTRAP_PATH, 'WebDriverAgent.xcodeproj');
const customBootstrapPath = '/path/to/wda';
const customAgentPath = '/path/to/some/agent/WebDriverAgent.xcodeproj';
const customDerivedDataPath = '/path/to/some/agent/DerivedData/';
describe('Constructor', function () {
let chai;
before(async function() {
chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.should();
chai.use(chaiAsPromised.default);
});
it('should have a default wda agent if not specified', function () {
let agent = new WebDriverAgent({}, fakeConstructorArgs);
agent.bootstrapPath.should.eql(BOOTSTRAP_PATH);
agent.agentPath.should.eql(defaultAgentPath);
});
it('should have custom wda bootstrap and default agent if only bootstrap specified', function () {
let agent = new WebDriverAgent({}, _.defaults({
bootstrapPath: customBootstrapPath,
}, fakeConstructorArgs));
agent.bootstrapPath.should.eql(customBootstrapPath);
agent.agentPath.should.eql(path.resolve(customBootstrapPath, 'WebDriverAgent.xcodeproj'));
});
it('should have custom wda bootstrap and agent if both specified', function () {
let agent = new WebDriverAgent({}, _.defaults({
bootstrapPath: customBootstrapPath,
agentPath: customAgentPath,
}, fakeConstructorArgs));
agent.bootstrapPath.should.eql(customBootstrapPath);
agent.agentPath.should.eql(customAgentPath);
});
it('should have custom derivedDataPath if specified', function () {
let agent = new WebDriverAgent({}, _.defaults({
derivedDataPath: customDerivedDataPath
}, fakeConstructorArgs));
agent.xcodebuild.derivedDataPath.should.eql(customDerivedDataPath);
});
});
describe('launch', function () {
it('should use webDriverAgentUrl override and return current status', async function () {
const override = 'http://mockurl:8100/';
const args = Object.assign({}, fakeConstructorArgs);
args.webDriverAgentUrl = override;
const agent = new WebDriverAgent({}, args);
const wdaStub = sinon.stub(agent, 'getStatus');
wdaStub.callsFake(function () {
return {build: 'data'};
});
await agent.launch('sessionId').should.eventually.eql({build: 'data'});
agent.url.href.should.eql(override);
agent.jwproxy.server.should.eql('mockurl');
agent.jwproxy.port.should.eql(8100);
agent.jwproxy.base.should.eql('');
agent.jwproxy.scheme.should.eql('http');
agent.noSessionProxy.server.should.eql('mockurl');
agent.noSessionProxy.port.should.eql(8100);
agent.noSessionProxy.base.should.eql('');
agent.noSessionProxy.scheme.should.eql('http');
wdaStub.reset();
});
});
describe('use wda proxy url', function () {
it('should use webDriverAgentUrl wda proxy url', async function () {
const override = 'http://127.0.0.1:8100/aabbccdd';
const args = Object.assign({}, fakeConstructorArgs);
args.webDriverAgentUrl = override;
const agent = new WebDriverAgent({}, args);
const wdaStub = sinon.stub(agent, 'getStatus');
wdaStub.callsFake(function () {
return {build: 'data'};
});
await agent.launch('sessionId').should.eventually.eql({build: 'data'});
agent.url.port.should.eql('8100');
agent.url.hostname.should.eql('127.0.0.1');
agent.url.path.should.eql('/aabbccdd');
agent.jwproxy.server.should.eql('127.0.0.1');
agent.jwproxy.port.should.eql(8100);
agent.jwproxy.base.should.eql('/aabbccdd');
agent.jwproxy.scheme.should.eql('http');
agent.noSessionProxy.server.should.eql('127.0.0.1');
agent.noSessionProxy.port.should.eql(8100);
agent.noSessionProxy.base.should.eql('/aabbccdd');
agent.noSessionProxy.scheme.should.eql('http');
});
});
describe('get url', function () {
it('should use default WDA listening url', function () {
const args = Object.assign({}, fakeConstructorArgs);
const agent = new WebDriverAgent({}, args);
agent.url.href.should.eql('http://127.0.0.1:8100/');
agent.setupProxies('mysession');
agent.jwproxy.scheme.should.eql('http');
agent.noSessionProxy.scheme.should.eql('http');
});
it('should use default WDA listening url with emply base url', function () {
const wdaLocalPort = '9100';
const wdaBaseUrl = '';
const args = Object.assign({}, fakeConstructorArgs);
args.wdaBaseUrl = wdaBaseUrl;
args.wdaLocalPort = wdaLocalPort;
const agent = new WebDriverAgent({}, args);
agent.url.href.should.eql('http://127.0.0.1:9100/');
agent.setupProxies('mysession');
agent.jwproxy.scheme.should.eql('http');
agent.noSessionProxy.scheme.should.eql('http');
});
it('should use customised WDA listening url', function () {
const wdaLocalPort = '9100';
const wdaBaseUrl = 'http://mockurl';
const args = Object.assign({}, fakeConstructorArgs);
args.wdaBaseUrl = wdaBaseUrl;
args.wdaLocalPort = wdaLocalPort;
const agent = new WebDriverAgent({}, args);
agent.url.href.should.eql('http://mockurl:9100/');
agent.setupProxies('mysession');
agent.jwproxy.scheme.should.eql('http');
agent.noSessionProxy.scheme.should.eql('http');
});
it('should use customised WDA listening url with slash', function () {
const wdaLocalPort = '9100';
const wdaBaseUrl = 'http://mockurl/';
const args = Object.assign({}, fakeConstructorArgs);
args.wdaBaseUrl = wdaBaseUrl;
args.wdaLocalPort = wdaLocalPort;
const agent = new WebDriverAgent({}, args);
agent.url.href.should.eql('http://mockurl:9100/');
agent.setupProxies('mysession');
agent.jwproxy.scheme.should.eql('http');
agent.noSessionProxy.scheme.should.eql('http');
});
it('should use the given webDriverAgentUrl and ignore other params', function () {
const args = Object.assign({}, fakeConstructorArgs);
args.wdaBaseUrl = 'http://mockurl/';
args.wdaLocalPort = '9100';
args.webDriverAgentUrl = 'https://127.0.0.1:8100/';
const agent = new WebDriverAgent({}, args);
agent.url.href.should.eql('https://127.0.0.1:8100/');
});
it('should set scheme to https for https webDriverAgentUrl', function () {
const args = Object.assign({}, fakeConstructorArgs);
args.webDriverAgentUrl = 'https://127.0.0.1:8100/';
const agent = new WebDriverAgent({}, args);
agent.setupProxies('mysession');
agent.jwproxy.scheme.should.eql('https');
agent.noSessionProxy.scheme.should.eql('https');
});
});
describe('setupCaching()', function () {
let wda;
let wdaStub;
let wdaStubUninstall;
const getTimestampStub = sinon.stub(utils, 'getWDAUpgradeTimestamp');
beforeEach(function () {
wda = new WebDriverAgent('1');
wdaStub = sinon.stub(wda, 'getStatus');
wdaStubUninstall = sinon.stub(wda, 'uninstall');
});
afterEach(function () {
for (const stub of [wdaStub, wdaStubUninstall, getTimestampStub]) {
if (stub) {
stub.reset();
}
}
});
it('should not call uninstall since no Running WDA', async function () {
wdaStub.callsFake(function () {
return null;
});
wdaStubUninstall.callsFake(_.noop);
await wda.setupCaching();
wdaStub.calledOnce.should.be.true;
wdaStubUninstall.notCalled.should.be.true;
_.isUndefined(wda.webDriverAgentUrl).should.be.true;
});
it('should not call uninstall since running WDA has only time', async function () {
wdaStub.callsFake(function () {
return {build: { time: 'Jun 24 2018 17:08:21' }};
});
wdaStubUninstall.callsFake(_.noop);
await wda.setupCaching();
wdaStub.calledOnce.should.be.true;
wdaStubUninstall.notCalled.should.be.true;
wda.webDriverAgentUrl.should.equal('http://127.0.0.1:8100/');
});
it('should call uninstall once since bundle id is not default without updatedWDABundleId capability', async function () {
wdaStub.callsFake(function () {
return {build: { time: 'Jun 24 2018 17:08:21', productBundleIdentifier: 'com.example.WebDriverAgent' }};
});
wdaStubUninstall.callsFake(_.noop);
await wda.setupCaching();
wdaStub.calledOnce.should.be.true;
wdaStubUninstall.calledOnce.should.be.true;
_.isUndefined(wda.webDriverAgentUrl).should.be.true;
});
it('should call uninstall once since bundle id is different with updatedWDABundleId capability', async function () {
wdaStub.callsFake(function () {
return {build: { time: 'Jun 24 2018 17:08:21', productBundleIdentifier: 'com.example.different.WebDriverAgent' }};
});
wdaStubUninstall.callsFake(_.noop);
await wda.setupCaching();
wdaStub.calledOnce.should.be.true;
wdaStubUninstall.calledOnce.should.be.true;
_.isUndefined(wda.webDriverAgentUrl).should.be.true;
});
it('should not call uninstall since bundle id is equal to updatedWDABundleId capability', async function () {
wda = new WebDriverAgent('1', { updatedWDABundleId: 'com.example.WebDriverAgent' });
wdaStub = sinon.stub(wda, 'getStatus');
wdaStubUninstall = sinon.stub(wda, 'uninstall');
wdaStub.callsFake(function () {
return {build: { time: 'Jun 24 2018 17:08:21', productBundleIdentifier: 'com.example.WebDriverAgent' }};
});
wdaStubUninstall.callsFake(_.noop);
await wda.setupCaching();
wdaStub.calledOnce.should.be.true;
wdaStubUninstall.notCalled.should.be.true;
wda.webDriverAgentUrl.should.equal('http://127.0.0.1:8100/');
});
it('should call uninstall if current revision differs from the bundled one', async function () {
wdaStub.callsFake(function () {
return {build: { upgradedAt: '1' }};
});
getTimestampStub.callsFake(() => '2');
wdaStubUninstall.callsFake(_.noop);
await wda.setupCaching();
wdaStub.calledOnce.should.be.true;
wdaStubUninstall.calledOnce.should.be.true;
});
it('should not call uninstall if current revision is the same as the bundled one', async function () {
wdaStub.callsFake(function () {
return {build: { upgradedAt: '1' }};
});
getTimestampStub.callsFake(() => '1');
wdaStubUninstall.callsFake(_.noop);
await wda.setupCaching();
wdaStub.calledOnce.should.be.true;
wdaStubUninstall.notCalled.should.be.true;
});
it('should not call uninstall if current revision cannot be retrieved from WDA status', async function () {
wdaStub.callsFake(function () {
return {build: {}};
});
getTimestampStub.callsFake(() => '1');
wdaStubUninstall.callsFake(_.noop);
await wda.setupCaching();
wdaStub.calledOnce.should.be.true;
wdaStubUninstall.notCalled.should.be.true;
});
it('should not call uninstall if current revision cannot be retrieved from the file system', async function () {
wdaStub.callsFake(function () {
return {build: { upgradedAt: '1' }};
});
getTimestampStub.callsFake(() => null);
wdaStubUninstall.callsFake(_.noop);
await wda.setupCaching();
wdaStub.calledOnce.should.be.true;
wdaStubUninstall.notCalled.should.be.true;
});
describe('uninstall', function () {
let device;
let wda;
let deviceGetBundleIdsStub;
let deviceRemoveAppStub;
beforeEach(function () {
device = {
getUserInstalledBundleIdsByBundleName: () => {},
removeApp: () => {}
};
wda = new WebDriverAgent('1', {device});
deviceGetBundleIdsStub = sinon.stub(device, 'getUserInstalledBundleIdsByBundleName');
deviceRemoveAppStub = sinon.stub(device, 'removeApp');
});
afterEach(function () {
for (const stub of [deviceGetBundleIdsStub, deviceRemoveAppStub]) {
if (stub) {
stub.reset();
}
}
});
it('should not call uninstall', async function () {
deviceGetBundleIdsStub.callsFake(() => []);
await wda.uninstall();
deviceGetBundleIdsStub.calledOnce.should.be.true;
deviceRemoveAppStub.notCalled.should.be.true;
});
it('should call uninstall once', async function () {
const uninstalledBundIds = [];
deviceGetBundleIdsStub.callsFake(() => ['com.appium.WDA1']);
deviceRemoveAppStub.callsFake((id) => uninstalledBundIds.push(id));
await wda.uninstall();
deviceGetBundleIdsStub.calledOnce.should.be.true;
deviceRemoveAppStub.calledOnce.should.be.true;
uninstalledBundIds.should.eql(['com.appium.WDA1']);
});
it('should call uninstall twice', async function () {
const uninstalledBundIds = [];
deviceGetBundleIdsStub.callsFake(() => ['com.appium.WDA1', 'com.appium.WDA2']);
deviceRemoveAppStub.callsFake((id) => uninstalledBundIds.push(id));
await wda.uninstall();
deviceGetBundleIdsStub.calledOnce.should.be.true;
deviceRemoveAppStub.calledTwice.should.be.true;
uninstalledBundIds.should.eql(['com.appium.WDA1', 'com.appium.WDA2']);
});
});
});
describe('usePreinstalledWDA related functions', function () {
describe('bundleIdForXctest', function () {
it('should have xctrunner automatically', function () {
const args = Object.assign({}, fakeConstructorArgs);
args.updatedWDABundleId = 'io.appium.wda';
const agent = new WebDriverAgent({}, args);
agent.bundleIdForXctest.should.equal('io.appium.wda.xctrunner');
});
it('should have xctrunner automatically with default bundle id', function () {
const args = Object.assign({}, fakeConstructorArgs);
const agent = new WebDriverAgent({}, args);
agent.bundleIdForXctest.should.equal('com.facebook.WebDriverAgentRunner.xctrunner');
});
it('should allow an empty string as xctrunner suffix', function () {
const args = Object.assign({}, fakeConstructorArgs);
args.updatedWDABundleId = 'io.appium.wda';
args.updatedWDABundleIdSuffix = '';
const agent = new WebDriverAgent({}, args);
agent.bundleIdForXctest.should.equal('io.appium.wda');
});
it('should allow an empty string as xctrunner suffix with default bundle id', function () {
const args = Object.assign({}, fakeConstructorArgs);
args.updatedWDABundleIdSuffix = '';
const agent = new WebDriverAgent({}, args);
agent.bundleIdForXctest.should.equal('com.facebook.WebDriverAgentRunner');
});
it('should have an arbitrary xctrunner suffix', function () {
const args = Object.assign({}, fakeConstructorArgs);
args.updatedWDABundleId = 'io.appium.wda';
args.updatedWDABundleIdSuffix = '.customsuffix';
const agent = new WebDriverAgent({}, args);
agent.bundleIdForXctest.should.equal('io.appium.wda.customsuffix');
});
});
});