Description
Connects to the specified mobile device and opens a testing session on it. The target testing session will match the specified desired capabilities.
Declaration
Mobile.ConnectDevice(HubUrl, Capabilities, ConnectTimeoutSec)
HubUrl | [in] | Required | String | |
Capabilities | [in] | Required | Object | |
ConnectTimeoutSec | [in] | Optional | Integer | Default value: 180 |
Result | A Device object |
Applies To
The method is applied to the following object:
Parameters
The method has the following parameters:
HubUrl
Specifies the URL of the server that manages the target mobile device. It can be either the BitBar hub or an Appium server running on your local computer or on a remote computer in your local network.
Capabilities
The object that describes a testing session you want to open on your mobile device. For the list of required capabilities, see Supported capabilities.
ConnectTimeoutSec
Specifies the period (in seconds) for which the method waits for the session to open. If the parameter is not specified, the default value (180 seconds) will be used.
Result Value
The Device
object that provides access to the mobile device (a real device or an emulator) on which the session is opened.
Note: All further method calls with the same capabilities will not reconnect to the specified device. The method will return the same Device
object and reset the state of the tested application on it.
Example
The following code sample shows how to connect to an Appium server and to open a testing session on an Android device:
JavaScript
{
var server = "http://localhost:4723/wd/hub"; // or "http://localhost:4723/" for older versions
var capabilities = {
deviceName: "MyAndroidDevice",
platformVersion: 10,
platformName: "android",
automationName: "UIAutomator2",
app: "/tests/MyApp.apk",
newCommandTimeout: 600
};
Mobile.ConnectDevice(server, capabilities);
}
Python
server = "http://localhost:4723/wd/hub" # or "http://localhost:4723/" for older versions
capabilities = {
"deviceName": "MyAndroidDevice",
"platformVersion": 10,
"platformName": "android",
"automationName": "UIAutomator2",
"app": "/tests/MyApp.apk",
"newCommandTimeout": 600
}
Mobile.ConnectDevice(server, capabilities)
VBScript
server = "http://localhost:4723/wd/hub" // or "http://localhost:4723/" for older versions
capabilities = "{""deviceName"":""MyAndroidDevice"",""platformVersion"":10,""platformName"":""android"",""automationName"":""UIAutomator2"",""app"":""\/tests\/MyApp.apk"",""newCommandTimeout"":600}"
Call Mobile.ConnectDevice(server, capabilities)
End Sub
DelphiScript
var server, capabilities;
begin
server := 'http://localhost:4723/wd/hub'; // or "http://localhost:4723/" for older versions
capabilities := '{"deviceName":"MyAndroidDevice","platformVersion":10,"platformName":"android","automationName":"UIAutomator2","app":"\/tests\/MyApp.apk","newCommandTimeout":600}';
Mobile.ConnectDevice(server, capabilities);
end;
C++Script, C#Script
{
var server = "http://localhost:4723/wd/hub"; // or "http://localhost:4723/" for older versions
var capabilities = "{\"deviceName\":\"MyAndroidDevice\",\"platformVersion\":10,\"platformName\":\"android\",\"automationName\":\"UIAutomator2\",\"app\":\"\\/tests\\/MyApp.apk\",\"newCommandTimeout\":600}";
Mobile["ConnectDevice"](server, capabilities);
}
See Also
Mobile Object
Disconnect Method
Connecting to Mobile Devices and Opening Testing Sessions
Run Remote Device Operation