Parallel.RunTests Method

Applies to TestComplete 15.45, last modified on December 01, 2022

Description

Use the Parallel.RunTests method to run the specified list of tests in parallel.

Requirements

Declaration

Parallel.RunTests(Tests, TestTimeOut, LicenseCount)

Tests [in]    Required    Array of strings    
TestTimeOut [in]    Optional    Integer Default value: 0   
LicenseCount [in]    Optional    Integer Default value: 0   
Result None

Applies To

The method is applied to the following object:

Parameters

The method has the following parameters:

Tests

The list of tests you want to run in parallel. It can be script routines, keyword tests, and BDD scenarios. The tests must belong to the same project from which you run the method.

You can specify tests either by their full name or by tags.

The full name includes the name of the collection to which the test belongs, and the test name separated by the pipe character. For script tests, the full name also includes the name of the unit.

To run tests that match a tag, specify the tag name in the @tag_name format.

Example

TestTimeOut

The number of minutes that TestComplete waits for the test run to finish. If the test run time exceeds the specified timeout, TestComplete will stop the test run and report an error to the test log.

If the value is 0 (default value), the wait time is not limited.

LicenseCount

The maximum number of tests that you want to execute simultaneously during the test run.

Result Value

None.

Example

The sample code below runs MyTest1 and MyTest2 cross-platform web tests in parallel. Each test connects to a device cloud, launches a web browser there, and simulates user actions in that web browser.

JavaScript, JScript

function Main()
{
  // Set a list of tests to run in parallel
  var tests = ['Script|Unit1|MyTest1', 'Script|Unit1|MyTest2'];

  // Run tests in parallel
  Parallel.RunTests(tests);
}

function MyTest1()
{
  var url = "http://services.smartbear.com/samples/TestComplete15/smartstore/";
  // Set the URL of the device cloud server
  var server = "http://hub.crossbrowsertesting.com:80/wd/hub";

  // Set an environment for the test to run
  var capabilities = {
  "platform": "Mac OSX 10.14",
  "browserName": "Safari",
  "version": "12",
  "screenResolution": "1366x768"
};

  // Launch a browser in the environment
  Browsers.RemoteItem(server, JSON.stringify(capabilities)).Run(url);

  var browser = Sys.Browser();
  var page = browser.Page("*services.smartbear.com/samples/TestComplete*/smartstore/");
  …

}

function MyTest2()
{
  var url = "http://services.smartbear.com/samples/TestComplete15/smartstore/";
  // Set the URL of the device cloud server
  var server = "http://hub.crossbrowsertesting.com:80/wd/hub";

  // Set an environment for the test to run
  var capabilities = {
  "deviceName": "Pixel 4",
  "platformName": "Android",
  "platformVersion": "10.0",
  "browserName": "Chrome",
  "deviceOrientation": "portrait"
};

  // Launch a browser in the environment
  Browsers.RemoteItem(server, JSON.stringify(capabilities)).Run(url);

  var browser = Sys.Browser();
  var page = browser.Page("*services.smartbear.com/samples/TestComplete*/smartstore/");
  …

}

Python

def Main():
  # Set a list of tests to run in parallel
  tests = ['Script|Unit1|MyTest1', 'Script|Unit1|MyTest2']

  # Run tests in parallel
  Parallel.RunTests(tests)

def MyTest1():
  url = "http://services.smartbear.com/samples/TestComplete15/smartstore/"
  # Set the URL of the device cloud server
  server = "http://hub.crossbrowsertesting.com:80/wd/hub"

  # Set an environment for the test to run
  capabilities = {
  "platform": "Mac OSX 10.14",
  "browserName": "Safari",
  "version": "12",
  "screenResolution": "1366x768"}

  # Launch a browser in the environment
  Browsers.RemoteItem[server, capabilities].Run(url)

  browser = Sys.Browser()
  page = browser.Page("*services.smartbear.com/samples/TestComplete*/smartstore/")
  …

def MyTest2():
  url = "http://services.smartbear.com/samples/TestComplete15/smartstore/"
  # Set the URL of the device cloud server
  server = "http://hub.crossbrowsertesting.com:80/wd/hub"

  # Set an environment for the test to run
  capabilities = {
  "deviceName": "Pixel 4",
  "platformName": "Android",
  "platformVersion": "10.0",
  "browserName": "Chrome",
  "deviceOrientation": "portrait"
}

  # Launch a browser in the environment
  Browsers.RemoteItem(server, capabilities).Run(url)

  browser = Sys.Browser()
  page = browser.Page("*services.smartbear.com/samples/TestComplete*/smartstore/")
  …

