TestedApps.AddBrowser Method

Applies to TestComplete 14.60, last modified on April 22, 2021

Description

The AddBrowser method adds the specified web browser to the list of tested applications and returns the browser’s zero-based index it has in the application list.

Tested applications of the Web type are obsolete and are supported for backward compatibility only. To launch a web browser from tests, use the Run Browser keyword test operation or the Browsers.Item(...).Run scripting method.

Declaration

TestedApps.AddBrowser(BrowserTypeBrowserVersion)

BrowserType [in]    Optional    String Default value: Empty string   
BrowserVersion [in]    Optional    String Default value: Empty string   
Result Integer

Applies To

The method is applied to the following object:

Parameters

The method has the following parameters:

BrowserType

Specifies the name of the web browser you want to add to the list. The following values are available:

  • Internet Explorer
  • Mozilla Firefox
  • Google Chrome
  • Edge

If the property is not specified, the default browser used in your system is added.

BrowserVersion

Specifies the version of the browser you want to add.

You can specify the version in various formats: major version only, major + minor version, major + minor + build number. Below are some examples that are valid for Internet Explorer 11:

  • 11
  • 11.0
  • 11.0.165
  • 11.535.18362

If the property is not specified, the latest installed version of the specified web browser is added.

Result Value

The zero-based index of the web browser in the list of tested applications. You can use this index to access the corresponding BrowserTestedApp object using the TestedApps.Items(Index) property.

Example

The following script adds a web browser to TestedApps list, specifies the URL of the target web page and launches it.

JavaScript, JScript

function Test()
{

  var webBrowserName = "Internet Explorer";
  var webBrowserVersion = "11.0";
  var pageURL = "http://www.smartbear.com";

  // Add the web browser to the list of tested applications
  var webBrowserIndex = TestedApps.AddBrowser(webBrowserName, webBrowserVersion);

  // Obtains the web browser and changes its parameters
  var webBrowser = TestedApps.Items(webBrowserIndex);
  webBrowser.PageAddress = pageURL;
  // Launches the web browser and opens the specified web page
  webBrowser.Run();

}

Python

def Test():
  webBrowserName = "Internet Explorer"
  webBrowserVersion = "11.0"
  pageURL = "http://www.smartbear.com"
  # Add the web browser to the list of tested applications
  webBrowserIndex = TestedApps.AddBrowser(webBrowserName, webBrowserVersion)
  # Obtains the web browser and changes its parameters
  webBrowser = TestedApps.Items[webBrowserIndex] 
  webBrowser.PageAddress = pageURL
  # Launches the web browser and opens the specified web page
  webBrowser.Run()

VBScript

Sub Test

  webBrowserName = "Internet Explorer"
  webBrowserVersion = "11.0"
  pageURL = "http://www.smartbear.com"

  ' Add the web browser to the list of tested applications
   webBrowserIndex = TestedApps.AddBrowser(webBrowserName, webBrowserVersion)

  ' Obtains the web browser and changes its parameters
  Set webBrowser = TestedApps.Items(webBrowserIndex)
  webBrowser.PageAddress = pageURL
  ' Launches the web browser and opens the specified web page
  webBrowser.Run()

End Sub

DelphiScript

procedure Test();
var
  webBrowserName, webBrowserVersion, pageURL : string;
  webBrowserIndex : integer;
  webBrowser : OleVariant;
begin

  webBrowserName := 'Internet Explorer';
  webBrowserVersion := '11.0';
  pageURL := 'http://www.smartbear.com';

  // Add the web browser to the list of tested applications
  webBrowserIndex := TestedApps.AddBrowser(webBrowserName, webBrowserVersion);

  // Obtains the web browser and changes its parameters
  webBrowser := TestedApps.Items(webBrowserIndex);
  webBrowser.PageAddress := pageURL;
  // Launches the web browser and opens the specified web page
  webBrowser.Run();

end;

C++Script, C#Script

function Test()
{

  var webBrowserName = "Internet Explorer";
  var webBrowserVersion = "11.0";
  var pageURL = "http://www.smartbear.com";

  // Add the web browser to the list of tested applications
  var webBrowserIndex = TestedApps["AddBrowser"](webBrowserName, webBrowserVersion);

  // Obtains the web browser and changes its parameters
  var webBrowser = TestedApps["Items"](webBrowserIndex);
  webBrowser["PageAddress"] = pageURL;
  // Launches the web browser and opens the specified web page
  webBrowser["Run"]();

}

See Also

TestedApps Object
BrowserTestedApp Object
Add Method
AddClickOnceApp Method
Adding Tested Applications

Highlight search results