Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: uninstall wda with '.xctrunner' suffix for real device #1052

Merged
merged 20 commits into from
Sep 1, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
remove arg for setupCaching
  • Loading branch information
KazuCocoa committed Aug 27, 2019
commit 5b18d3edbe3f65103e247498e7331e97ad93e10e
6 changes: 3 additions & 3 deletions lib/wda/webdriveragent.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ class WebDriverAgent {
*
* @param {string} updatedWDABundleId BundleId you'd like to use
*/
async setupCaching (updatedWDABundleId) {
async setupCaching () {
const status = await this.getStatus();
if (!status || !status.build) {
log.debug('WDA is currently not running. There is nothing to cache');
Expand All @@ -370,12 +370,12 @@ class WebDriverAgent {
upgradedAt,
} = status.build;
// for real device
if (util.hasValue(productBundleIdentifier) && util.hasValue(updatedWDABundleId) && updatedWDABundleId !== productBundleIdentifier) {
if (util.hasValue(productBundleIdentifier) && util.hasValue(this.updatedWDABundleId) && this.updatedWDABundleId !== productBundleIdentifier) {
log.info(`Will uninstall running WDA since it has different bundle id. The actual value is '${productBundleIdentifier}'.`);
return await this.uninstall(productBundleIdentifier);
}
// for simulator
if (util.hasValue(productBundleIdentifier) && !util.hasValue(updatedWDABundleId) && WDA_RUNNER_BUNDLE_ID !== productBundleIdentifier) {
if (util.hasValue(productBundleIdentifier) && !util.hasValue(this.updatedWDABundleId) && WDA_RUNNER_BUNDLE_ID !== productBundleIdentifier) {
log.info(`Will uninstall running WDA since its bundle id is not equal to the default value ${WDA_RUNNER_BUNDLE_ID}`);
return await this.uninstall();
}
Expand Down
62 changes: 45 additions & 17 deletions test/unit/webdriveragent-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,13 @@ describe('setupCaching()', function () {

describe('Xcode 10, simulator', function () {
beforeEach(function () {
opts = {};
wdaDevice = { removeApp: () => {} };
wda = new WebDriverAgent({major: 10}, {device: wdaDevice, realDevice: false});
wdaStub = sinon.stub(wda, 'getStatus');
wdaStubRemoveApp = sinon.stub(wdaDevice, 'removeApp');
});

afterEach(function () {
opts = {};
for (const stub of [wdaStub, wdaStubRemoveApp, getTimestampStub]) {
if (stub) {
stub.reset();
Expand All @@ -141,7 +139,7 @@ describe('setupCaching()', function () {
});
wdaStubRemoveApp.callsFake(_.noop);

await wda.setupCaching(opts.updatedWDABundleId);
await wda.setupCaching();
wdaStub.calledOnce.should.be.true;
wdaStubRemoveApp.notCalled.should.be.true;
_.isUndefined(wda.webDriverAgentUrl).should.be.true;
Expand All @@ -153,7 +151,7 @@ describe('setupCaching()', function () {
});
wdaStubRemoveApp.callsFake(_.noop);

await wda.setupCaching(opts.updatedWDABundleId);
await wda.setupCaching();
wdaStub.calledOnce.should.be.true;
wdaStubRemoveApp.notCalled.should.be.true;
wda.webDriverAgentUrl.should.equal('http://localhost:8100/');
Expand All @@ -165,35 +163,42 @@ describe('setupCaching()', function () {
});
wdaStubRemoveApp.callsFake(_.noop);

await wda.setupCaching(opts.updatedWDABundleId);
await wda.setupCaching();
wdaStub.calledOnce.should.be.true;
wdaStubRemoveApp.withArgs('com.apple.test.WebDriverAgentRunner-Runner').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 () {
opts.updatedWDABundleId = 'com.example.WebDriverAgent';
wdaDevice = { removeApp: () => {} };
wda = new WebDriverAgent({major: 10}, {device: wdaDevice, realDevice: false, updatedWDABundleId: 'com.example.WebDriverAgent'});
wdaStub = sinon.stub(wda, 'getStatus');
wdaStubRemoveApp = sinon.stub(wdaDevice, 'removeApp');
wdaStub.callsFake(function () {
return {build: { time: 'Jun 24 2018 17:08:21', productBundleIdentifier: 'com.example.different.WebDriverAgent' }};
});

wdaStubRemoveApp.callsFake(_.noop);

await wda.setupCaching(opts.updatedWDABundleId);
await wda.setupCaching();
wdaStub.calledOnce.should.be.true;
wdaStubRemoveApp.withArgs('com.apple.test.WebDriverAgentRunner-Runner').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 () {
opts.updatedWDABundleId = 'com.example.WebDriverAgent';
wdaDevice = { removeApp: () => {} };
wda = new WebDriverAgent({major: 10}, {device: wdaDevice, realDevice: false, updatedWDABundleId: 'com.example.WebDriverAgent'});
wdaStub = sinon.stub(wda, 'getStatus');
wdaStubRemoveApp = sinon.stub(wdaDevice, 'removeApp');

wdaStub.callsFake(function () {
return {build: { time: 'Jun 24 2018 17:08:21', productBundleIdentifier: 'com.example.WebDriverAgent' }};
});

wdaStubRemoveApp.callsFake(_.noop);

await wda.setupCaching(opts.updatedWDABundleId);
await wda.setupCaching();
wdaStub.calledOnce.should.be.true;
wdaStubRemoveApp.notCalled.should.be.true;
wda.webDriverAgentUrl.should.equal('http://localhost:8100/');
Expand All @@ -218,43 +223,58 @@ describe('setupCaching()', function () {
getTimestampStub.callsFake(() => '2');
wdaStubRemoveApp.callsFake(_.noop);

await wda.setupCaching(opts.updatedWDABundleId);
await wda.setupCaching();
wdaStub.calledOnce.should.be.true;
wdaStubRemoveApp.withArgs('com.apple.test.WebDriverAgentRunner-Runner').calledOnce.should.be.true;
});

it('should not call uninstall if current revision is the same as the bundled one', async function () {
wdaDevice = { removeApp: () => {} };
wda = new WebDriverAgent({major: 10}, {device: wdaDevice, realDevice: false, updatedWDABundleId: 'something'});
wdaStub = sinon.stub(wda, 'getStatus');
wdaStubRemoveApp = sinon.stub(wdaDevice, 'removeApp');

wdaStub.callsFake(function () {
return {build: { upgradedAt: '1' }};
});
getTimestampStub.callsFake(() => '1');
wdaStubRemoveApp.callsFake(_.noop);

await wda.setupCaching('something');
await wda.setupCaching();
wdaStub.calledOnce.should.be.true;
wdaStubRemoveApp.notCalled.should.be.true;
});

it('should not call uninstall if current revision cannot be retrieved from WDA status', async function () {
wdaDevice = { removeApp: () => {} };
wda = new WebDriverAgent({major: 10}, {device: wdaDevice, realDevice: false, updatedWDABundleId: 'something'});
wdaStub = sinon.stub(wda, 'getStatus');
wdaStubRemoveApp = sinon.stub(wdaDevice, 'removeApp');

wdaStub.callsFake(function () {
return {build: {}};
});
getTimestampStub.callsFake(() => '1');
wdaStubRemoveApp.callsFake(_.noop);

await wda.setupCaching('something');
await wda.setupCaching();
wdaStub.calledOnce.should.be.true;
wdaStubRemoveApp.notCalled.should.be.true;
});

it('should not call uninstall if current revision cannot be retrieved from the file system', async function () {
wdaDevice = { removeApp: () => {} };
wda = new WebDriverAgent({major: 10}, {device: wdaDevice, realDevice: false, updatedWDABundleId: 'something'});
wdaStub = sinon.stub(wda, 'getStatus');
wdaStubRemoveApp = sinon.stub(wdaDevice, 'removeApp');

wdaStub.callsFake(function () {
return {build: { upgradedAt: '1' }};
});
getTimestampStub.callsFake(() => null);
wdaStubRemoveApp.callsFake(_.noop);

await wda.setupCaching('something');
await wda.setupCaching();
wdaStub.calledOnce.should.be.true;
wdaStubRemoveApp.notCalled.should.be.true;
});
Expand Down Expand Up @@ -315,28 +335,36 @@ describe('setupCaching()', function () {
});

it('should call uninstall once since bundle id is different with updatedWDABundleId capability', async function () {
opts.updatedWDABundleId = 'com.example.WebDriverAgent';
wdaDevice = { removeApp: () => {} };
wda = new WebDriverAgent({major: 11}, {device: wdaDevice, realDevice: true, updatedWDABundleId: 'com.example.WebDriverAgent'});
wdaStub = sinon.stub(wda, 'getStatus');
wdaStubRemoveApp = sinon.stub(wdaDevice, 'removeApp');

wdaStub.callsFake(function () {
return {build: { time: 'Jun 24 2018 17:08:21', productBundleIdentifier: 'com.example.different.WebDriverAgent' }};
});

wdaStubRemoveApp.callsFake(_.noop);

await wda.setupCaching(opts.updatedWDABundleId);
await wda.setupCaching();
wdaStub.calledOnce.should.be.true;
wdaStubRemoveApp.withArgs('com.example.different.WebDriverAgent.xctrunner').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 () {
opts.updatedWDABundleId = 'com.example.WebDriverAgent';
wdaDevice = { removeApp: () => {} };
wda = new WebDriverAgent({major: 11}, {device: wdaDevice, realDevice: true, updatedWDABundleId: 'com.example.WebDriverAgent'});
wdaStub = sinon.stub(wda, 'getStatus');
wdaStubRemoveApp = sinon.stub(wdaDevice, 'removeApp');

wdaStub.callsFake(function () {
return {build: { time: 'Jun 24 2018 17:08:21', productBundleIdentifier: 'com.example.WebDriverAgent' }};
});

wdaStubRemoveApp.callsFake(_.noop);

await wda.setupCaching(opts.updatedWDABundleId);
await wda.setupCaching();
wdaStub.calledOnce.should.be.true;
wdaStubRemoveApp.notCalled.should.be.true;
wda.webDriverAgentUrl.should.equal('http://localhost:8100/');
Expand Down