VBScript

Sub Main
  ' Set a list of tests to run in parallel
  Dim tests : tests = Array("Script|Unit1|MyTest1", "Script|Unit1|MyTest2")

  ' Run tests in parallel
  Parallel.RunTests(tests)
End Sub

Sub MyTest1()
  url = "http://services.smartbear.com/samples/TestComplete15/smartstore/"
  ' Set the URL of the device cloud server
  server = "http://hub.crossbrowsertesting.com:80/wd/hub"

  ' Set an environment for the test to run
   capabilities = "{""platform"":""Mac OSX 10.14"",""browserName"":""Safari"",""version"":""12"",""screenResolution"":""1366x768""}"

  ' Launch a browser in the environment
  Browsers.RemoteItem(server, capabilities).Run(url)

  Set browser = Sys.Browser()
  Set page = browser.Page("*services.smartbear.com/samples/TestComplete*/smartstore/")
  …

End Sub

Sub MyTest2()
  url = "http://services.smartbear.com/samples/TestComplete15/smartstore/"
  ' Set the URL of the device cloud server
  server = "http://hub.crossbrowsertesting.com:80/wd/hub"

  ' Set an environment for the test to run
  capabilities = "{""deviceName"":""Pixel 4"",""platformName"":""Android"",""platformVersion"":""10.0"",""browserName"":""Chrome"",""deviceOrientation"":""portrait""}"

  ' Launch a browser in the environment
  Call Browsers.RemoteItem(server, capabilities).Run(url)

  Set browser = Sys.Browser()
  Set page = browser.Page("*services.smartbear.com/samples/TestComplete*/smartstore/")
  …

End Sub

DelphiScript

procedure Main();
var tests : Array[0..1];
begin
  // Set a list of tests to run in parallel
  tests[0] := 'Script|Unit1|MyTest1';
  tests[1] := 'Script|Unit1|MyTest2';

  // Run tests in parallel
  Parallel.RunTests(tests);
end;

procedure MyTest1();
var url, server, capabilities, browser, page;
begin
  url := 'http://services.smartbear.com/samples/TestComplete15/smartstore/';
  // Set the URL of the device cloud server
  server := 'http://hub.crossbrowsertesting.com:80/wd/hub';

  // Set an environment for the test to run
  capabilities := '{"platform":"Mac OSX 10.14","browserName":"Safari","version":"12","screenResolution":"1366x768"}';

  // Launch a browser in the environment
  Browsers.RemoteItem(server, capabilities).Run(url);

  browser := Sys.Browser();
  page := browser.Page('*services.smartbear.com/samples/TestComplete*/smartstore/');
  …

end;

procedure MyTest2();
var url, server, capabilities, browser, page;
begin
  url := 'http://services.smartbear.com/samples/TestComplete15/smartstore/';
  // Set the URL of the device cloud server
  server := 'http://hub.crossbrowsertesting.com:80/wd/hub';

  // Set an environment for the test to run
  capabilities := '{"deviceName":"Pixel 4","platformName":"Android","platformVersion":"10.0","browserName":"Chrome","deviceOrientation":"portrait"}';

  // Launch a browser in the environment
  Browsers.RemoteItem(server, capabilities).Run(url);

  browser := Sys.Browser();
  page := browser.Page('*services.smartbear.com/samples/TestComplete*/smartstore/');
  …

end;

C++Script, C#Script

function Main()
{
  // Set a list of tests to run in parallel
  var tests = ['Script|Unit1|MyTest1', 'Script|Unit1|MyTest2'];

  // Run tests in parallel
  Parallel["RunTests"](tests);
}

function MyTest1()
{
  var url = "http://services.smartbear.com/samples/TestComplete15/smartstore/";
  // Set the URL of the device cloud server
  var server = "http://hub.crossbrowsertesting.com:80/wd/hub";

  // Set an environment for the test to run
  var capabilities = {
  "platform": "Mac OSX 10.14",
  "browserName": "Safari",
  "version": "12",
  "screenResolution": "1366x768"
};

  // Launch a browser in the environment
  Browsers.RemoteItem(server, JSON["stringify"](capabilities))["Run"](url);

  var browser = Sys["Browser"]();
  var page = browser["Page"]("*services.smartbear.com/samples/TestComplete*/smartstore/");
  …

}

