Working With Network Suite Variables in Tests

Applies to TestComplete 12.60, last modified on September 17, 2018
Information in this topic applies to desktop and web applications.

You can access network suite variables from your keyword tests and scripts and work with them: enumerate variables, modify their values, check their properties, and so on. You access network suite variables via the NetworkSuite.Variables collection. This topic explains how to perform some common operations over network suite variables from TestComplete tests .

Adding Network Suite Variables

Network suite variables cannot be created and deleted in tests during the network suite run.

You can use the NetworkSuite.Variables.Add method to create network suite variables from tests:

JavaScript, JScript

function Test()
{
  // Adds a new network suite variable
  NetworkSuite.Variables.AddVariable("MyVar", "String");
  NetworkSuite.Variables.MyVar = "Hello, world!";
  …
  // Runs the network suite
  NetworkSuite.Run(true);
}

Python

def Test():
  # Adds a new network suite variable
  NetworkSuite.Variables.AddVariable("MyVar", "String")
  NetworkSuite.Variables.MyVar = "Hello, world!"
  ...
  # Runs the network suite
  NetworkSuite.Run(True)

VBScript

Sub Test
  ' Adds a new network suite variable
  Call NetworkSuite.Variables.AddVariable("MyVar", "String")
  NetworkSuite.Variables.MyVar = "Hello, world!"
  …
  ' Runs the network suite
  NetworkSuite.Run(true)
End Sub

DelphiScript

procedure Test();
begin
  // Adds a new network suite variable
  NetworkSuite.Variables.AddVariable('MyVar', 'String');
  NetworkSuite.Variables.MyVar := 'Hello, world!';
  …
  // Runs the network suite
  NetworkSuite.Run(true);
end;

C++Script, C#Script

function Test()
{
  // Adds a new network suite variable
  NetworkSuite["Variables"]["AddVariable"]("MyVar", "String");
  NetworkSuite["Variables"]["MyVar"] = "Hello, world!";
  …
  // Runs the network suite
  NetworkSuite["Run"](true);
}

You cannot create (or delete) network suite variables while the network suite or one of its jobs or tasks is running. If you need to create or delete network suite variables in test, do it before the network suite starts or after its execution is finished.

Modifying Network Suite Variables

To address network suite variables in your tests, use the NetworkSuite.Variables.variable_name syntax. For example:

JavaScript, JScript

NetworkSuite.Variables.MyExportFilePath = "C:\\MyFolder\\MyProject.mds";
ExportFileTo(NetworkSuite.Variables.MyExportFilePath);

Python

NetworkSuite.Variables.MyExportFilePath = "C:\\MyFolder\\MyProject.mds"
ExportFileTo(NetworkSuite.Variables.MyExportFilePath)

VBScript

NetworkSuite.Variables.MyExportFilePath = "C:\MyFolder\MyProject.mds"
ExportFileTo(NetworkSuite.Variables.MyExportFilePath)

DelphiScript

NetworkSuite.Variables.MyExportFilePath := 'C:\MyFolder\MyProject.mds';
ExportFileTo(NetworkSuite.Variables.MyExportFilePath);

C++Script, C#Script

NetworkSuite["Variables"]["MyExportFilePath"] = "C:\\MyFolder\\MyProject.mds";
ExportFileTo(NetworkSuite["Variables"]["MyExportFilePath"]);

You can also get the variables using the NetworkSuite.Variables.VariableByName property.

This way you can form a string holding the variable name and then use this string to get the variable during the test run:

JavaScript

NetworkSuite.Variables.$set("VariableByName", "MyExportFilePath", "C:\\MyFolder\\MyProject.mds");

JScript

NetworkSuite.Variables.VariableByName("MyExportFilePath") = "C:\\MyFolder\\MyProject.mds";

Python

NetworkSuite.Variables.VariableByName["MyExportFilePath"] = "C:\\MyFolder\\MyProject.mds"

VBScript

NetworkSuite.Variables.VariableByName("MyExportFilePath") = "C:\MyFolder\MyProject.mds"

DelphiScript

NetworkSuite.Variables.VariableByName('MyExportFilePath') := 'C:\MyFolder\MyProject.mds';

C++Script, C#Script

NetworkSuite["Variables"]["VariableByName"]["MyExportFilePath"] = "C:\\MyFolder\\MyProject.mds";

Note: Temporary network suite variables restore their initial values when the test finishes while persistent network suite variables store their values between test runs. Therefore, if your test modifies a persistent network suite variable, the variable does not have its initial value each time you run the test, it has the modified value.

Getting Properties of Network Suite Variables

You can also get information about network suite variables, such as the variable name, value, category and description.

The following example posts the list of network suite variables and their properties to the log:

JavaScript, JScript

function Main()
{
  var i, name;

  for (i = 0; i < NetworkSuite.Variables.VariableCount; i++)
  {
    name = NetworkSuite.Variables.GetVariableName(i);
    Log.AppendFolder(name);
    Log.Message("Type: " + NetworkSuite.Variables.GetVariableType(i));
    Log.Message("Value: " + NetworkSuite.Variables.VariableByName(name));
    Log.Message("Category: " + NetworkSuite.Variables.GetVariableCategory(i));
    Log.Message("Description: " + NetworkSuite.Variables.GetVariableDescription(i));
    Log.PopLogFolder();
  }
}

Python

