Working With Android Device Settings During Test Run (Legacy)

Applies to TestComplete 15.62, last modified on March 19, 2024
The information below concerns legacy mobile tests that work with mobile devices connected to the local computer. For new mobile tests, we recommend using the newer cloud-compatible approach.

In your tests, you may need to check how the application works on devices with different settings setup. This topic describes how you can access the device settings during the test run.

Available Options

TestComplete provides the following methods and properties to access the device's settings:

In order for TestComplete to work with these options, TestComplete Android Agent must be installed and running on the device.
Method or property Possible actions
AllowMockLocations Gets or sets "AllowMockLocations" developer setting status. Read/Write. Boolean.
BluetoothEnabled Gets or sets Bluetooth status. Read/Write. Boolean.
ChangeLocale Sets the locale of the device.
CurrentLocaleName Gets the name of the current locale. Read only. String.
GPSEnabled Gets or sets GPS status. Read/Write. Boolean.
WiFiEnabled Gets or sets Wi-Fi status. Read/Write. Boolean.

Notes

  • All properties that return boolean data type return True if the setting is enabled and False otherwise.

  • The locale name specified by the ChangeLocale method must be available on the device and follow the ISO 639-1 and ISO 3166-1 standards.

Working With Device Settings From Keyword Tests

To work with the device's settings in keyword tests, call the required method by using the Call Object Method, Run Code Snippet or Run Script Routine operations.

Changing device properties from keyword test

Working With Device Settings From Scripts

Changing Settings

If the setting you want to change corresponds to the read/write property in TestComplete, you can assign the required value to it. For example:

JavaScript, JScript

Mobile.Device().GPS.AllowMockLocations = true;

Python

Mobile.Device().GPS.AllowMockLocations = True;

VBScript

Mobile.Device.GPS.AllowMockLocations = true

DelphiScript

Mobile.Device.GPS.AllowMockLocations := true;

C++Script, C#Script

Mobile["Device"].GPS["AllowMockLocations"] = true;

If the setting corresponds to the read only property in TestComplete, you can use the method that changes it. For example:

JavaScript, JScript

Mobile.Device().ChangeLocale("en", "GB");

Python

Mobile.Device().ChangeLocale("en", "GB");

VBScript

Call Mobile.Device.ChangeLocale("en", "GB")

DelphiScript

Mobile.Device.ChangeLocale('en', 'GB');

C++Script, C#Script

Mobile["Device"]["ChangeLocale"]("en", "GB");

Checking Settings

You can check the current state of the setting during your test run and act accordingly. For example:

JavaScript, JScript

function Test()
{
  Mobile.SetCurrent("MI 2")
  if (Mobile.Device().Connections.WiFiEnabled)
    Log.Message("WiFi is enabled")
  else
    Log.Message("WiFi is disabled")
}

Python

def Test():
  Mobile.SetCurrent("MI 2")
  if (Mobile.Device().Connections.WiFiEnabled):
    Log.Message("WiFi is enabled")
  else:
    Log.Message("WiFi is disabled")

VBScript

Sub Test()
  Mobile.SetCurrent("MI 2")
  If Mobile.Device.Connections.WiFiEnabled Then
    Log.Message("WiFi is enabled")
  Else
    Log.Message("WiFi is disabled")
  End If
End Sub

DelphiScript

procedure Test();
begin
  Mobile.SetCurrent('MI 2');
  if Mobile.Device.Connections.WiFiEnabled then
    Log.Message('WiFi is enabled')
  else
    Log.Message('WiFi is disabled')
end;

C++Script, C#Script

function Test()
{
  Mobile["SetCurrent"]("MI 2")
  if (Mobile["Device"].Connections["WiFiEnabled"])
    Log["Message"]("WiFi is enabled")
  else
    Log["Message"]("WiFi is disabled")
}

See Also

About Testing Android Applications (Legacy)

Highlight search results