Other Ways to Check Images on Screen

Applies to TestComplete 15.69, last modified on November 13, 2024

There can be situations where you cannot use mobile checkpoints to verify data in your tests. In this case, you can make use of the following approaches:

Verifying the Full Screen

In your tests, you can get an image of the full screen of your mobile device and verify it, for example, to make sure that the expected activity has started.

To get an image of the full screen, use the Mobile.Device.Desktop.Picture method.

After you get the image, you can verify it in several ways:

The sample code below demonstrates how to capture the entire screen of a connected mobile device and how to compare the actual screen with the baseline copy:

JavaScript, JScript

function screenCompare()
{

  // Set the current device
  Mobile.SetCurrent("MyDevice");

  // Get the image of the full screen
  var pict = Mobile.Device().Desktop.Picture();

  // Save the image to a file and add it to the Regions collection
  pict.SaveToFile("screenimage.png");
  Regions.AddPicture(pict, "MobileScreen");

  ...

  // Verify the screen image
  Regions.MobileScreen.Check(Mobile.Device().Desktop.Picture());
}

Python

def screenCompare():
  # Set current device
  Mobile.SetCurrent("MyDevice")

  # Get the full screen image
  pict = Mobile.Device().Desktop.Picture()

  # Save the full screen image to the file and add it to the Regions collection
  pict.SaveToFile("screenimage.png")
  Regions.AddPicture(pict, "MobileScreen")

  ...

  # Verify screen image
  Regions.MobileScreen.Check(Mobile.Device().Desktop.Picture())

VBScript

Sub screenCompare

  ' Set the current device
  Mobile.SetCurrent "MyDevice"

  ' Get the image of the full screen
  Set pict = Mobile.Device.Desktop.Picture

  ' Save the image to a file and add it to the Regions collection
  pict.SaveToFile "screenimage.png"
  Regions.AddPicture pict, "MobileScreen"

  ...

  ' Verify the screen image
  Regions.MobileScreen.Check(Mobile.Device.Desktop.Picture())
End Sub

DelphiScript

procedure screenCompare();
var pict;
begin

  // Set the current device
  Mobile.SetCurrent('MyDevice');

  // Get the image of the full screen
  pict := Mobile.Device.Desktop.Picture();

  // Save the image to a file and add it to the Regions collection
  pict.SaveToFile('screenimage.png');
  Regions.AddPicture(pict, 'MobileScreen');

  ...

  // Verify the screen image
  Regions.MobileScreen.Check(Mobile.Device.Desktop.Picture());
end;

C++Script, C#Script

function screenCompare()
{

  // Set the current device
  Mobile["SetCurrent"]("MyDevice");

  // Get the image of the full screen
  var pict = Mobile["Device"]["Desktop"]["Picture"]();

  // Save the image to a file and add it to the Regions collection
  pict.SaveToFile("screenimage.png");
  Regions["AddPicture"](pict, "MobileScreen");

  ...

  // Verify the screen image
  Regions["MobileScreen"]["Check"](Mobile["Device"]["Desktop"]["Picture"]());
}

To compare the actual screen with the baseline copy in keyword tests, use the Region Checkpoint operation.

The sample code below demonstrates how to capture the entire screen of a connected mobile device and how to use the Picture.Compare method to verify the image:

JavaScript, JScript

function VerifyScreen()
{

  //Set the current device
  Mobile.SetCurrent("MyDevice");

  // Obtain the Picture object that corresponds to the full screen
  var p = Mobile.Device().Desktop.Picture();

  ...

  // Compare the actual screen with its baseline copy
  if (!(p.Compare(Mobile.Device().Desktop.Picture())))
    Log.Error("Screen image has changed")
}

Python

def VerifyScreen():

  # Set current device
  Mobile.SetCurrent("MyDevice")

  # Obtain Picture object that corresponds to the full screen
  p = Mobile.Device().Desktop.Picture()

  ...

  # Compare the actual screen with its baseline copy
  if not (p.Compare(Mobile.Device().Desktop.Picture())):
    Log.Error("Screen image has changed")

VBScript

Sub VerifyScreen

  'Set the current device
  Mobile.SetCurrent("MyDevice")

  ' Obtain the Picture object that corresponds to the full screen
  Set p = Mobile.Device.Desktop.Picture

  ...

  ' Compare the actual screen with its baseline copy
  If Not (p.Compare(Mobile.Device.Desktop.Picture())) Then
    Log.Error("Screen image has changed")
  End If
End Sub

DelphiScript


procedure VerifyScreen();
var p:OleVariant;
begin

  //Set the current device
  Mobile.SetCurrent('MyDevice');

  // Obtain the Picture object that corresponds to the full screen
  p := Mobile.Device.Desktop.Picture();

  ...

  // Compare the actual screen with its baseline copy
  if not (p.Compare(Mobile.Device.Desktop.Picture())) then
    Log.Error('Screen image has changed')
end;

C++Script, C#Script

function VerifyScreen()
 {

  //Set the current device
  Mobile["SetCurrent"]("MyDevice");

  // Obtain the Picture object that corresponds to the full screen
  var p = Mobile["Device"]["Desktop"]["Picture"]();

  ...

  // Compare the actual screen with its baseline copy
  if (!(p["Compare"](Mobile["Device"]["Desktop"]["Picture"]())))
    Log["Error"]("Screen image has changed")
}

To call scripting methods in your keyword tests, use the Call Object Method and Run Code Snippet operations.

Note: In order for the examples to work, the project must have the Stores | Region collection.

Verifying Individual Controls

