Skip to content

Commit

Permalink
Added testBinaryPath as an optional config parameter (#1007)
Browse files Browse the repository at this point in the history
* added testBinaryPath as an optional config parameter

* added testBinaryPath doc

* added testBinaryPath tests

* added testBinaryPath to deviceconfiguration doc

* testBinaryPath unit test fixed

* revert DTXLoggingInfra
  • Loading branch information
reime005 authored and rotemmiz committed Nov 11, 2018
1 parent d165117 commit 9044414
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
1 change: 1 addition & 0 deletions detox/src/configurations.mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const validOneDeviceAndSession = {
"configurations": {
"ios.sim.release": {
"binaryPath": "ios/build/Build/Products/Release-iphonesimulator/example.app",
"testBinaryPath": "some/test/path",
"type": "ios.simulator",
"name": "iPhone 7 Plus, iOS 10.2"
}
Expand Down
10 changes: 6 additions & 4 deletions detox/src/devices/Device.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ class Device {

async prepare(params = {}) {
this._binaryPath = this._getAbsolutePath(this._deviceConfig.binaryPath);
this._testBinaryPath = this._deviceConfig.testBinaryPath ? this._getAbsolutePath(this._deviceConfig.testBinaryPath) : null;
this._deviceId = await this.deviceDriver.acquireFreeDevice(this._deviceConfig.name);
this._bundleId = await this.deviceDriver.getBundleIdFromBinary(this._binaryPath);

await this.deviceDriver.prepare();

if (!argparse.getArgValue('reuse')) {
await this.deviceDriver.uninstallApp(this._deviceId, this._bundleId);
await this.deviceDriver.installApp(this._deviceId, this._binaryPath);
await this.deviceDriver.installApp(this._deviceId, this._binaryPath, this._testBinaryPath);
}

if (params.launchApp) {
Expand All @@ -47,7 +48,7 @@ class Device {
if (params.delete) {
await this.deviceDriver.terminate(this._deviceId, this._bundleId);
await this.deviceDriver.uninstallApp(this._deviceId, this._bundleId);
await this.deviceDriver.installApp(this._deviceId, this._binaryPath);
await this.deviceDriver.installApp(this._deviceId, this._binaryPath, this._testBinaryPath);
} else if (params.newInstance) {
await this.deviceDriver.terminate(this._deviceId, this._bundleId);
}
Expand Down Expand Up @@ -136,9 +137,10 @@ class Device {
await this.deviceDriver.terminate(this._deviceId, _bundleId);
}

async installApp(binaryPath) {
async installApp(binaryPath, testBinaryPath) {
const _binaryPath = binaryPath || this._binaryPath;
await this.deviceDriver.installApp(this._deviceId, _binaryPath);
const _testBinaryPath = testBinaryPath || this._testBinaryPath;
await this.deviceDriver.installApp(this._deviceId, _binaryPath, _testBinaryPath);
}

async uninstallApp(bundleId) {
Expand Down
13 changes: 11 additions & 2 deletions detox/src/devices/Device.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,24 @@ describe('Device', () => {

await device.installApp('newAppPath');

expect(device.deviceDriver.installApp).toHaveBeenCalledWith(device._deviceId, 'newAppPath');
expect(device.deviceDriver.installApp).toHaveBeenCalledWith(device._deviceId, 'newAppPath', undefined);
});

it(`installApp() with a custom test app path should use custom test app path`, async () => {
device = validDevice();
fs.existsSync.mockReturnValue(true);

await device.installApp('newAppPath', 'newTestAppPath');

expect(device.deviceDriver.installApp).toHaveBeenCalledWith(device._deviceId, 'newAppPath', 'newTestAppPath');
});

it(`installApp() with no params should use the default path given in configuration`, async () => {
device = validDevice();

await device.installApp();

expect(device.deviceDriver.installApp).toHaveBeenCalledWith(device._deviceId, device._binaryPath);
expect(device.deviceDriver.installApp).toHaveBeenCalledWith(device._deviceId, device._binaryPath, device._testBinaryPath);
});

it(`uninstallApp() with a custom app path should use custom app path`, async () => {
Expand Down
4 changes: 2 additions & 2 deletions detox/src/devices/drivers/AndroidDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ class AndroidDriver extends DeviceDriverBase {
return await this.aapt.getPackageName(apkPath);
}

async installApp(deviceId, binaryPath) {
async installApp(deviceId, binaryPath, testBinaryPath) {
await this.adb.install(deviceId, binaryPath);
await this.adb.install(deviceId, this.getTestApkPath(binaryPath));
await this.adb.install(deviceId, testBinaryPath ? testBinaryPath : this.getTestApkPath(binaryPath));
}

async pressBack(deviceId) {
Expand Down
1 change: 1 addition & 0 deletions docs/APIRef.Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ title: Configuration Options
|Configuration Params|Details|
|---|---|
|`binaryPath`| Relative path to the ipa/app due to be tested (make sure you build the app in a project relative path)|
|`testBinaryPath`| (optional, Android only): relative path to the test app (apk) |
|`type`| Device type, available options are `ios.simulator`, `ios.none`, `android.emulator`, and `android.attached`. |
|`name`| Device name, aligns to the device list avaliable through `xcrun simctl list` for example, this is one line of the output of `xcrun simctl list`: `A3C93900-6D17-4830-8FBE-E102E4BBCBB9 iPhone 7 Shutdown iPhone 7 iOS 10.2`, ir order to choose the first `iPhone 7` regardless of OS version, use `iPhone 7`. <br>To be OS specific use `iPhone 7, iOS 10.2`|
|`build`| **[optional]** Build command (either `xcodebuild`, `react-native run-ios`, etc...), will be later available through detox CLI tool.|
Expand Down

0 comments on commit 9044414

Please sign in to comment.