def Main():
  for i in (0, NetworkSuite.Variables.VariableCount):
    name = NetworkSuite.Variables.GetVariableName(i)
    Log.AppendFolder(name)
    Log.Message("Type: " + NetworkSuite.Variables.GetVariableType(i))
    Log.Message("Value: " + NetworkSuite.Variables.VariableByName(name))
    Log.Message("Category: " + NetworkSuite.Variables.GetVariableCategory(i))
    Log.Message("Description: " + NetworkSuite.Variables.GetVariableDescription(i))
    Log.PopLogFolder()

VBScript

Sub Main
  Dim i, name
  For i = 0 To NetworkSuite.Variables.VariableCount - 1
    name = NetworkSuite.Variables.GetVariableName(i)
    Log.AppendeFolder name
    Log.Message "Type: " & NetworkSuite.Variables.GetVariableType(i)
    Log.Message "Value: " & NetworkSuite.Variables.VariableByName(name)
    Log.Message "Category: " & NetworkSuite.Variables.GetVariableCategory(i)
    Log.Message "Description: " & NetworkSuite.Variables.GetVariableDescription(i)
    Log.PopLogFolder
  Next
End Sub

DelphiScript

procedure Main;
var i, name;
begin
  for i := 0 to NetworkSuite.Variables.VariableCount - 1 do
  begin
    name := NetworkSuite.Variables.GetVariableName(i);
    Log.AppendFolder(name);
    Log.Message('Type: ' + NetworkSuite.Variables.GetVariableType(i));
    Log.Message('Value: ' + aqConvert.VarToStr(NetworkSuite.Variables.VariableByName[name]));
    Log.Message('Category: ' + NetworkSuite.Variables.GetVariableCategory(i));
    Log.Message('Description: ' + NetworkSuite.Variables.GetVariableDescription(i));
    Log.PopLogFolder();
  end;
end;

C++Script, C#Script

function Main()
{
  var i, name;

  for (i = 0; i < NetworkSuite["Variables"]["VariableCount"]; i++)
  {
    name = NetworkSuite["Variables"]["GetVariableName"](i);
    Log["AppendFolder"](name);
    Log["Message"]("Type: " + NetworkSuite["Variables"]["GetVariableType"](i));
    Log["Message"]("Value: " + NetworkSuite["Variables"]["VariableByName"](name));
    Log["Message"]("Category: " + NetworkSuite["Variables"]["GetVariableCategory"](i));
    Log["Message"]("Description: " + NetworkSuite["Variables"]["GetVariableDescription"](i));
    Log["PopLogFolder"]();
  }
}

Removing Network Suite Variables

Network suite variables cannot be created and deleted in tests during the network suite run.

To delete a variable from the network suite variables collection, use the NetworkSuite.Variables.RemoveVariable method:

JavaScript, JScript

function Test()
{
  …
  // Runs the network suite and waits until its execution is over
  NetworkSuite.Run(true);
  // After the network suite run is over, deletes a network suite variable
  NetworkSuite.Variables.RemoveVariable("MyVar1");
}

Python

def Test():
  ...
  # Runs the network suite and waits until its execution is over
  NetworkSuite.Run(True)
  # After the network suite run is over, deletes a network suite variable
  NetworkSuite.Variables.RemoveVariable("MyVar1")

VBScript

Sub Test
  …
  ' Runs the network suite and waits until its execution is over
  NetworkSuite.Run(true)
  ' After the network suite run is over, deletes a network suite variable
  NetworkSuite.Variables.RemoveVariable("MyVar1")
End Sub

DelphiScript

procedure Test();
begin
  …
  // Runs the network suite and waits until its execution is over
  NetworkSuite.Run(true);
  // After the network suite run is over, deletes a network suite variable
  NetworkSuite.Variables.RemoveVariable('MyVar1');
end;

C++Script, C#Script

function Test()
{
  …
  // Runs the network suite and waits until its execution is over
  NetworkSuite["Run"](true);
  // After the network suite run is over, deletes a network suite variable
  NetworkSuite["Variables"]["RemoveVariable"]("MyVar1");
}

You cannot delete (or create) network suite variables while the network suite or one of its jobs or tasks is running. If you need to create or delete network suite variables in test, do it before the network suite starts or after its execution is finished.

Working with Network Suite Variables from Keyword Tests

To manage network suite variables from keyword tests, call the needed methods of the NetworkSuite.Variables collection by using the Run Code Snippet operation.

Creating a network suite variable from a keyword test

You can also use network suite variables as parameters for keyword test operations. See Specifying Operation Parameters.

Accessing Network Suite Variables from Connected Application

Connected and self-testing applications are deprecated. We do not recommend using them.

To access network suite variables in a Connected Application:

C#

void Test(){
  ...
  Connect.NetworkSuite["Variables"]["netsuiteVar"] = "C:\\MyFolder\\MyProject.mds"; 
  ...
}

C++

void Test(){
  ...
  NetworkSuite["Variables"]["netsuiteVar"] = "C:\\MyFolder\\MyProject.mds";
  ...
}

Visual Basic

Sub Test
  ...
  NetworkSuite.Variables.netsuiteVar = "C:\MyFolder\MyProject.mds"
  ...
End Sub

Delphi

procedure Test;
begin
  ...
  NetworkSuite.Variables.netsuiteVar := 'C:\MyFolder\MyProject.mds';
  ...
end;

Before you read or assign a value to a network suite variable in a Connected Application, be sure you have loaded the project that holds this variable in TestComplete. Otherwise, an error will occur.

See Also

Network Suite Variables
Network Suite Variables - Overview
Network Suite Editor - Variables Page
How to Specify Parameters for the Test Run

Highlight search results