You can use a region checkpoint to check whether your tested control exists on the device screen:

  1. Save the image of the desired control to the Regions collection.

  2. Create a region checkpoint that will verify the control’s image.

The sample code below demonstrates how to use a region checkpoint to verify the image of an individual control:

JavaScript, JScript

function ControlImageVerify()
{
  // Set the current device
  Mobile.SetCurrent("MyDevice");
  
  // Get the control image
  var pict = Mobile.Device().Desktop.Picture(60, 80, 75, 75)

  // Save the control image to a file and add it to the Regions collection
  pict.SaveToFile("AppButton.png");
  Regions.AddPicture(pict, "AppButton");

  ...

  // Verify the control image
  Regions.AppButton.Check(pict);
}

Python

def ControlImageVerify():
  # Set current device
  Mobile.SetCurrent("MyDevice")
  
  # Get the control image
  pict = Mobile.Device().Desktop.Picture(60, 80, 75, 75)

  # Save the control image to the file and add it to the Regions collection
  pict.SaveToFile("AppButton.png")
  Regions.AddPicture(pict, "AppButton")

  ...

  # Verify control image
  Regions.AppButton.Check(pict)

VBScript

Sub ControlImageVerify
  ' Set the current device
   Mobile.SetCurrent "MyDevice"
  
  ' Get the control image
  Set pict = Mobile.Device.Desktop.Picture(60, 80, 75, 75)

  ' Save the control image to a file and add it to the Regions collection
   pict.SaveToFile "AppButton.png"
   Regions.AddPicture pict, "AppButton"

  ...

  ' Verify the control image
   Regions.AppButton.Check(pict)
End Sub

DelphiScript

procedure ControlImageVerify();
var pict;
begin
  // Set the current device
  Mobile.SetCurrent('MyDevice');
  
  // Get the control image
  pict := Mobile.Device.Desktop.Picture(60, 80, 75, 75);

  // Save the control image to a file and add it to the Regions collection
  pict.SaveToFile('AppButton.png');
  Regions.AddPicture(pict, 'AppButton');

  ...

  // Verify the control image
  Regions.AppButton.Check(pict);
end;

C++Script, C#Script

function ControlImageVerify()
{
  // Set the current device
  Mobile["SetCurrent"]("MyDevice");
  
  // Get the control image
  var pict = Mobile["Device"]["Desktop"]["Picture"](60, 80, 75, 75)

  // Save the control image to a file and add it to the Regions collection
  pict["SaveToFile"]("AppButton.png");
  Regions["AddPicture"](pict, "AppButton");

  ...

  // Verify the control image
  Regions["AppButton"]["Check"](pict);
}

Note: In order for the examples to work, the project must have the Stores | Region collection.

Verifying Object Properties

If you have access to objects and properties of your tested application, you can check the values of your tested control’s properties rather than checking the control’s appearance on screen.

To learn how to get access to application internals, see:

To check an individual property, you can use a property checkpoint. To check several properties at once, you can use an object checkpoint.

The sample code below demonstrates how to use an object checkpoint to check the state of the tested application:

JavaScript, JScript

function TestDevice()
{

  // Set the current device
  Mobile.SetCurrent("MyDevice", 0);

  // Save the values of the specified properties to the Objects collection
  var p = Mobile.Device().DeviceInfo;
  var propertySet = "Manufacturer Product Model";
  Objects.Save(p, "propSet", propertySet);

  ...

  // Compare the property values with the baseline copy
  if (!(Objects.Compare(p, "propSet")))
    Log.Error("Wrong current device")
}

Python

def TestDevice():

  # Set current device
  Mobile.SetCurrent("MyDevice", 1)

  # Save the values of the specified properties to the Objects collection
  p = Mobile.Device().DeviceInfo
  propertySet = "Manufacturer Product Model"
  Objects.Save(p, "propSet", propertySet)

  ...

  # Compare property values with the baseline copy
  if not Objects.Compare(p, "propSet"):
    Log.Error("Wrong current device")

VBScript

Sub TestDevice

  ' Set the current device
  Call Mobile.SetCurrent("MyDevice", 0)

  ' Save the values of the specified properties to the Objects collection
  Set p = Mobile.Device.DeviceInfo
  propertySet = "Manufacturer Product Model"
  Objects.Save p, "propSet", propertySet

  ...

  ' Compare the property values with the baseline copy
  If Not Objects.Compare(p, "propSet") Then
    Log.Error("Wrong current device")
  End If
End Sub

DelphiScript

procedure TestDevice();
var p, propertySet: OleVariant;
begin

  // Set the current device
  Mobile.SetCurrent('MyDevice', 0);

  // Save the values of the specified properties to the Objects collection
  p := Mobile.Device.DeviceInfo;
  propertySet := 'Manufacturer Product Model';
  Objects.Save(p, 'propSet', propertySet);

  ...

  // Compare the property values with the baseline copy
  if not (Objects.Compare(p, 'propSet')) then
    Log.Error('Wrong current device');
end;

C++Script, C#Script

function TestDevice()
{

  // Set the current device
  Mobile["SetCurrent"]("MyDevice", 0);

  // Save the values of the specified properties to the Objects collection
  var p = Mobile["Device"]["DeviceInfo"];
  var propertySet = "Manufacturer Product Model";
  Objects["Save"](p, "propSet", propertySet);

  ...

  // Compare the property values with the baseline copy
  if (!(Objects["Compare"](p, "propSet")))
    Log["Error"]("Wrong current device")
}

See Also

About Mobile Checkpoints
About Region Checkpoints
About Property Checkpoints
About Object Checkpoints
Mobile Checkpoints

Highlight search results