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

feat: Add utils exports #903

Merged
merged 3 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 9 additions & 4 deletions lib/commands/app-management.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ export async function background(seconds) {
* @param {import('../driver').AndroidDriverOpts?} [opts=null]
* @returns {Promise<void>}
*/
export async function resetApp(opts = null) {
export async function resetAUT(opts = null) {
const {
app,
appPackage,
Expand Down Expand Up @@ -397,7 +397,12 @@ export async function resetApp(opts = null) {
});
}

export async function installApk(opts = null) {
/**
* @this {AndroidDriver}
* @param {import('../driver').AndroidDriverOpts?} [opts=null]
* @returns {Promise<void>}
*/
export async function installAUT(opts = null) {
const {
app,
appPackage,
Expand All @@ -414,7 +419,7 @@ export async function installApk(opts = null) {
}

if (fullReset) {
await this.resetApp(opts);
await this.resetAUT(opts);
return;
}

Expand All @@ -430,7 +435,7 @@ export async function installApk(opts = null) {
!wasUninstalled && appState !== this.adb.APP_INSTALL_STATE.NOT_INSTALLED;
if (fastReset && isInstalledOverExistingApp) {
this.log.info(`Performing fast reset on '${appPackage}'`);
await this.resetApp(opts);
await this.resetAUT(opts);
}
}

Expand Down
8 changes: 4 additions & 4 deletions lib/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ import {
getThirdPartyPackages,
uninstallOtherPackages,
installOtherApks,
installApk,
resetApp,
installAUT,
resetAUT,
background,
getCurrentActivity,
getCurrentPackage,
Expand Down Expand Up @@ -375,8 +375,8 @@ class AndroidDriver
getThirdPartyPackages = getThirdPartyPackages;
uninstallOtherPackages = uninstallOtherPackages;
installOtherApks = installOtherApks;
installApk = installApk;
resetApp = resetApp;
installAUT = installAUT;
resetAUT = resetAUT;
background = background;
getCurrentActivity = getCurrentActivity;
getCurrentPackage = getCurrentPackage;
Expand Down
7 changes: 7 additions & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ import {install} from 'source-map-support';
install();

import {AndroidDriver} from './driver';
import { getChromePkg } from './commands/context/helpers';
import { parseArray, requireArgs } from './utils';
export const utils = {
getChromePkg,
parseArray,
requireArgs,
} as const;
export type * from './commands/types';
export {ANDROID_DRIVER_CONSTRAINTS as commonCapConstraints} from './constraints';
export * from './driver';
Expand Down
30 changes: 15 additions & 15 deletions test/unit/commands/app-management-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ describe('App Management', function () {
});
});

describe('resetApp', function() {
describe('resetAUT', function() {
const localApkPath = 'local';
const pkg = 'pkg';

Expand All @@ -207,21 +207,21 @@ describe('App Management', function () {
});

it('should complain if opts arent passed correctly', async function () {
await driver.resetApp({}).should.be.rejectedWith(/appPackage/);
await driver.resetAUT({}).should.be.rejectedWith(/appPackage/);
});
it('should be able to do full reset', async function () {
sandbox.stub(driver.adb, 'install').withArgs(localApkPath).onFirstCall();
sandbox.stub(driver.adb, 'forceStop').withArgs(pkg).onFirstCall();
sandbox.stub(driver.adb, 'isAppInstalled').withArgs(pkg).onFirstCall().returns(true);
sandbox.stub(driver.adb, 'uninstallApk').withArgs(pkg).onFirstCall();
await driver.resetApp({app: localApkPath, appPackage: pkg});
await driver.resetAUT({app: localApkPath, appPackage: pkg});
});
it('should be able to do fast reset', async function () {
sandbox.stub(driver.adb, 'isAppInstalled').withArgs(pkg).onFirstCall().returns(true);
sandbox.stub(driver.adb, 'forceStop').withArgs(pkg).onFirstCall();
sandbox.stub(driver.adb, 'clear').withArgs(pkg).onFirstCall().returns('Success');
sandbox.stub(driver.adb, 'grantAllPermissions').withArgs(pkg).onFirstCall();
await driver.resetApp({
await driver.resetAUT({
app: localApkPath,
appPackage: pkg,
fastReset: true,
Expand All @@ -234,11 +234,11 @@ describe('App Management', function () {
sandbox.stub(driver.adb, 'clear').throws();
sandbox.stub(driver.adb, 'uninstallApk').throws();
sandbox.stub(driver.adb, 'install').withArgs(localApkPath).onFirstCall();
await driver.resetApp({app: localApkPath, appPackage: pkg, fastReset: true});
await driver.resetAUT({app: localApkPath, appPackage: pkg, fastReset: true});
});
});

describe('installApk', function () {
describe('installAUT', function () {
//use mock appium capabilities for this test
const opts = {
app: 'local',
Expand All @@ -251,36 +251,36 @@ describe('App Management', function () {
});

it('should complain if appPackage is not passed', async function () {
await driver.installApk({}).should.be.rejectedWith(/appPackage/);
await driver.installAUT({}).should.be.rejectedWith(/appPackage/);
});
it('should install/upgrade and reset app if fast reset is set to true', async function () {
sandbox.stub(driver.adb, 'installOrUpgrade')
.withArgs(opts.app, opts.appPackage)
.onFirstCall()
.returns({wasUninstalled: false, appState: 'sameVersionInstalled'});
sandbox.stub(driver, 'resetApp').onFirstCall();
await driver.installApk(Object.assign({}, opts, {fastReset: true}));
sandbox.stub(driver, 'resetAUT').onFirstCall();
await driver.installAUT(Object.assign({}, opts, {fastReset: true}));
});
it('should reinstall app if full reset is set to true', async function () {
sandbox.stub(driver.adb, 'installOrUpgrade').throws();
sandbox.stub(driver, 'resetApp').onFirstCall();
await driver.installApk(Object.assign({}, opts, {fastReset: true, fullReset: true}));
sandbox.stub(driver, 'resetAUT').onFirstCall();
await driver.installAUT(Object.assign({}, opts, {fastReset: true, fullReset: true}));
});
it('should not run reset if the corresponding option is not set', async function () {
sandbox.stub(driver.adb, 'installOrUpgrade')
.withArgs(opts.app, opts.appPackage)
.onFirstCall()
.returns({wasUninstalled: true, appState: 'sameVersionInstalled'});
sandbox.stub(driver, 'resetApp').throws();
await driver.installApk(opts);
sandbox.stub(driver, 'resetAUT').throws();
await driver.installAUT(opts);
});
it('should install/upgrade and skip fast resetting the app if this was the fresh install', async function () {
sandbox.stub(driver.adb, 'installOrUpgrade')
.withArgs(opts.app, opts.appPackage)
.onFirstCall()
.returns({wasUninstalled: false, appState: 'notInstalled'});
sandbox.stub(driver, 'resetApp').throws();
await driver.installApk(Object.assign({}, opts, {fastReset: true}));
sandbox.stub(driver, 'resetAUT').throws();
await driver.installAUT(Object.assign({}, opts, {fastReset: true}));
});
});
describe('installOtherApks', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import sinon from 'sinon';
import ADB from 'appium-adb';
import B from 'bluebird';
import { AndroidDriver } from '../../../lib/driver';
import { setMockLocationApp } from '../../../lib/commands/geolocation';

Expand Down
Loading