Iterate Through Remote Testing Environments

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

In TestComplete, you can run web tests in device clouds. 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 and Running 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. Add test commands that will iterate through the desired environments and run your web tests in each of them:

    In keyword tests (available only if you use CrossBrowserTesting.com)
    1. In your test, select all the operations you want to simulate in the device cloud.

    2. Right-click the operations and then click Make Remote Browser Loop:

      Making a remote browser loop

      Click the image to enlarge it.

    3. In the resulting wizard, specify the environments in which you want to run your test:

      Remote environments added to the loop
    4. TestComplete will add the Remote Browser Loop operation to the recorded test and turn the selected operations to the loop’s child operations:

      Operations added to the remote browser loop

      Click the image to enlarge it.

    In script tests
    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 web test instructions in the loop.

      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.

      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"]();
        }

      }
  4. Run the resulting test. It will connect to your device cloud, launch the specified web browsers, and simulate test commands in each of them, one browser after another.

See Also

About Cross-Platform Web Tests
Creating and Running Cross-Platform Web Tests

Highlight search results