Applies to ReadyAPI 2.3, last modified on April 25, 2018

Below are the quick tips for performing some simple tasks in ReadyAPI TestServer code based recipes.

In This Topic

Click the links above or scroll down to find the section you need.

Configuring the Environment

Task Tip
To register a user in the Runtime Service See Running and Configuring TestServer.

Recipes

Creating

Task Java C#
To create a new recipe Call the TestRecipeBuilder.newRecipe() method. Call the TestRecipeBuilder.NewTestRecipe() method.

Back to Top

Securing

Using SSL certificates is only available in Java code-based recipes.
Task Java
To secure the recipe with keystore Call the withClientCertificate("keystoreFilePath") and withClientCertificatePassword("keystorePassword") methods for the recipe and specify the full path to the keystore file and the keystore password respectively. See Recipes With SSL Keystore.
To secure the test step with keystore Call the withClientCertificate("keystoreFilePath") and withClientCertificatePassword("keystorePassword") methods for the test step and specify the full path to the keystore file and the keystore password respectively. See Recipes With SSL Keystore.

Back to Top

Configuring Execution

Configuring execution properties is only available in Java code-based recipes.
Task Java
To configure recipe execution properties Use methods of the TestCase object. You can get it by calling the recipe.getTestCase() method.
To configure execution properties for multiple recipes Implement the RecipeFilter interface.

Back to Top

Running

Task Java C#
To prepare a recipe for execution on your computer using the default settings Specify localhost when creating RecipeExecutor:
RecipeExecutor exec = new RecipeExecutor(Scheme.HTTP, "localhost");
To prepare a recipe for execution on another computer or to use a non-default port Specify the computer address or name and the port number when creating RecipeExecutor:
RecipeExecutor exec = new RecipeExecutor(Scheme.HTTP, "computerName", 9090);
To run a recipe using HTTPS Specify Scheme.HTTPS when creating RecipeExecutor:
RecipeExecutor exec = new RecipeExecutor(Scheme.HTTPS, "localhost");
To run a recipe synchronously Call the RecipeExecutor.executeRecipe(recipe) method. See Running Test Recipes. Call the RecipeExecutor.ExecuteRecipe(recipe) method. See Running Test Recipes.
To run a recipe asynchronously (do not wait until the execution is over) Call the RecipeExecutor.submitRecipe(recipe) method. See Running Recipes Asynchronously. Call the RecipeExecutor.SubmitRecipe(recipe) method. See Running Recipes Asynchronously.

Back to Top

Cancelling Execution

Task Java C#
To abort the recipe execution Call the cancelExecution(Execution execution) method of the RecipeExecutor object. Call the CancelExecution(Execution execution) method of the RecipeExecutor object.
You can call this method if you run a recipe asynchronously.

Back to Top

Getting Execution Results

Task Java C#
To get the execution status Use the Execution.getCurrentStatus() method. See Getting Execution Results. Use the Execution.CurrentStatus property. See Getting Execution Results.
To get the execution report Use the Execution.getCurrentReport() method. See Getting Execution Results. Use the Execution.CurrentReport property. See Getting Execution Results.
To get the execution identifier Call Execution.getId(). Call Execution.Id.
To get the transaction identifier Call Execution.getExecutionResult().getTestStepResult(0)
.getTransactionId(). Use the getTestStepResult value corresponding to the test step you need transactionId for.
Not supported.
To get transaction logs for the test step Call recipeExecutor.getTransactionLog(Execution, transactionId). Not supported.
To get error messages Call Execution.getErrorMessages(). See Getting Error Messages. Call Execution.ErrorMessages. See Getting Error Messages.
To check the server response to a request

Add assertions to your request test step.

Back to Top

Getting Information on Errors

Task Java C#
To get a notification on an error Create a class implementing the ExecutionListener interface and write code for its errorOccurred method. See Getting Notifications. Create a class implementing the IExecutionListener interface and write code for its ErrorOccurred method. See Getting Notifications.

Back to Top

Exporting

Task Java C#
To export a test recipe as a JSON file Convert the created recipe to a string and save it to a file. See Exporting Text-Based Recipes to JSON File.

Back to Top

Test Steps

General

Task Java C#
To create a test step Call methods of the TestSteps object (the methods are static): TestSteps.restRequest()
TestSteps.PropertyTransfer()
Call methods of the TestSteps object (the methods are static): TestSteps.RestRequest()
TestSteps.PropertyTransfer()

Back to Top

REST Request

Task Java C#
To specify the request type (GET, POST, and so on) Call the get, post, put, or delete method of the RestRequestTestStepBuilder object.
...restRequest().get("url")
The post and put methods return an object of the RestRequestWithBody type that contains specific methods for setting the request body. See below.
Call Get, Post, Put, or Delete method of the RestRequestTestStepBuilder object.
...restRequest().Get("url")
The Post and Put methods return an object of the RestRequestWithBody type that contains specific methods for setting the request body. See below.
To set the request URL (endpoint) Pass the URL as a parameter to the get, post, put, or delete method (see the example above), or call the withURL(String uri) method. Pass the URL as a parameter to the Get, Post, Put, or Delete method (see the example above), or call the WithURL(String uri) method.
To add a custom header to the simulated request Use the withHeader() method. Use the WithHeader() method.
To change the request body, media type, or encoding Call post or put to get an object of the RestRequestWithBody type and then use the withRequestBody, withMediaType, or withEncoding methods correspondingly. Call Post or Put to get an object of the RestRequestWithBody type and then use the WithRequestBody, WithMediaType, or WithEncoding methods correspondingly.
To add parameters of various types Depending on the parameter style, use the following methods:
  • addQueryParameter
  • addPathParameter
  • addMatrixParameter
  • addHeaderParameter
