Checking the Current Browser

Applies to TestComplete 15.47, last modified on January 20, 2023

In some cases, when performing a cross-browser test, you may need to know in what browser your test is currently being executed. This can be helpful, for example, when handling browser-specific issues and differences.

This topic describes how to determine which browser is currently used:

Tip: To obtain the Browser process that corresponds to the current browser, either call the Sys.Browser() or Sys.WaitBrowser() methods or use the Aliases.browser mapped name.

Checking the Current Browser in Keyword Tests

To check the current browser in keyword tests, use the If Browser operation. It compares the current browser with the browser name specified at design time and executes child operations on success. To perform actions when the condition of the If Browser operation evaluates to False, insert the Else operation right after the If Browser operation.

Handling browser-specific windows.

Checking the Current Browser in Scripts

To obtain information about the current browser in scripts, use the Browsers.CurrentBrowser property. It returns the BrowserInfo object that indicates the browser which is currently used in the web test. By reading the sub-properties of the Browsers.CurrentBrowser object, you check the family name, version and executable type of the current browser.

Checking the browser’s family name

The following code snippet checks the browser’s family name and performs test actions that are specific to Internet Explorer:

JavaScript, JScript

...
if (Browsers.CurrentBrowser.Family == Browsers.btIExplorer)
{
  // Handle Active Content Notification in Internet Explorer
  AllowActiveContent();
}
...

Python

...
if (Browsers.CurrentBrowser.Family == Browsers.btIExplorer):
  # Handle Active Content Notification in Internet Explorer
  AllowActiveContent();
...

VBScript

...
If Browsers.CurrentBrowser.Family = Browsers.btIExplorer Then 
  ' Handle Active Content Notification in Internet Explorer
  AllowActiveContent
End If
...

DelphiScript

...
if Browsers.CurrentBrowser.Family = Browsers.btIExplorer then
begin
  // Handle Active Content Notification in Internet Explorer
  AllowActiveContent;
end;
...

C++Script, C#Script

...
if (Browsers["CurrentBrowser"]["Family"] == Browsers["btIExplorer"])
{
  // Handle Active Content Notification in Internet Explorer
  AllowActiveContent();
}
...

Checking the browser’s platform

The code below checks whether a 32-bit or a 64-bit browser version was launched:

JavaScript, JScript

function CheckIEPlatform()
{
  Browsers.Item(btIExplorer).Run();
  if (Browsers.CurrentBrowser.Platform == Browsers.pX86)
    Log.Message("You are using a 32-bit version of Internet Explorer.");
  else
    Log.Message("You are using a 64-bit version of Internet Explorer.");
}

Python

def CheckIEPlatform():
  Browsers.Item[btIExplorer].Run();
  if (Browsers.CurrentBrowser.Platform == Browsers.pX86):
    Log.Message("You are using a 32-bit version of Internet Explorer.");
  else:
    Log.Message("You are using a 64-bit version of Internet Explorer.");

VBScript

Sub CheckIEPlatform
  Browsers.Item(btIExplorer).Run
  If Browsers.CurrentBrowser.Platform = Browsers.pX86 Then
    Log.Message("You are using a 32-bit version of Internet Explorer.")
  Else
    Log.Message("You are using a 64-bit version of Internet Explorer.")
  End If
End Sub

DelphiScript

procedure CheckIEPlatform;
begin
  Browsers.Item(btIExplorer).Run;
  if Browsers.CurrentBrowser.Platform = Browsers.pX86 then
    Log.Message('You are using a 32-bit version of Internet Explorer.')
  else
    Log.Message('You are using a 64-bit version of Internet Explorer.');
end;

C++Script, C#Script

function CheckIEPlatform()
{
  Browsers["Item"](btIExplorer)["Run"]();
  if (Browsers["CurrentBrowser"].Platform == Browsers["pX86"])
    Log["Message"]("You are using a 32-bit version of Internet Explorer.");
  else
    Log["Message"]("You are using a 64-bit version of Internet Explorer.");
}

Checking the browser’s family name and version

The following code displays a warning message when the test starts running in Internet Explorer 9 or earlier:

JavaScript, JScript

function CheckIEVer()
{
  ...
  if ((Browsers.CurrentBrowser.Family == btIExplorer) &&
      (Browsers.CurrentBrowser.Version.MajorPart < 11))
    Log.Warning("You are using an outdated version of Internet Explorer.")
  ...
}

Python

function CheckIEVer():
  ...
  if ((Browsers.CurrentBrowser.Family == btIExplorer) and
      (Browsers.CurrentBrowser.Version.MajorPart < 11)):
    Log.Warning("You are using an outdated version of Internet Explorer.");
  ...

VBScript

Sub CheckIEVer
  ...
  If Browsers.CurrentBrowser.Family = btIExplorer Then
    If Browsers.CurrentBrowser.Version.MajorPart < 11 Then
      Log.Warning("You are using an outdated version of Internet Explorer.")
    End If
  End If
...
End Sub

DelphiScript

procedure CheckIEVer;
begin
  ...
  if (Browsers.CurrentBrowser.Family = btIExplorer) and
     (Browsers.CurrentBrowser.Version.MajorPart < 11) then
    Log.Warning('You are using an outdated version of Internet Explorer.');
  ...
end;

C++Script, C#Script

function CheckIEVer()
{
  ...
  if ((Browsers["CurrentBrowser"]["Family"] == btIExplorer) &&
      (Browsers["CurrentBrowser"]["Version"]["MajorPart"] < 11))
    Log["Warning"]("You are using an outdated version of Internet Explorer.")
  ...
}

See Also

About Cross-Browser Testing in TestComplete
Running Tests in Multiple Browsers
Handling Browser Differences
Check if Browser Is Running

Highlight search results