Applies to TestComplete 14.50, last modified on August 05, 2020

Description

The VirtualBrowsers.CurrentBrowser property returns the mobile browser profile that was last simulated during the current test run session. This is the browser profile used in the last executed Run Virtual Browser keyword operation or in the VirtualBrowsers.Item(browser_name).Run scripting method.

You can use VirtualBrowsers.CurrentBrowser to check the currently used mobile browser and execute part of the test in a specific browser only.

Declaration

VirtualBrowsers.CurrentBrowser

Read-Only Property A VirtualBrowserInfo object

Applies To

The property is applied to the following object:

Property Value

The VirtualBrowserInfo object that corresponds to the last used mobile browser profile.

If the mobile browser emulator has not been yet launched during the test run, VirtualBrowsers.CurrentBrowser returns an empty object (Nothing in VBScript; null in JavaScript, JScript, C++Script and C#Script; None in Python; nil in DelphiScript).

Example

The following example logs a web page screenshot if the page is displayed in the iPhone 7 browser emulator.

JavaScript, JScript

function Test()
{
  VirtualBrowsers.Item("Apple iPhone 7").Run("http://m.smartbear.com");

  if (VirtualBrowsers.CurrentBrowser.Name == "Apple iPhone 7")
  {
    Log.Picture(Sys.Browser().Page("*").PagePicture(), "Web page screenshot");
  }

  Sys.Browser().Close();
}

Python

def Test():
  VirtualBrowsers.Item["Apple iPhone 7"].Run("http://m.smartbear.com");

  if (VirtualBrowsers.CurrentBrowser.Name == "Apple iPhone 7"):
    Log.Picture(Sys.Browser().Page("*").PagePicture(), "Web page screenshot")

  Sys.Browser().Close()

VBScript

Sub Test
  Call VirtualBrowsers.Item("Apple iPhone 7").Run("http://m.smartbear.com")

  If VirtualBrowsers.CurrentBrowser.Name = "Apple iPhone 7" Then
    Call Log.Picture(Sys.Browser.Page("*").PagePicture, "Web page screenshot")
  End If

  Sys.Browser.Close
End Sub

DelphiScript

procedure Test;
begin
  VirtualBrowsers.Item('Apple iPhone 7').Run('http://m.smartbear.com');

  if VirtualBrowsers.CurrentBrowser.Name = 'Apple iPhone 7' then
  begin
    Log.Picture(Sys.Browser.Page('*').PagePicture, 'Web page screenshot');
  end;

  Sys.Browser.Close;
end;

C++Script, C#Script

function Test()
{
  VirtualBrowsers["Item"]("Apple iPhone 7")["Run"]("http://m.smartbear.com");

  if (VirtualBrowsers["CurrentBrowser"]["Name"] == "Apple iPhone 7")
  {
    Log["Picture"](Sys["Browser"]()["Page"]("*")["PagePicture"](), "Web page screenshot");
  }

  Sys["Browser"]()["Close"]();
}

See Also

Testing Mobile Web Applications Using Emulator
VirtualBrowsers Object
VirtualBrowsers.Count
VirtualBrowsers.Item
VirtualBrowserInfo Object

Highlight search results