Navigating Through Application Pages

Applies to TestComplete 14.93, last modified on September 16, 2021

Page controls in iOS applications display a number of dots that correspond to pages available in the application. A user can navigate through pages in the application by touching the dots of the page control.

When testing iOS applications, you may need to navigate through its pages by using the page control. To do this in tests, you can simulate touches on the page control, or you can use methods of the iOS PageControl test object that TestComplete automatically associates with the control.

Using Specific Methods

To select the page preceding or following the page that is currently selected in the page control, you can use the Back and Next methods of the iOS PageControl test object. To select an arbitrary page (specified by its index), you can call the SelectPage method of the iOS PageControl object.

The code sample below demonstrates how to use the methods to navigate through pages:

JavaScript, JScript

function Test()
{
  // Select the mobile device
  Mobile.SetCurrent("iPhone");
  // Obtain the PageControl object
  var p = Mobile.Device().Process("SampleApp");
  var pageControl = p.Window().PageControl();

  // Navigate to the second page
  pageControl.SelectPage(1);

  // Navigate to the following page
  pageControl.Next();

  // Navigate to the preceeding page
  pageControl.Back();
}

Python

def Test():
  # Select the mobile device
  Mobile.SetCurrent("iPhone")
  # Obtain the PageControl object
  p = Mobile.Device().Process("SampleApp")
  pageControl = p.Window().PageControl()

  # Navigate to the second page
  pageControl.SelectPage(1)

  # Navigate to the following page
  pageControl.Next()

  # Navigate to the preceeding page
  pageControl.Back()

VBScript

Sub Test
  ' Select the mobile device
  Mobile.SetCurrent("iPhone")
  ' Obtain the PageControl object
  Set p = Mobile.Device.Process("SampleApp")
  Set pageControl = p.Window().PageControl

  ' Navigate to the second page
  pageControl.SelectPage(1)

  ' Navigate to the following page
  pageControl.Next

  ' Navigate to the preceeding page
  pageControl.Back
End Sub

DelphiScript

procedure Test();
var p, pageControl;
begin
  // Select the mobile device
  Mobile.SetCurrent('iPhone');
  // Obtain the PageControl object
  p := Mobile.Device.Process('SampleApp');
  pageControl := p.Window().PageControl;

  // Navigate to the second page
  pageControl.SelectPage(1);

  // Navigate to the following page
  pageControl.Next;

  // Navigate to the preceeding page
  pageControl.Back;
end;

C++Script, C#Script

function Test()
{
  // Select the mobile device
  Mobile["SetCurrent"]("iPhone");
  // Obtain the PageControl object
  var p = Mobile["Device"]["Process"]("SampleApp");
  var pageControl = p["Window"]()["PageControl"]();

  // Navigate to the second page
  pageControl["SelectPage"](1);

  // Navigate to the following page
  pageControl["Next"]();

  // Navigate to the preceeding page
  pageControl["Back"]();
}

Simulating Touches on the Control

To move through pages, you can simulate touches on the page control by calling the Touch method of the iOS PageControl test object. If you call the Touch method without parameters, it simulates the touch at the center of the control. To simulate touches at the specific point of the control, call the Touch method with the appropriate coordinates specified.

The following sample code simulates a touch on the right side of the page control to navigate to the next page:

JavaScript, JScript

function Test()
{

  // Select the mobile device
  Mobile.SetCurrent("iPhone");
  // Obtain the PageControl object
  var p = Mobile.Device().Process("SampleApp");
  var pageControl = p.Window().PageControl();

  // Touch the right side of the page control to navigate to the next page
  var x = pageControl.Width - 2;
  var y = Math.round(pageControl.Height / 2);
  pageControl.Touch(x, y);

}

Python

def Test():

  # Select the mobile device
  Mobile.SetCurrent("iPhone");
  # Obtain the PageControl object
  p = Mobile.Device().Process("SampleApp")
  pageControl = p.Window().PageControl()

  # Touch the right side of the page control to navigate to the next page
  x = pageControl.Width - 2
  y = Math.round(pageControl.Height / 2)
  pageControl.Touch(x, y)

VBScript

Sub Test

  ' Select the mobile device
  Mobile.SetCurrent("iPhone")
  ' Obtain the PageControl object
  Set p = Mobile.Device.Process("SampleApp")
  Set pageControl = p.Window().PageControl

  ' Touch the right side of the page control to navigate to the next page
  x = pageControl.Width - 2
  y = Round(pageControl.Height / 2)
  Call pageControl.Touch(x, y)

End Sub

DelphiScript

procedure Test();
var p, pageControl, x, y;
begin

  // Select the mobile device
  Mobile.SetCurrent('iPhone');
  // Obtain the PageControl object
  p := Mobile.Device.Process('SampleApp');
  pageControl := p.Window().PageControl();

  // Touch the right side of the page control to navigate to the next page
  x := pageControl.Width - 2;
  y := Round(pageControl.Height / 2);
  pageControl.Touch(x, y);

end;

C++Script, C#Script

function Test()
{

  // Select the mobile device
  Mobile["SetCurrent"]("iPhone");
  // Obtain the PageControl object
  var p = Mobile["Device"]["Process"]("SampleApp");
  var pageControl = p["Window"]()["PageControl"]();

  // Touch the right side of the page control to navigate to the next page
  var x = pageControl["Width"] - 2;
  var y = Math["round"](pageControl["Height"] / 2);
  pageControl["Touch"](x, y);

}
Note: Simulating touches on a specific dot of the page control does not select the corresponding page. If you need to select a specific page, use the SelectPage method of the iOS PageControl test object (see above).

Navigating Through Pages in Keyword Tests

To navigate through application’s pages from keyword tests, call the methods described above by using the On-Screen Action or Call Object Method operation. See Calling Object Methods.

See Also

Working With iOS Page Controls
Determining the Selected Page
SelectPage Method (Specific to iOS PageControl Objects)
Back Method (iOS Controls)
Next Method (iOS Controls)

Highlight search results