Mobile.ConnectDevice Method

Applies to TestComplete 14.80, last modified on April 13, 2021

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(HubUrlCapabilitiesConnectTimeoutSec)

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 controls 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.

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

function Connect_Android_Appium()
{
  var server = "http://my_appium_server:4723/wd/hub";
  var capabilities = {
    deviceName: "MyAndroidDevice",
    platformVersion: 10,
    platformName: "android",
    automationName: "UIAutomator2",
    app: "/tests/MyApp.apk",
    newCommandTimeout: 600
  };

  Mobile.ConnectDevice(server, capabilities);

}

Python

def Connect_Android_Appium():
  server = "http://my_appium_server:4723/wd/hub"
  capabilities = {
    "deviceName": "MyAndroidDevice",
    "platformVersion": 10,
    "platformName": "android",
    "automationName": "UIAutomator2",
    "app": "/tests/MyApp.apk",
    "newCommandTimeout": 600
  }

  Mobile.ConnectDevice(server, capabilities)

VBScript

Sub Connect_Android_Appium()
  server = "http://my_appium_server:4723/wd/hub"
  capabilities = "{""deviceName"":""MyAndroidDevice"",""platformVersion"":10,""platformName"":""android"",""automationName"":""UIAutomator2"",""app"":""\/tests\/MyApp.apk"",""newCommandTimeout"":600}"
  Call Mobile.ConnectDevice(server, capabilities)

End Sub

DelphiScript

procedure Connect_Android_Appium();
var server, capabilities;
begin
  server := 'http://my_appium_server:4723/wd/hub';
  capabilities := '{"deviceName":"MyAndroidDevice","platformVersion":10,"platformName":"android","automationName":"UIAutomator2","app":"\/tests\/MyApp.apk","newCommandTimeout":600}';

  Mobile.ConnectDevice(server, capabilities);
end;

C++Script, C#Script

function Connect_Android_Appium()
{
  var server = "http://my_appium_server:4723/wd/hub";
  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

Highlight search results