function MyTest2()
{
  var url = "http://services.smartbear.com/samples/TestComplete15/smartstore/";
  // Set the URL of the device cloud server
  var server = "http://hub.crossbrowsertesting.com:80/wd/hub";

  // Set an environment for the test to run
  var capabilities = {
  "deviceName": "Pixel 4",
  "platformName": "Android",
  "platformVersion": "10.0",
  "browserName": "Chrome",
  "deviceOrientation": "portrait"
};

  // Launch a browser in the environment
  Browsers["RemoteItem"](server, JSON["stringify"](capabilities))["Run"](url);

  var browser = Sys["Browser"]();
  var page = browser["Page"]("*services.smartbear.com/samples/TestComplete*/smartstore/");
  …

}

The sample code below runs MyTest1 and MyTest2 mobile tests in parallel. Each test connects to a mobile device, opens a testing session there, and simulates user actions:

JavaScript, JScript

function Main()
{
  var tests = ['Script|Unit1|MyTest1', 'Script|Unit1|MyTest2'];
  Parallel.RunTests(tests);
}

function MyTest1()
{
  var capabilities = {
    "automationName": "UiAutomator2",
    "bitbar_app": "123",
    "bitbar_device": "Google Pixel 3a Android 10",
    "bitbar_findDevice": "false",
    "bitbar_target": "android",
    "deviceName": "Android Phone",
    "newCommandTimeout": "600",
    "platformName": "ANDROID"
};

  var server = "https://appium.bitbar.com/wd/hub/";
  Mobile.ConnectDevice(server, capabilities);

  var device = Mobile.Device();

  device.FindElementByXPath("//*[@text=\"Samuel Clemens\"]").Touch();
  device.FindElementById("smartbear.example.orders:id/editButton").Touch();

  // …
}

function MyTest2()
{
  var capabilities = {
    "automationName": "UiAutomator2",
    "bitbar_app": "123",
    "bitbar_device": "LG Google Nexus 5 6.0.1",
    "bitbar_findDevice": "false",
    "bitbar_target": "android",
    "deviceName": "Android Phone",
    "newCommandTimeout": "600",
    "platformName": "ANDROID"
};

  var server = "https://appium.bitbar.com/wd/hub/";
  Mobile.ConnectDevice(server, capabilities);

  var device = Mobile.Device();

  device.FindElementByXPath("//*[@text=\"Clare Jefferson\"]").Touch();
  device.FindElementById("smartbear.example.orders:id/editButton").Touch();

  // …
}

Python

def Main():
  tests = ['Script|Unit1|MyTest1', 'Script|Unit1|MyTest2']
  Parallel.RunTests(tests)

def MyTest1():
  capabilities = {
    "automationName": "UiAutomator2",
    "bitbar_app": "123",
    "bitbar_device": "Google Pixel 3a Android 10",
    "bitbar_findDevice": "false",
    "bitbar_target": "android",
    "deviceName": "Android Phone",
    "newCommandTimeout": "600",
    "platformName": "ANDROID"
}

  server = "https://appium.bitbar.com/wd/hub/"
  Mobile.ConnectDevice(server, capabilities)

  device = Mobile.Device()

  device.FindElementByXPath("//*[@text=\"Samuel Clemens\"]").Touch()
  device.FindElementById("smartbear.example.orders:id/editButton").Touch()

  # …

def MyTest2():
  capabilities = {
    "automationName": "UiAutomator2",
    "bitbar_app": "123",
    "bitbar_device": "LG Google Nexus 5 6.0.1",
    "bitbar_findDevice": "false",
    "bitbar_target": "android",
    "deviceName": "Android Phone",
    "newCommandTimeout": "600",
    "platformName": "ANDROID"
}

  server = "https://appium.bitbar.com/wd/hub/"
  Mobile.ConnectDevice(server, capabilities)

  device = Mobile.Device()

  device.FindElementByXPath("//*[@text=\"Clare Jefferson\"]").Touch()
  device.FindElementById("smartbear.example.orders:id/editButton").Touch()

  # …

VBScript

Sub Main
  DIm tests : tests = Array("Script|Unit1|MyTest1", "Script|Unit1|MyTest2")
  Call Parallel.RunTests(tests)
End Sub

Sub MyTest1()
  capabilities = "{""automationName"": ""UiAutomator2"",""bitbar_app"": ""123"",""bitbar_device"": ""Google Pixel 3a Android 10"",""bitbar_findDevice"": ""false"",""bitbar_target"": ""android"",""deviceName"": ""Android Phone"",""newCommandTimeout"": ""600"",""platformName"": ""ANDROID""}"

  server = "https://appium.bitbar.com/wd/hub/"
  Call Mobile.ConnectDevice(server, capabilities)

  Set device = Mobile.Device()

  device.FindElementByXPath("//*[@text=\"Samuel Clemens\"]").Touch()
  device.FindElementById("smartbear.example.orders:id/editButton").Touch()

  ' …
