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

Implemented AttachedAndroidDriver device for connecting to Genymotion #397

Merged
merged 5 commits into from
Nov 19, 2017
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
4 changes: 3 additions & 1 deletion detox/src/Detox.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const Device = require('./devices/Device');
const IosDriver = require('./devices/IosDriver');
const SimulatorDriver = require('./devices/SimulatorDriver');
const EmulatorDriver = require('./devices/EmulatorDriver');
const AttachedAndroidDriver = require('./devices/AttachedAndroidDriver');
const argparse = require('./utils/argparse');
const configuration = require('./configuration');
const Client = require('./client/Client');
Expand All @@ -18,7 +19,8 @@ log.heading = 'detox';
const DEVICE_CLASSES = {
'ios.simulator': SimulatorDriver,
'ios.none': IosDriver,
'android.emulator': EmulatorDriver
'android.emulator': EmulatorDriver,
'android.attached': AttachedAndroidDriver,
};

class Detox {
Expand Down
21 changes: 21 additions & 0 deletions detox/src/devices/AndroidDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,27 @@ class AndroidDriver extends DeviceDriverBase {
return 'android';
}

async findDeviceId(filter) {
const adbDevices = await this.adb.devices();
const filteredDevices = _.filter(adbDevices, filter);

let adbName;
switch (filteredDevices.length) {
case 1:
const adbDevice = filteredDevices[0];
adbName = adbDevice.adbName;
break;
case 0:
throw new Error(`Could not find '${name}' on the currently ADB attached devices,
try restarting adb 'adb kill-server && adb start-server'`);
break;
default:
throw new Error(`Got more than one device corresponding to the name: ${name}`);
}

return adbName;
}

async setURLBlacklist(urlList) {
const call = invoke.call(invoke.Android.Class(EspressoDetox), 'setURLBlacklist', urlList);
await this.invocationManager.execute(call);
Expand Down
19 changes: 19 additions & 0 deletions detox/src/devices/AttachedAndroidDriver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const Emulator = require('./android/Emulator');
const AndroidDriver = require('./AndroidDriver');

class AttachedAndroidDriver extends AndroidDriver {

constructor(client) {
super(client);

this.emulator = new Emulator();
}

async acquireFreeDevice(name) {
const deviceId = await this.findDeviceId({name: name});
await this.adb.unlockScreen(deviceId);
return deviceId;
}
}

module.exports = AttachedAndroidDriver;
22 changes: 3 additions & 19 deletions detox/src/devices/EmulatorDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,9 @@ class EmulatorDriver extends AndroidDriver {

await this.emulator.boot(name);

const adbDevices = await this.adb.devices();
const filteredDevices = _.filter(adbDevices, {type: 'emulator', name: name});

let adbName;
switch (filteredDevices.length) {
case 1:
const adbDevice = filteredDevices[0];
adbName = adbDevice.adbName;
break;
case 0:
throw new Error(`Could not find '${name}' on the currently ADB attached devices,
try restarting adb 'adb kill-server && adb start-server'`);
break;
default:
throw new Error(`Got more than one device corresponding to the name: ${name}`);
}

await this.adb.unlockScreen(adbName);
return adbName;
const deviceId = await this.findDeviceId({type: 'emulator', name: name});
await this.adb.unlockScreen(deviceId);
return deviceId;
}

async shutdown(deviceId) {
Expand Down
7 changes: 7 additions & 0 deletions docs/Introduction.Android.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ Add this part to your `package.json`:
}
```

Following device types could be used to control Android devices:

`android.emulator`. Boot stock SDK emulator with provided `name`, for example `Nexus_5X_API_25`. After booting connect to it.

`android.attached`. Connect to already-attached android device. The device should be listed in the output of `adb devices` command under provided `name`.
Use this type to connect to Genymotion emulator.

### 7. Run the tests

Using the `android.emu.debug` configuration from above, you can invoke it in the standard way.
Expand Down
14 changes: 13 additions & 1 deletion docs/More.AndroidSupportStatus.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,19 @@ All Core APIs are 100% implemented.
## Emulator control
1. **Emulators** are fully supported, to choose an emulator to run your tests on check `emulator -list-avds`. If none exist, create one.
2. **Devices** - Coming soon!
3. **Genymotion** - Coming a bit later...
Copy link
Member

@rotemmiz rotemmiz Nov 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not relate to Genymotion specifically, it can be used with any connected android device, I think it should be emphesized in the docs.

3. **Genymotion**
To utilize Genymotion you should use 'android.attached' as configuration type parameter and Genymotion emulator name as configuration name parameter. For example,

```json
"android": {
"binaryPath": "./android/app/build/outputs/apk/app-debug.apk",
"build": "pushd ./android && ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug && popd",
"type": "android.attached",
"name": "192.168.57.101:5555"
}
```

Type 'android.attached' could be used to connect to any of already attached devices that are visible through 'adb devices' command.

## Mocking
1. Deep Links - Done
Expand Down