ToURL Method (Mobile Objects)

Applies to TestComplete 15.47, last modified on January 20, 2023
This method is available in legacy mobile tests that work with devices connected to the local computer. To learn how to simulate user actions in newer cloud-compatible mobile tests, see the Simulating user actions in tests section.

Description

The ToUrl method loads a page specified by the URL parameter in the WebView control and returns the Page object that corresponds to the loaded page. You can use the Exists property to determine if the new page was loaded successfully.

Declaration

TestObj.ToURL(URL, WaitTime)

TestObj A variable, parameter or expression that specifies a reference to one of the objects listed in the Applies To section
URL [in]    Required    String    
WaitTime [in]    Optional    Integer Default value: -1   
Result A Page object

Applies To

The method is applied to the following objects:

View Mode

This method is available in the Object Browser panel and in other panels and dialogs in both Basic and Advanced view modes.

Parameters

The method has the following parameters:

URL

The URL to navigate to. It is recommended that you specify the protocol in the URL, otherwise the page may not be loaded. For example, use http://www.example.com rather than www.example.com. This parameter can hold either the absolute or relative path to the new page (relative to the current page).

WaitTime

Specifies the time (in milliseconds) to wait until the browser loads the page and becomes ready to accept user input. If WaitTime is omitted, the timeout is specified by the project’s Web page loading timeout option. After the specified time limit is reached, the test execution proceeds.

Result Value

The Page object that that corresponds to the newly loaded web page.

Remarks

  • To determine whether the specified web page has loaded completely, TestComplete uses the WebWiew.getProgress() and WebViewClient.onPageFinished() native methods of the Android application.

    The described mechanism of determining whether a web page has been downloaded completely is acceptable only for static web pages and is not effective for pages with dynamic content. For more information, see Waiting for Web Pages in Hybrid Mobile Applications (Legacy).

  • The ToURL method uses two waiting periods:

    • First, it waits for the web page to load for the timeout period specified by the WaitTime parameter and stops waiting when the page has been loaded completely or after the timeout elapses.

      The method also stops waiting if the loaded page displays a login dialog. In this case, you need to create test commands that simulate user actions over the dialog to close it.

    • After the method stops waiting for the page to be loaded, it waits for the time specified by the Auto-wait timeout setting until the object hierarchy contains the desired Page object.

Example

The following example opens a new page and checks whether it has loaded successfully:

JavaScript, JScript

function Test1()
{
  // Select the Android device
  Mobile.SetCurrent("MI 2");

  // Obtain the WebView object
  var p = Mobile.Device().Process("smartbear.tctests.webbrowserapp");
  var WebView = p.RootLayout("").Layout("layoutTop").WebView("webview");
  
  // Navigate to a new page
  var Page = WebView.ToUrl("example.com");
  
  // Check if the page was loaded
  if (!Page.Exists)
  {
    Log.Error("The page did not load");
  }
}

Python

def Test1():
  # Select the Android device
  Mobile.SetCurrent("MI 2")

  # Obtain the WebView object
  p = Mobile.Device().Process("smartbear.tctests.webbrowserapp")
  WebView = p.RootLayout("").Layout("layoutTop").WebView("webview")
  
  # Navigate to a new page
  Page = WebView.ToUrl("example.com")
  
  # Check if the page was loaded
  if (not Page.Exists):
    Log.Error("The page did not load")

VBScript

Sub Test
  Dim p, WebView, Page

  ' Select the Android device
  Mobile.SetCurrent("MI 2")

  ' Obtain the WebView object
  Set p = Mobile.Device.Process("smartbear.tctests.webbrowserapp")
  Set WebView = p.RootLayout("").Layout("layoutTop").WebView("webview")
  
  ' Navigate to a new page
  Set Page = WebView.ToUrl("example.com")
  
  ' Check if the page was loaded
  If Not Page.Exists Then
    Log.Error("The page did not load")
  End If
End Sub

DelphiScript

function Test1();
var
  p, WebView, Page;
begin
  // Select the Android device
  Mobile.SetCurrent('MI 2');

  // Obtain the WebView object
  p := Mobile.Device.Process('smartbear.tctests.webbrowserapp');
  WebView := p.RootLayout('').Layout('layoutTop').WebView('webview');
  
  // Navigate to a new page
  Page := WebView.ToUrl('example.com');
  
  // Check if the page was loaded
  if not Page.Exists then
  begin
    Log.Error('The page did not load');
  end;
end;

C++Script, C#Script

function Test1()
{
  // Select the Android device
  Mobile["SetCurrent"]("MI 2");

  // Obtain the WebView object
  var p = Mobile["Device"].Process("smartbear.tctests.webbrowserapp");
  var WebView = p["RootLayout"]("")["Layout"]("layoutTop")["WebView"]("webview");
  
  // Navigate to a new page
  var Page = WebView["ToUrl"]("example.com");
  
  // Check if the page was loaded
  if (!Page["Exists"])
  {
    Log["Error"]("The page did not load");
  }
}

See Also

Testing Hybrid Mobile Applications (Legacy)
Navigating to Web Pages in Hybrid Applications (Legacy)
Waiting for Web Pages in Hybrid Mobile Applications (Legacy)

Highlight search results