Mobile.Device Method

Applies to TestComplete 15.40, last modified on July 05, 2022

Description

The Mobile.Device method returns an object for the specified connected mobile device.

To get the current device, which was earlier set by the Mobile.SetCurrent or Mobile.TrySetCurrent method, use Mobile.Device without parameters. See examples at the end of the topic.

Declaration

Mobile.Device(Name, Index)

Name [in]    Optional    String Default value: Empty string   
Index [in]    Optional    Integer Default value: 1   
Result An AndroidDevice object or an iOSDevice object

Applies To

The method is applied to the following object:

Parameters

The method has the following parameters:

Name

The device name that you see in the Object Browser and in the Mobile Screen window. For example, "Nexus 7", "iPhone 5S", "emulator-5554", "VirtualBox" and so on.

Index

If several connected devices have the same name, specify the device’s 1-based index among the devices with the same name.

Result Value

The AndroidDevice object that corresponds to the specified Android device or the iOSDevice object that corresponds to the specified iOS device.

Remarks

The Mobile.Device method without parameters returns the current device.

If the specified device is not found, the method posts an error to the test log and returns an object with the Connected property set to False.

Example

The following example works with a specific mobile device:

JavaScript, JScript

Mobile.Device("Nexus 7").PressButton(mbkHome);

Python

Mobile.Device("Nexus 7").PressButton(mbkHome)

VBScript

Call Mobile.Device("Nexus 7").PressButton(mbkHome)

DelphiScript

Mobile.Device('Nexus 7').PressButton(mbkHome);

C++Script, C#Script

Mobile["Device"]("Nexus 7")["PressButton"](mbkHome);

To refer to the current device, use Mobile.Device without parameters:

JavaScript, JScript

Mobile.SetCurrent("Nexus 7");
Mobile.Device().PressButton(mbkHome);

Python

Mobile.SetCurrent("Nexus 7")
Mobile.Device().PressButton(mbkHome)

VBScript

Call Mobile.SetCurrent("Nexus 7")
Call Mobile.Device.PressButton(mbkHome)

DelphiScript

Mobile.SetCurrent('Nexus 7');
Mobile.Device.PressButton(mbkHome);

C++Script, C#Script

Mobile["SetCurrent"]("Nexus 7");
Mobile["Device"]()["PressButton"](mbkHome);

See Also

Testing Android Applications (Legacy)
Testing iOS Applications (Legacy)
AndroidDevice Object
iOSDevice Object
TrySetCurrent Method
SetCurrent Method

Highlight search results