Sharing data between workstations

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.

Getting ready

First of all, we need to create the Network variable. To this end:

  1. Right-click on the NetworkSuite project element and select the Edit | Variables option.
  2. Right-click on the Persistent Variables area and select the New Item option. In the result, a new variable Var1 of the String type will appear on the list.
    Getting ready

How to do it...

To change the value of the Network variable, it is necessary to accomplish the following steps:

  1. First of all, enter the code critical section:
    NetworkSuite.EnterCriticalSection("Change Variable");
  2. Change the value of the variable:
    NetworkSuite.Variables.Var1 = "NEW VALUE";
  3. And finally, exit the critical code section:
    NetworkSuite.LeaveCriticalSection("Change Variable");
  4. Now, the NetworkSuite.Variables.Var1 variable contains a new value, which is accessible to any computer for the distributed testing.
  5. It is possible to write a function that will do so, automatically:
    function changeNetworkVar(varName, value)
    {
      NetworkSuite.EnterCriticalSection(varName);
      NetworkSuite.Variables.VariableByName(varName) = value;
      NetworkSuite.LeaveCriticalSection(varName);
    }
  6. Now, changing the variable will look as follows:
    changeNetworkVar("Var1", "NEW VALUE");

How it works...

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.

There's more...

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.

See also

  • The variables of the NetworkSuite level are analogous to the Project variables, which are dealt with in the Using global variables recipe in Chapter 3, Scripting.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.31.67