WaitFor Method

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.

Description

The WaitFor method tries to synchronize the test execution flow of the current project with test execution flows of other projects by using a particular synchronization point (synchpoint).

When the WaitFor method is used, the execution of the current project is suspended until any of the following events occurs:

  • Other projects, which have a synchpoint with the same name, execute their tests up to the operation or script line that calls the WaitFor method for the same synchpoint (this line is executed as well);

  • The specified time limit is reached.

If at least one of the projects subscribed to the synchpoint is not synchronized within the specified period, synchronization will not be made.

Declaration

SynchPointObj.WaitFor(Timeout)

SynchPointObj An expression, variable or parameter that specifies a reference to a SynchPoint object
Timeout [in]    Optional    Integer Default value: 0   
Result Boolean

Applies To

The method is applied to the following object:

Parameters

The method has the following parameter:

Timeout

Sets the time limit in milliseconds. 0 (the default value) means the waiting time is infinite.

Result Value

True if synchronization is made, and False otherwise.

Remarks

  • Regardless of the method result value (True or False), the test engine considers the project has gone through the synchronization point.

    We will illustrate this by citing an example. Suppose you have two projects, Project A and Project B, that need to be synchronized. Suppose that in Project A you call the WaitFor method with some timeout specified. Also, suppose that this method call returns False for some reason (this may happen, for example, if Project B was unable to reach the synchronization point within the expected time period).

    Though the method returned False, the test engine will consider Project A has gone through the synchronization point. Now, if you call the WaitFor method in Project B, this method call will return True as if both projects reached the synchronization point at the same time.

  • To synchronize execution of projects via synchpoints, you can also use the NetworkSuite.Synchronize method.

  • If a slave project has the specified synchpoint, but does not call for the SynchPoint.WaitFor (or NetworkSuite.Synchronize) method for this synchpoint, while the other projects are waiting for the synchronization by that synchpoint, the synchronization will never be reached. In order to prevent synchronization from hanging, either keep track of all your projects’ synchpoints and synchronization methods, or use the Timeout parameter of the WaitFor or Synchronize methods to set the synchronization timeout for your projects.

  • If a project that has a synchpoint stops running before calling WaitFor for this synchpoint, TestComplete considers the project does not have this synchpoint and the WaitFor method called by other projects does not wait for that project.

Example

The following example demonstrates how you can access the synchpoint collection from script and synchronize tests execution by using the desired synchpoint from this collection. The example uses the SynchPoint.WaitFor method to simultaneously start creating new files on different computers. Remember that this code must be added to all the projects that will create files.

JavaScript, JScript

...
// Obtain the collection of synchronization points defined in the current project
MySynchPointCollection = NetworkSuite.SynchPoints;

// Obtain the synchpoint named Synchpoint1 from the collection
MySynchPoint = MySynchPointCollection.Synchpoint1;

// Synchronize the script execution flow of the current project with script execution flows of other projects
MySynchPoint.WaitFor();

// Call the routine that creates files
CreateFiles(0);
...

Python

# ...
# Obtain the collection of synchronization points defined in the current project 
MySynchPointCollection = NetworkSuite.SynchPoints
# Obtain the synchpoint named Synchpoint1 from the collection 
MySynchPoint = MySynchPointCollection.Synchpoint1
# Synchronize the script execution flow of the current project with script execution flows of other projects 
MySynchPoint.WaitFor()
# Call the routine that creates files 
CreateFiles(0)

VBScript

...
' Obtain the collection of synchronization points defined in the current project
Set MySynchPointCollection = NetworkSuite.SynchPoints

' Obtain the synchpoint named Synchpoint1 from the collection
Set MySynchPoint = MySynchPointCollection.Synchpoint1

' Synchronize the script execution flow of the current project with script execution flows of other projects
Call MySynchPoint.WaitFor

' Call the routine that creates files
Call CreateFiles(0)
...

DelphiScript

...
// Obtain the collection of synchronization points defined in the current project
MySynchPointCollection := NetworkSuite.SynchPoints;

// Obtain the synchpoint named Synchpoint1 from the collection
MySynchPoint := MySynchPointCollection.Synchpoint1;

// Synchronize the script execution flow of the current project with script execution flows of other projects
MySynchPoint.WaitFor;

// Call the routine that creates files
CreateFiles(0);
...

C++Script, C#Script

...
// Obtain the collection of synchronization points defined in the current project
MySynchPointCollection = NetworkSuite["SynchPoints"];

// Obtain the synchpoint named Synchpoint1 from the collection
MySynchPoint = MySynchPointCollection["Synchpoint1"];

// Synchronize the script execution flow of the current project with script execution flows of other projects
MySynchPoint["WaitFor"]();

// Call the routine that creates files
CreateFiles(0);
...

For more information on using the WaitFor method and for sample code, see Synchronization Points.

See Also

Distributed Testing
Synchronization Points
Synchronizing Projects in Network Suites

Highlight search results