Iterate Through Remote Testing Environments

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

In TestComplete 14.40, you can create cross-platform web tests. That is, you record a single test on your local computer and then run it in a needed scope of web browsers managed by Selenium Grid. This way, you can easily run your tests in as many browsers, browser versions and platforms as you need.

To run your recorded web test in several test environments:

Currently, TestComplete does not support running cross-platform tests in parallel. You can only run your test in each remote environment one after another.

  1. Record your web test on your local computer (where your TestComplete is installed). See Creating Cross-Platform Web Tests.

  2. Modify the test so that it could run in remote test environments successfully. For instance, in script tests, remove (or comment out) lines that use the Browsers.Item property. In keyword tests, remove or disable the Run Browser operation. To learn more, see Running Tests in Remote Environments.

  3. Create test commands that will iterate through the desired environments and run your web tests in each of them:

    1. Create objects that describe the desired test environments by their capabilities. Which capabilities are supported depends on the Selenium Grid version you use and the remote machine it manages. If you use Selenium Grid provided by CrossBrowserTesting.com, you can use the Generate Run Code dialog to generate the needed objects easier (remove the redundant run instructions).

    2. Create a loop that will iterate through the specified environments.

      Tip: You can store environment descriptions in a file or variable and use a data-driven loop to iterate them. See Data-Driven Testing - Basic Concepts.

    3. Call your recorded cross-platform test in the loop.

      In scripts, if your recorded test is also a script test, call it as you usually would call any script routine. If your recorded test is a keyword test, use the KeywordTests.Test_Name.Run method to run it.

      In keyword tests, if your recorded test is a script, use the Run Script Routine operation to call it. If your recorded test is also a keyword test, use the Run Keyword Test operation.

The example below shows how to describe several remote test environments by their capabilities, connect to Selenium Grid provided by CrossBrowserTesting, iterate through the described environments, and run the Test1 keyword test in each of them:

JavaScript, JScript

function Main()
{
  var url = "http://services.smartbear.com/samples/TestComplete14/smartstore/";
  var server = "http://hub.crossbrowsertesting.com:80/wd/hub";

  var remotes = [
  {
    browserName: 'safari',
    version: '13',
    platform: 'Mac OSX 10.15',
    username: 'user_name',
    password: 'mypassword1'
  },
  {
    browserName: 'chrome',
    deviceName: 'Nexus 9',
    username: 'user_name',
    password: 'mypassword1'
  }];

  for (var i = 0; i < remotes.length; i++)
  {
    Browsers.RemoteItem(server, JSON.stringify(remotes[i])).Run(url);
    KeywordTests.Test1.Run();
  }

}

Python

def Main():
  url = "http://services.smartbear.com/samples/TestComplete14/smartstore/";
  server = "http://hub.crossbrowsertesting.com:80/wd/hub";

  remotes = [
  {
    "browserName": "safari",
    "version": "13",
    "platform": "Mac OSX 10.15",
    "username": "user_name",
    "password": "mypassword1"
  },
  {
    "browserName": "chrome",
    "deviceName": "Nexus 9",
    "username": "user_name",
    "password": "mypassword1"
  }];

  for i in range (0, len(remotes)):
    Browsers.RemoteItem[server, remotes[i]].Run(url)
    KeywordTests.Test1.Run()

VBScript

Sub Main
  url = "http://services.smartbear.com/samples/TestComplete14/smartstore/"
  server = "http://hub.crossbrowsertesting.com:80/wd/hub"

  Dim remotes: remotes = Array(_
      "{""browserName"": ""safari"", ""version"": ""13"", ""platform"": ""Mac OSX 10.15"", ""username"": ""user_name"", ""password"": ""mypassword1""}",_
      "{""browserName"": ""chrome"", ""deviceName"": ""Nexus 9"", ""username"": ""user_name"", ""password"": ""mypassword1""}"_
      )

  For i = 0 To UBound(remotes)
    Call Browsers.RemoteItem(server, remotes(i)).Run(url)
    KeywordTests.Test1.Run()
  Next

End Sub

DelphiScript

procedure Main();
var url, server, i;
var remotes : array[0..1];
begin
  url := 'http://services.smartbear.com/samples/TestComplete14/smartstore/';
  server := 'http://hub.crossbrowsertesting.com:80/wd/hub';

  remotes[0] := '{"browserName": "safari", "version": "13", "platform": "Mac OSX 10.15", "username": "user_name", "password": "mypassword1"}';
  remotes[1] := '{"browserName": "chrome", "deviceName": "Nexus 9", "username": "user_name", "password": "mypassword1"}';

  for i := 0 to VarArrayHighBound(remotes, 1) do
  begin
    Browsers.RemoteItem[server, remotes[i]].Run(url);
    KeywordTests.Test1.Run();
  end;

end;

C++Script, C#Script

function Main()
{
  var url = "http://services.smartbear.com/samples/TestComplete14/smartstore/";
  var server = "http://hub.crossbrowsertesting.com:80/wd/hub";

  var remotes = [
  {
    browserName: 'safari',
    version: '13',
    platform: 'Mac OSX 10.15',
    username: 'username',
    password: 'mypassword1'
  },
  {
    browserName: 'chrome',
    deviceName: 'Nexus 9',
    username: 'username',
    password: 'mypassword1'
  }];

  for (var i = 0; i < remotes["length"]; i++)
  {
    Browsers["RemoteItem"](server, JSON["stringify"](remotes[i]))["Run"](url);
    KeywordTests["Test1"]["Run"]();
  }

}

See Also

About Cross-Platform Web Tests
Creating Cross-Platform Web Tests

Highlight search results