Depending on the parameter style, use the following methods:
  • AddQueryParameter
  • AddPathParameter
  • AddMatrixParameter
  • AddHeaderParameter
To specify request authentication data Create an object that will contain authentication data and add this object to the request by using the setCredentials method. See Authentication Data. Create an object that will contain authentication data and add this object to the request by using the SetCredentials method. See Authentication Data.
To add assertions See the Assertions section below. See the Assertions section below.

Back to Top

SOAP Request

SOAP requests are only supported in Java code-based recipes.
Task Java
To specify the binding Use the forBinding method.
To select an operation Use the forOperation method.
To add parameters Use the withParameter or withPathParameter method.
For the withParameter method, specify the property name and value.
For the withPathParameter method, specify XPATH to the property and its value.
To add assertions See the Assertions section below.

Back to Top

JDBC Request

Task Java C#
To create a JDBC Request test step
  1. Create a connection object:
    JdbcConnection connection =
    new JdbcConnection(DRIVER, CONNECTION_STRING);

  2. Add the test step by calling the jdbcRequest method of the connection object and by specifying the SQL query as its String parameter:
    newTestRecipe().addStep(connection
    .jdbcRequest("Select Persons.PersonID From Persons")

See JDBC Code-Based Recipes.

  1. Create a connection object:
    JdbcConnection connection =
    new JdbcConnection(DRIVER, CONNECTION_STRING);

  2. Add the test step by calling the JdbcRequest method of the connection object and by specifying the SQL query as its String parameter:
    TestRecipeBuilder.NewTestRecipe().AddStep(connection
    .JdbcRequest("Select Persons.PersonID From Persons")

Back to Top

Assertions

Task Java C#
To create assertions Call methods of the Assertions object like Assertions.jsonPathCount, Assertions.contains, Assertions.validStatusCode, and others, then call the addAssertion(...) method of the request step object. See Adding Assertions. Call methods of the Assertions object like Assertions.JsonPathCount, Assertions.Contains, Assertions.ValidStatusCode, and others, then call the AddAssertion(...) method of the request step object. See Adding Assertions.
To name the assertion Call the .named("New Assertion Name") method for the created assertion.

Back to Top

Data Sources

Task Java C#
To specify a data source Call the .addStep(excelDataSource) method, or a similar method for other data source types. See an example in Using DataSources. Call the .AddStep(ExcelDataSource) method or a similar method for other data source types. See an example in Using DataSources.
To specify a DataSource identifier for reference Call the .withName("datasource_name") method. Call the .WithName("datasource_name") method.
To implement a DataSource loop Add child test steps to the DataSource step by calling the .addTestStep() method. These child steps will be executed as a data loop body. Add child test steps to the DataSource step by calling the .AddTestStep() method. These child steps will be executed as a data loop body.
To refer to a DataSource property in a request parameter

Use the ${dataSourceStepName#propertyName} syntax.

For an example of working with data sources, see Using DataSources.

Back to Top

Data Generators

Data Generators are only supported in Java code-based recipes.
Task Java
To specify a data source using the data generator Call the .addStep(dataGenDataSource) method and specify the generator in its properties. See an example in Using Data Generators
To specify an identifier for reference Call the .named("DataGenName") method.
To implement a DataSource loop Add child test steps to the DataSource step by calling the .addTestStep() method. These child steps will be executed as a data loop body.
To refer to a DataSource property in a request parameter Use the ${dataSourceStepName#propertyName} syntax.

For an example of working with data generators, see Using Data Generators.

Back to Top

Property Expansion

The property expansion feature lets you use values of test step properties. This is needed if you want to pass values to properties of another test step or to an assertion.

Task Java & C#
To refer to a property Specify the property expansion expression in the same way you do this in the ReadyAPI UI, for example:
${dataSourceStepName#PropertyName}
See Expansion Syntax and Dynamic Properties.

Back to Top

Plugin-Provided Test Step

Test steps provided by plugins are only available in Java code-based recipes.
Task Java
To add a plugin test step
  1. Copy the plugin .jar file to the *.soapui folder in your user directory.

  2. In your test recipe, call the .addStep(pluginTestStep() method.

  3. Call the named("My Test Step typeName") method and specify the typeName property of the PluginTestStepConfigurator annotation.

See Plugin-Provided Test Steps in Code-Based Recipes.

To specify test step properties Call the withConfigProperty("property", "value") or andWithConfigProperty("property", "value") method for each test step property.

Back to Top

Scripting

You can include Groovy scripts into your test recipes to perform test actions for which there is no predefined test step:

Task Java
To add Groovy scripts Call the TestSteps.groovyScriptStep(scriptCode) method and pass the desired script to it as a parameter (string). See Running Groovy Scripts.

Back to Top

See Also

Creating Java Code-Based Recipes
Code-Based Recipes