AndroidFile Object

Applies to TestComplete 15.10, last modified on December 15, 2021
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.

Description

The AndroidFile object provides the following information about a file stored on the connected Android device:

Property Description
Name String. Read-only. Returns the name of the file (with the extension).
Path String. Read-only. Returns the path to the file (with the file name and extension).
Location String. Read-only. Returns the path to the folder where the file is stored.
Size Integrer. Read-only. Returns the size of the file in bytes.

To obtain the AndroidFile object in tests, use the FindFiles method of the FileSystemManager or AndroidFolder objects.

Example

The sample code below demonstrates how to search the system/app folder on the connected Android device for all .apk files and posts the names of the found files to the test log:

JavaScript, JScript

function Test()
{

  var fileSystemManager = Mobile.Device("MyDevice").FileSystemManager;
  var apkFiles = fileSystemManager.FindFiles("system/app/*.apk");

  if (apkFiles.Count > 0)
  {
    while (apkFiles.HasNext())
    {
      var apkFile = apkFiles.Next();
      Log.Message(apkFile.Name);
    }

  }
  else
    Log.Warning("No files were found.");

}

Python

def Test():
  fileSystemManager = Mobile.Device("MyDevice").FileSystemManager
  apkFiles = fileSystemManager.FindFiles("system/app/*.apk")

  if apkFiles.Count > 0:
    while apkFiles.HasNext:
      apkFile = apkFiles.Next
      Log.Message(apkFile.Name)
  else:
    Log.Warning("No files were found.")

VBScript

Sub Test

  Set fileSystemManager = Mobile.Device("MyDevice").FileSystemManager
  Set apkFiles = fileSystemManager.FindFiles("system/app/*.apk")

  If apkFiles.Count > 0 Then
    While apkFiles.HasNext
      Set apkFile = apkFiles.Next
      Log.Message(apkFile.Name)
    Wend

  Else
    Log.Warning("No files were found.")
  End If

End Sub

DelphiScript

procedure Test();
var fileSystemManager, apkFiles, apkFile;
begin

fileSystemManager := Mobile.Device('MyDevice').FileSystemManager;
apkFiles := fileSystemManager.FindFiles('system/app/*.apk');

if apkFiles.Count > 0 then
  begin
    while apkFiles.HasNext do
    begin
      apkFile := apkFiles.Next;
      Log.Message(apkFile.Name);
    end;

    end
else
    Log.Warning('No files were found.');

end;

C++Script, C#Script

function Test()
{

  var fileSystemManager = Mobile["Device"]("MyDevice")["FileSystemManager"];
  var apkFiles = fileSystemManager["FindFiles"]("system/app/*.apk");

  if (apkFiles["Count"] > 0)
  {
    while (apkFiles["HasNext"]())
    {
      var apkFile = apkFiles["Next"]();
      Log["Message"](apkFile["Name"]);
    }

  }
  else
    Log["Warning"]("No files were found.");

}

See Also

FindFiles Method
FileSystemManager Object
AndroidDevice Object
Testing Android Applications (Legacy)

Highlight search results