virtRunner Scripting Object

Applies to ReadyAPI 3.57, last modified on December 20, 2024

The virtRunner object allows you to run and stop virtual services (virtual APIs) specified in ReadyAPI or deployed on VirtServer.

Object Properties

Name Description
exitCode Returns the result of the previous run or stop method.

Object Methods

Name Description
getExitCode

Returns the exitCode property.

run(virtName)

Runs the specified virtual service in ReadyAPI.

virtName

String. The name of the virtual service to run.

run(virtName, virtServerURL)

Runs the desired virtual service deployed on the specified VirtServer.

virtName

String. The name of the virtual service to run.

virtServerURL

String. The address and port of VirtServer. Usage: https://<address>:<port>.

stop(virtName)

Stops the specified virtual service in ReadyAPI.

virtName

String. The name of the virtual service to stop.

stop(virtName, virtServerURL)

Stops the desired virtual service deployed on the specified VirtServer.

virtName

String. The name of the virtual service to stop.

virtServerURL

String. The address and port of VirtServer. Usage: https://<address>:<port>.

Examples

The SOAP Sample Project shipped with ReadyAPI contains the Virtual Service Runner test steps at the beginning of each test case to run a virtual service, and at the end to stop it. For demonstration purposes, two scripts on the project level will substitute for all of these test steps. They will run the virtual service when you run the project and will stop it when the test finishes.

With the approach described above, when you run a test suite or a test case, it will not run the virtual service, and your test will fail.
  1. Double-click the project node of the desired project in the Navigator.

  2. In the project editor, open the Setup Script tab and enter the following code:

    Groovy

    virtRunner.run("ServiceSoapBinding MockService");

    When you start the test run of the entire project, this script runs the specified virtual service before the test steps.

  3. Switch to the TearDown Script tab.

  4. Enter the following code:

    Groovy

    virtRunner.stop("ServiceSoapBinding MockService");

    When the project run finishes, this script stops the specified virtual service.

If your test contains the Virtual Service Runner test step that runs or stops the same virtual service, you can disable it.

The following code snippet runs the desired virtual service deployed on the specified VirtServer. After that, it posts results of the virtual service run to the script log.

Like in the previous example, you can run this script in the Setup Script tab in the project editor.

Groovy

virtRunner.run("My Virtual Service", "https://10.0.84.226:9090")
if (virtRunner.exitCode == 0)
{
  log.info("Virtual service starts successfully")
} else {
  log.info("An error occurred: " + virtRunner.getExitCode())
}

See Also

Scripting

Highlight search results