Multiple Mobile Device Instances in Single Script
One can connect to multiple mobile devices from inside a script, and interact with them. These devices may be a mix of Android and iOS devices.
_connectDevice
Section titled “_connectDevice”- Since
- Mobile Engine 7.5.0
Modes AndroidiOS
_connectDevice([$deviceId])Arguments
| Name | Type | Description |
|---|---|---|
$deviceId | stringoptional | Android: Id of device to connect to. If not specified, the default device is connected to. iOS: Connection params for a device. See the Details section. If not specified, the default device is connected to. |
Returns
string | Device instanceId. This can be passed to _selectDevice. |
Connects to a Mobile Device. The Mobile device can be an Android Device/Emulator or an iOS Device/Simulator.
To connect to an Android Device/Emulator, Mode has to be set to ANDROID, using _setMode before calling this function.
To connect to an iOS Device/Simulator, Mode has to be set to IOS, using _setMode before calling this function.
Once connected, steps can be directed to different device instances via _selectDevice using deviceInstanceId returned from _connectDevice.
For an iOS Device, the connection params is of the form "platform=iOS,id=" + deviceUUID, where deviceUUID is the UUID of the iOS Device.
For an iOS Simulator, the connection params is of the form "platform=iOS Simulator,id=" + simulatorUUID, where simulatorUUID is the UUID of the iOS Simulator.
To help the end user with the correct connection params, two helper functions have been added in <SAHI_INSTALLATION_FOLDER>/userdata/scripts/sahitests/ios/helperFunctions.sah.
- To get the connection params for an iOS Device, call
connectionParamsForDevice($deviceId)where $deviceId is the Device UUID. - To get the connection params for an iOS Simulator, call
connectionParamsForSimulator($simulatorId)where $simulatorId is the Simulator UUID.
NOTE that helperFunctions.sah needs to be included using _include with the appropriate relative path.
// Android// Default deviceId_setMode("ANDROID");_connectDevice(); // Connects to the default Android Device/Emulator....
// Explicit Emulator Id_setMode("ANDROID");var $id = _connectDevice("192.168.140.101:5555");...
// iOS// Default deviceId_setMode("IOS");_connectDevice(); // Connects to the default iOS Device/Simulator....
// Explicit Simulator Id_setMode("IOS");var $id = _connectDevice(connectionParamsForSimulator("183AA1E6-609B-48AC-9392-6ABF4C31280E"));...
// Explicit Device Id_setMode("IOS");var $id = _connectDevice(connectionParamsForDevice("f1cb463919c46a9b81743eae3aef5fcb8793ec53"));..._selectDevice
Section titled “_selectDevice”- Since
- Mobile Engine 7.5.0
Modes AndroidiOS
_selectDevice([$deviceInstanceId])Arguments
| Name | Type | Description |
|---|---|---|
$deviceInstanceId | stringoptional | deviceInstanceId to forward further steps to. If not specified, steps are forwarded to the default device that the script was started with. |
Returns
null |
Selects the particular device instance. Further steps in the script will be directed to the selected instance.
// Android// Default Device_setMode("ANDROID");_connectDevice(); // Connects to the default Android Device/Emulator._selectDevice(); // Selects the default Android Device/Emulator._mActivateApplication("com.android.settings", true);...
// Explicit Emulator Id_setMode("ANDROID");var $id = _connectDevice("192.168.140.101:5555");_selectDevice($id);_mActivateApplication("com.android.settings", true);...
// iOS// Default Device_setMode("IOS");_connectDevice(); // Connects to the default iOS Device/Simulator._selectDevice(); // Selects the default iOS Device/Simulator._mActivateApplication("com.apple.Preferences", true);...
// Explicit Simulator Id_setMode("IOS");var $id = _connectDevice(connectionParamsForSimulator("183AA1E6-609B-48AC-9392-6ABF4C31280E"));_selectDevice($id);_mActivateApplication("com.apple.Preferences", true);...
// Explicit Device Id_setMode("IOS");var $id = _connectDevice(connectionParamsForDevice("f1cb463919c46a9b81743eae3aef5fcb8793ec53"));_selectDevice($id);_mActivateApplication("com.apple.Preferences", true);...