End Sub

Sub MyTest2()
  capabilities = "{""automationName"": ""UiAutomator2"",""bitbar_app"": ""123"",""bitbar_device"": ""LG Google Nexus 5 6.0.1"",""bitbar_findDevice"": ""false"",""bitbar_target"": ""android"",""deviceName"": ""Android Phone"",""newCommandTimeout"": ""600"",""platformName"": ""ANDROID""}"

  server = "https://appium.bitbar.com/wd/hub/"
  Call Mobile.ConnectDevice(server, capabilities)

  Set device = Mobile.Device()

  device.FindElementByXPath("//*[@text=\"Clare Jefferson\"]").Touch()
  device.FindElementById("smartbear.example.orders:id/editButton").Touch()

  ' …
End Sub

DelphiScript

procedure MyTest1();
var capabilities, server, device;
begin
  capabilities := '{"automationName": "UiAutomator2", "bitbar_app": "123", "bitbar_device": "Google Pixel 3a Android 10", "bitbar_findDevice": "false", "bitbar_target": "android", "deviceName": "Android Phone", "newCommandTimeout": "600", "platformName": "ANDROID"}';

  server := 'https://appium.bitbar.com/wd/hub/';
  Mobile.ConnectDevice(server, capabilities);

  device := Mobile.Device();

  device.FindElementByXPath('//*[@text=\"Samuel Clemens\"]').Touch();
  device.FindElementById('smartbear.example.orders:id/editButton').Touch();

  // …
end;

procedure MyTest2();
var capabilities, server, device;
begin
  capabilities := '{"automationName": "UiAutomator2", "bitbar_app": "123", "bitbar_device": "LG Google Nexus 5 6.0.1", "bitbar_findDevice": "false", "bitbar_target": "android", "deviceName": "Android Phone", "newCommandTimeout": "600", "platformName": "ANDROID"}';

  server := 'https://appium.bitbar.com/wd/hub/';
  Mobile.ConnectDevice(server, capabilities);

  device := Mobile.Device();

  device.FindElementByXPath('//*[@text=\"Clare Jefferson\"]').Touch();
  device.FindElementById('smartbear.example.orders:id/editButton').Touch();

  // …
end;

procedure Main();
var tests : Array[0..1];
begin
  tests[0] := 'Script|Unit1|MyTest1';
  tests[1] := 'Script|Unit1|MyTest2';
  Parallel.RunTests(tests);
end;

C++Script, C#Script

function Main()
{
  var tests = ['Script|Unit1|MyTest1', 'Script|Unit1|MyTest2'];
  Parallel["RunTests"](tests);
}

function MyTest1()
{
  var capabilities = {
    "automationName": "UiAutomator2",
    "bitbar_app": "123",
    "bitbar_device": "Google Pixel 3a Android 10",
    "bitbar_findDevice": "false",
    "bitbar_target": "android",
    "deviceName": "Android Phone",
    "newCommandTimeout": "600",
    "platformName": "ANDROID"
};

  var server = "https://appium.bitbar.com/wd/hub/";
  Mobile["ConnectDevice"](server, JSON["stringify"](capabilities));

  var device = Mobile["Device"]();

  device["FindElementByXPath"]("//*[@text=\"Samuel Clemens\"]")["Touch"]();
  device["FindElementById"]("smartbear.example.orders:id/editButton")["Touch"]();

  // …
}

function MyTest2()
{
  var capabilities = {
    "automationName": "UiAutomator2",
    "bitbar_app": "123",
    "bitbar_device": "LG Google Nexus 5 6.0.1",
    "bitbar_findDevice": "false",
    "bitbar_target": "android",
    "deviceName": "Android Phone",
    "newCommandTimeout": "600",
    "platformName": "ANDROID"
};

  var server = "https://appium.bitbar.com/wd/hub/";
  Mobile["ConnectDevice"](server, JSON["stringify"](capabilities));

  var device = Mobile["Device"]();

  device["FindElementByXPath"]("//*[@text=\"Clare Jefferson\"]")["Touch"]();
  device["FindElementById"]("smartbear.example.orders:id/editButton")["Touch"]();

  // …
}

See Also

Parallel Object
RunWebTests Method
Running Cross-Platform Web Tests in Parallel

Highlight search results