Skip to content

Commit d2b0df9

Browse files
caching
1 parent e149958 commit d2b0df9

2 files changed

Lines changed: 21 additions & 17 deletions

File tree

lib/webdriveragent.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -404,12 +404,14 @@ export class WebDriverAgent {
404404
/**
405405
* Reuse running WDA if it has the same bundle id with updatedWDABundleId.
406406
* Or reuse it if it has the default id without updatedWDABundleId.
407+
*
408+
* @returns The WDA URL used for caching on success, or `undefined` if caching was skipped.
407409
*/
408-
async setupCaching(): Promise<void> {
410+
async setupCaching(): Promise<string | undefined> {
409411
const status = await this.getStatus(0);
410412
if (!status || !status.build) {
411413
this.log.debug('WDA is currently not running. There is nothing to cache');
412-
return;
414+
return undefined;
413415
}
414416

415417
const {productBundleIdentifier, upgradedAt} = status.build as any;
@@ -422,7 +424,7 @@ export class WebDriverAgent {
422424
this.log.info(
423425
`Will not reuse running WDA since it has different bundle id. The actual value is '${productBundleIdentifier}'.`,
424426
);
425-
return;
427+
return undefined;
426428
}
427429
// for simulator
428430
if (
@@ -433,7 +435,7 @@ export class WebDriverAgent {
433435
this.log.info(
434436
`Will not reuse running WDA since its bundle id is not equal to the default value ${WDA_RUNNER_BUNDLE_ID}`,
435437
);
436-
return;
438+
return undefined;
437439
}
438440

439441
const actualUpgradeTimestamp = await getWDAUpgradeTimestamp();
@@ -448,16 +450,18 @@ export class WebDriverAgent {
448450
'Will not reuse running WDA since it has different version in comparison to the one ' +
449451
`which is bundled with appium-xcuitest-driver module (${actualUpgradeTimestamp} != ${upgradedAt})`,
450452
);
451-
return;
453+
return undefined;
452454
}
453455

456+
const cachedUrl = this.url.href;
454457
const message = util.hasValue(productBundleIdentifier)
455-
? `Will reuse previously cached WDA instance at '${this.url.href}' with '${productBundleIdentifier}'`
456-
: `Will reuse previously cached WDA instance at '${this.url.href}'`;
458+
? `Will reuse previously cached WDA instance at '${cachedUrl}' with '${productBundleIdentifier}'`
459+
: `Will reuse previously cached WDA instance at '${cachedUrl}'`;
457460
this.log.info(
458461
`${message}. Set the wdaLocalPort capability to a value different from ${this.url.port} if this is an undesired behavior.`,
459462
);
460-
this.webDriverAgentUrl = this.url.href;
463+
this.webDriverAgentUrl = cachedUrl;
464+
return cachedUrl;
461465
}
462466

463467
private setupProxies(sessionId: string): void {

test/unit/webdriveragent-specs.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ describe('WebDriverAgent', function () {
251251
return null;
252252
});
253253

254-
await wda.setupCaching();
254+
expect(await wda.setupCaching()).to.be.undefined;
255255
expect(wdaStub.calledOnce).to.be.true;
256256
expect(wda.webDriverAgentUrl === undefined).to.be.true;
257257
});
@@ -261,7 +261,7 @@ describe('WebDriverAgent', function () {
261261
return {build: {time: 'Jun 24 2018 17:08:21'}};
262262
});
263263

264-
await wda.setupCaching();
264+
expect(await wda.setupCaching()).to.equal('http://127.0.0.1:8100/');
265265
expect(wdaStub.calledOnce).to.be.true;
266266
expect(wda.webDriverAgentUrl).to.equal('http://127.0.0.1:8100/');
267267
});
@@ -276,7 +276,7 @@ describe('WebDriverAgent', function () {
276276
};
277277
});
278278

279-
await wda.setupCaching();
279+
expect(await wda.setupCaching()).to.be.undefined;
280280
expect(wdaStub.calledOnce).to.be.true;
281281
expect(wda.webDriverAgentUrl === undefined).to.be.true;
282282
});
@@ -291,7 +291,7 @@ describe('WebDriverAgent', function () {
291291
};
292292
});
293293

294-
await wda.setupCaching();
294+
expect(await wda.setupCaching()).to.be.undefined;
295295
expect(wdaStub.calledOnce).to.be.true;
296296
expect(wda.webDriverAgentUrl === undefined).to.be.true;
297297
});
@@ -312,7 +312,7 @@ describe('WebDriverAgent', function () {
312312
};
313313
});
314314

315-
await wda.setupCaching();
315+
expect(await wda.setupCaching()).to.equal('http://127.0.0.1:8100/');
316316
expect(wdaStub.calledOnce).to.be.true;
317317
expect(wda.webDriverAgentUrl).to.equal('http://127.0.0.1:8100/');
318318
});
@@ -323,7 +323,7 @@ describe('WebDriverAgent', function () {
323323
});
324324
getTimestampStub.callsFake(async () => 2);
325325

326-
await wda.setupCaching();
326+
expect(await wda.setupCaching()).to.be.undefined;
327327
expect(wdaStub.calledOnce).to.be.true;
328328
expect(wda.webDriverAgentUrl === undefined).to.be.true;
329329
});
@@ -334,7 +334,7 @@ describe('WebDriverAgent', function () {
334334
});
335335
getTimestampStub.callsFake(async () => 1);
336336

337-
await wda.setupCaching();
337+
expect(await wda.setupCaching()).to.equal('http://127.0.0.1:8100/');
338338
expect(wdaStub.calledOnce).to.be.true;
339339
expect(wda.webDriverAgentUrl).to.equal('http://127.0.0.1:8100/');
340340
});
@@ -345,7 +345,7 @@ describe('WebDriverAgent', function () {
345345
});
346346
getTimestampStub.callsFake(async () => 1);
347347

348-
await wda.setupCaching();
348+
expect(await wda.setupCaching()).to.equal('http://127.0.0.1:8100/');
349349
expect(wdaStub.calledOnce).to.be.true;
350350
expect(wda.webDriverAgentUrl).to.equal('http://127.0.0.1:8100/');
351351
});
@@ -356,7 +356,7 @@ describe('WebDriverAgent', function () {
356356
});
357357
getTimestampStub.callsFake(async () => null);
358358

359-
await wda.setupCaching();
359+
expect(await wda.setupCaching()).to.equal('http://127.0.0.1:8100/');
360360
expect(wdaStub.calledOnce).to.be.true;
361361
expect(wda.webDriverAgentUrl).to.equal('http://127.0.0.1:8100/');
362362
});

0 commit comments

Comments
 (0)