To exchange the data between the Slave computers, the Network Suite variables are designed to make this available at any given moment on any Slave and the Master computer.
In this recipe, we will deal with an example of data exchange with the help of Network variables.
First of all, we need to create the Network variable. To this end:
To change the value of the Network variable, it is necessary to accomplish the following steps:
NetworkSuite.EnterCriticalSection("Change Variable");
NetworkSuite.Variables.Var1 = "NEW VALUE";
NetworkSuite.LeaveCriticalSection("Change Variable");
NetworkSuite.Variables.Var1
variable contains a new value, which is accessible to any computer for the distributed testing.function changeNetworkVar(varName, value) { NetworkSuite.EnterCriticalSection(varName); NetworkSuite.Variables.VariableByName(varName) = value; NetworkSuite.LeaveCriticalSection(varName); }
changeNetworkVar("Var1", "NEW VALUE");
The variables of the NetworkSuite
level are accessible for the scripts on all the computers throughout the distributed testing.
Usage of the code critical sections allows avoiding conflicts while simultaneously changing one and the same variable from different locations, all at once. As soon as one of the projects starts the critical code section, other projects will not be able to get on with the same critical code section under the same name, and would be waiting for its closure. This is why, to change one variable, it is always necessary to use the same names of the code critical sections.
When reading the values of the variables, the earlier mentioned conflicts will not arise, and this is why, for reading the values, we don't have to use code critical sections.
Usage of the code critical sections for changing variables is not mandatory; however, it is strongly recommended to preclude the synchronization errors. Locating the reasons of such errors is quite a task.
Another useful possibility to work with the Network variable is waiting for the variable to assume the assigned value. To this end, the WaitForNetVarChange
method is used:
NetworkSuite.WaitForNetVarChange("Var1", "NEW VALUE", 10000);
This example shows the variable Var1
is set to wait for maximum 10 seconds to assume the NEW VALUE
value. If the last parameter is set equal to zero, the waiting would be endless.
This method would help to synchronize tests execution on different Slave computers.
NetworkSuite
level are analogous to the Project variables, which are dealt with in the Using global variables recipe in Chapter 3, Scripting.18.224.73.175