Skip to content

Commit

Permalink
feat: add activeAppInfo (#1025)
Browse files Browse the repository at this point in the history
* feat: add activeAppInfo

* use const instead of let
  • Loading branch information
KazuCocoa committed Aug 4, 2019
1 parent fe9f6e2 commit 211d17d
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 2 deletions.
15 changes: 15 additions & 0 deletions lib/commands/activeAppInfo.js
@@ -0,0 +1,15 @@
const extensions = {}, commands = {};

/**
* Returns ActiveApp info.
*
* @returns {Object} The response of `/wda/activeAppInfo'`
* @throws {Error} if an error raised by command
*/
commands.mobileGetActiveAppInfo = async function mobileGetActiveAppInfo () {
return await this.proxyCommand('/wda/activeAppInfo', 'GET');
};

Object.assign(extensions, commands);
export { commands };
export default extensions;
2 changes: 1 addition & 1 deletion lib/commands/deviceInfo.js
@@ -1,4 +1,4 @@
let extensions = {}, commands = {};
const extensions = {}, commands = {};

/**
* Returns device info.
Expand Down
1 change: 1 addition & 0 deletions lib/commands/execute.js
Expand Up @@ -70,6 +70,7 @@ extensions.executeMobile = async function executeMobile (mobileCommand, opts = {

batteryInfo: 'mobileGetBatteryInfo',
deviceInfo: 'mobileGetDeviceInfo',
activeAppInfo: 'mobileGetActiveAppInfo',

pressButton: 'mobilePressButton',

Expand Down
4 changes: 3 additions & 1 deletion lib/commands/index.js
Expand Up @@ -23,6 +23,7 @@ import clipboardExtensions from './clipboard';
import certificateExtensions from './certificate';
import batteryExtensions from './battery';
import deviceInfoExtensions from './deviceInfo';
import activeAppnfoExtensions from './activeAppInfo';
import cookiesExtensions from './cookies';
import biometricExtensions from './biometric';
import keychainsExtensions from './keychains';
Expand All @@ -37,7 +38,8 @@ Object.assign(commands, contextCommands, executeExtensions,
alertExtensions, screenshotExtensions, pasteboardExtensions, locationExtensions,
lockExtensions, recordScreenExtensions, appManagementExtensions, performanceExtensions,
clipboardExtensions, certificateExtensions, batteryExtensions, cookiesExtensions,
biometricExtensions, keychainsExtensions, permissionsExtensions, deviceInfoExtensions
biometricExtensions, keychainsExtensions, permissionsExtensions, deviceInfoExtensions,
activeAppnfoExtensions
);

export default commands;
44 changes: 44 additions & 0 deletions test/unit/commands/activeAppInfo-specs.js
@@ -0,0 +1,44 @@
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import sinon from 'sinon';
import XCUITestDriver from '../../../';

chai.should();
chai.use(chaiAsPromised);

describe('get activeapp commands', function () {
const driver = new XCUITestDriver();
// give the driver a spy-able proxy object
driver.wda = {jwproxy: {command: () => {}}};
let proxyStub;

this.beforeEach(function () {
proxyStub = sinon.stub(driver.wda.jwproxy, 'command');
});

afterEach(function () {
proxyStub.restore();
});

it('get active app info', async function () {
proxyStub.returns({
pid: 15438,
name: '',
bundleId: 'com.apple.DocumentsApp',
processArguments: { env: { HAPPY: 'testing' }, args: ['happy', 'testing'] }
});

const out = await driver.mobileGetActiveAppInfo();
out.pid.should.eq(15438);
out.name.should.eq('');
out.bundleId.should.eq('com.apple.DocumentsApp');
out.processArguments.env.HAPPY.should.eq('testing');
out.processArguments.args[0].should.eq('happy');
out.processArguments.args[1].should.eq('testing');
});

it('get active app info raise an error if the endpoint raises error', async function () {
proxyStub.throws();
await driver.mobileGetActiveAppInfo().should.eventually.be.rejected;
});
});

0 comments on commit 211d17d

Please sign in to comment.