Mobile.TrySetCurrent Method

Applies to TestComplete 15.63, last modified on April 23, 2024

Description

Attempts to set the specified device as current for the test commands working with mobile devices. Unlike SetCurrent, the TrySetCurrent method does not fail if an attempt to set the current device was unsuccessful.

Declaration

Mobile.TrySetCurrent(Name, Index)

Name [in]    Required    String    
Index [in]    Optional    Integer Default value: 1   
Result Boolean

Applies To

The method is applied to the following object:

Parameters

The method has the following parameters:

Name

Specifies the name of the desired device.

Index

Specifies the zero-based index of the device in the collection of devices with the same name.

Result Value

True if the specified device was found and was set as current device for mobile testing, and False otherwise.

Example

The following code example demonstrates how you can set the current device for mobile testing:

JavaScript, JScript

if (Mobile.TrySetCurrent("MyDevice", 1))
{
  // testing device
  ...
}
else
  Log.Message("MyDevice is not found");

Python

if Mobile.TrySetCurrent("MyDevice", 1):
  # testing device
  # ...
else:
  Log.Message("MyDevice is not found")

VBScript

If Mobile.TrySetCurrent("MyDevice", 1) Then
  ' testing device
  ...
Else
  Log.Message("MyDevice is not found")
End If

DelphiScript

if Mobile.TrySetCurrent('MyDevice', 1) then
begin
  // testing device
  ...
end
else
  Log.Message('MyDevice is not found');

C++Script, C#Script

if (Mobile["TrySetCurrent"]("MyDevice", 1))
{
  // testing device
  ...
}
else
  Log["Message"]("MyDevice is not found");

See Also

Testing Android Applications (Legacy)
SetCurrent Method
Device Method

Highlight search results