Network Suite Variables - Overview

Applies to TestComplete 15.47, last modified on January 20, 2023
The Network Suite functionality is deprecated. We don’t recommend using it for distributed testing. Consider using a CI/CD system for managing distributed tests. See Migrating Distributed Tests to CI/CD Systems for details. In case you need to run web tests on multiple environments in parallel, you can also try using your project’s Execution Plan.

You use network suite variables to share data among all projects participating in distributed testing during the test run. If one project modifies a network suite variable, the other projects will use the new value.

We recommend that you use critical sections to change network suite variables during test runs. Otherwise, you may face a situation where several projects attempt to read or modify the same variable at the same time. (See below.)

You create and manage network suite variables in your master project. When a network suite starts, the master project’s suite variables replace the slave projects’ network suite variables.

In order for the changes made to network suite variables in slave projects to synchronize with projects correctly, the master project must keep running until all the tests in slave projects are completed. For example, if you run your slave projects from a script, make sure their WaitForCompletion parameter is set to True.

You can use network suite variables to synchronize your tests. TestComplete includes an event that fires when a network suite variable’s value changes. You can pause the test run until the variable gets the needed value.

Creating Network Suite Variables

You create variables on the Variables page of the Network Suite editor:

  • Right-click the NetworkSuite item in the Project Explorer and choose Edit | Variables from the context menu.

– or –

  • Double-click the NetworkSuite item to open the NetworkSuite editor and switch to the Variables page.

You add variables whose value will be stored between network suite runs to the Persistent Variables section. You add variables whose value will be restored to their initial value after each network suite run to the Temporary Variables section.

Click Add Variable on the toolbar of the needed section.

– or –

Right-click within the needed section and then click New Item.

Specify the variable's name, type and description, as well as its default value and the current value (in the Local column, only for persistent variables). For detailed information on columns of the Variables page, see the page’s description.

Note: The variable name must conform to the naming rules of the scripting languages supported by TestComplete. The easiest way to do this is to follow a simple rule: a variable name must consist only of alphanumeric characters and it must start with a letter.

Types of Network Suite Variables

There are two types of network suite variables:

  • Persistent network suite variables are stored between network suite runs.

  • Temporary network suite variables are restored to their initial value when the network suite run is finished.

Network suite variables can take values of the following types:

  • String - Can store strings and individual characters.

  • Integer - Can store integers.

  • Double - Can store floating-point numeric values.

  • Boolean - Can store True or False.

Network suite variables cannot store values of the Object, Table and DBTable types.

Working With Network Suite Variables in Tests

You can use network suite variables in scripts and keyword tests.

To access network suite variables from scripts, use the construction NetworkSuite.Variables.variable_name.

The following code demonstrates how to work with network suite variables in scripts:

JavaScript, JScript

// Stores a value to a network suite variable
NetworkSuite.Variables.Var1 = 0;

Python

# Stores a value to the network suite variable
NetworkSuite.Variables.Var1 = 0

VBScript

' Stores a value to a network suite variable
NetworkSuite.Variables.Var1 = 0

DelphiScript

// Stores a value to a network suite variable
NetworkSuite.Variables.Var1 := 0;

C++Script, C#Script

// Stores a value to a network suite variable
NetworkSuite["Variables"]["Var1"] = 0;

To assign a value to a network suite variable from a keyword test, use the Set Variable Value operation. To use a network suite variable as a parameter of a keyword test operation, in the Operation Parameters dialog, set the Variable mode for a parameter and select the network suite variable from the list.

Note: In your slave project’s keyword tests, operations may not be able to access variables that your master project defines. As a workaround, you can do any of the following:
  • In your slave project, create network suite variables with the same name as the master project’s network suite variables and use them in your keyword tests. When you run your network suite, the master project will copy the needed variable values to your slave project.

– or –

  • Use the Run Code Snippet operation to work with network suite variables in your slave project’s keyword tests.

    Keep in mind that in VBScript projects, the Run Code Snippet operation treats the equals sign (=) as a comparison operator by default. To treat it as an assignment operator, add the assignment code to the Execute statement:

    VBScript

    Execute("NetworkSuite.Variables.Var1 = 0")

TestComplete includes the OnNetVarChange event that fires when a network suite variable's value is changed. You can use it perform the needed actions when changing network suite variables.

You can also use the NetworkSuite.WaitForNetVarChange method to pause the test run until a variable gets the needed value.

Using Critical Sections When Changing Network Suite Variables

All the projects that belong to a network suite share network suite variables.

It is quite possible that several projects may access the same variables at the same time. Multiple reading attempts do not cause problems, but changes made simultaneously may cause unexpected results.

Suppose you have two projects that change records in a database, and you have a network suite variable that stores a change counter. The variable is 0 before the network suite starts running. We expect the variable value will be 2 after we run both projects.

To change a variable, the test engine —

  • Gets the variable value.

  • Changes it.

  • Saves the value to the variable.

If the changes made to the variable are not synchronized, and one of the projects reads the variable before another project changes it, the other project may overwrite the changes the project makes. As a result, the variable will store 1 instead of 2.

To work around the problem, synchronize the changes by using critical sections. This is a special instrument that is offered by the test engine to synchronize projects that participate in distributed testing. Critical sections are identified by their names and a project can “enter” or “exit” a section via the EnterCriticalSection and LeaveCriticalSection methods of the NetworkSuite object. Once a project enters a critical section, no project can enter it until that project exits it.

The common procedure of changing a variable value looks as follows:

  1. Enter a critical section by calling the NetworkSuite.EnterCriticalSection method.

  2. Change the variable (or work with it in the desired way). You can use a single scripting statement or keyword test operation to change the variable, or you can use several statements or operations.

  3. Leave the critical section by calling the NetworkSuite.LeaveCriticalSection method.

To call the EnterCriticalSection and LeaveCriticalSection methods from within keyword tests, use the Run Code Snippet operation.

Note: Use the same name of the critical section in each project.

If two projects use a network suite variable as a counter, each of these projects may contain the following code that updates the variable value:

JavaScript, JScript

...
NetworkSuite.EnterCriticalSection("My Section");
NetworkSuite.Variables.MyVarCounter = NetworkSuite.Variables.MyVarCounter + 1;
NetworkSuite.LeaveCriticalSection("My Section");
...

Python

...
NetworkSuite.EnterCriticalSection("My Section")
NetworkSuite.Variables.MyVarCounter = NetworkSuite.Variables.MyVarCounter + 1
NetworkSuite.LeaveCriticalSection("My Section")
...

VBScript

...
NetworkSuite.EnterCriticalSection("My Section")
NetworkSuite.Variables.MyVarCounter = NetworkSuite.Variables.MyVarCounter + 1
NetworkSuite.LeaveCriticalSection("My Section")
...

DelphiScript

...
NetworkSuite.EnterCriticalSection('My Section');
NetworkSuite.Variables.MyVarCounter := NetworkSuite.Variables.MyVarCounter + 1;
NetworkSuite.LeaveCriticalSection('My Section');
...

C++Script, C#Script

...
NetworkSuite["EnterCriticalSection"]("My Section");
NetworkSuite["Variables"]["MyVarCounter"] = NetworkSuite["Variables"]["MyVarCounter"] + 1;
NetworkSuite["LeaveCriticalSection"]("My Section");
...

Note: By default, the EnterCriticalSection method waits for the specified section for an unlimited period. To create more flexible tests, you can set a timeout: pass the number of milliseconds to wait for the section as the second parameters of the method.

For example, the following code snippet waits for the MySect section for 30 seconds and changes the network suite variable only if the section becomes available within this period:

JavaScript, JScript

...
if(NetworkSuite.EnterCriticalSection("MySect", 30000))
{
  NetworkSuite.Variables.MyVarCounter = NetworkSuite.Variables.MyVarCounter + 1;
  NetworkSuite.LeaveCriticalSection("MySect");
}
else
{
  Log.Error("Timeout has elapsed.");
}
...

Python

...
if NetworkSuite.EnterCriticalSection("MySect", 30000):
  NetworkSuite.Variables.MyVarCounter = NetworkSuite.Variables.MyVarCounter + 1
  NetworkSuite.LeaveCriticalSection("MySect")
else:
  Log.Error("Timeout has elapsed.");
...

VBScript

...
If NetworkSuite.EnterCriticalSection("MySect", 30000) Then
  NetworkSuite.Variables.MyVarCounter = NetworkSuite.Variables.MyVarCounter + 1
  NetworkSuite.LeaveCriticalSection("MySect")
Else
  Log.Error "Timeout has elapsed."
End If
...

DelphiScript

...
if NetworkSuite.EnterCriticalSection('MySect', 30000) then
begin
  NetworkSuite.Variables.MyVarCounter := NetworkSuite.Variables.MyVarCounter + 1;
  NetworkSuite.LeaveCriticalSection('MySect');
end
else
begin
  Log.Error('Timeout has elapsed.');
end;
...

C++Script, C#Script

...
if(NetworkSuite["EnterCriticalSection"]("MySect", 30000) )
{
  NetworkSuite["Variables"]["MyVarCounter"] = NetworkSuite["Variables"]["MyVarCounter"] + 1;
  NetworkSuite["LeaveCriticalSection"]("MySect");
}
else
{
  Log["Error"]("Timeout has elapsed.");
}
...


We highly recommend that you use critical sections to change the values of network suite variables. This will help you avoid possible problems caused by incorrect variable values.

See Also

Distributed Testing - Basic Concepts
Distributed Testing
Network Suite Variables
Synchronizing Projects in Network Suites
Critical Sections

Highlight search results