You can automatically create API tests for web applications during manual testing using the SOAtest Smart API Test Generator. The out-of-the-box implementation of the Smart API Test Generator is designed to help you start API testing very quickly, but you can also “train” it to create more specific tests for your projects. In this section:
You can define rules that determine test generation behaviors by creating Smart Test Template (.stt) files. Smart Test Template files consist of one or more Resource Suites, which enable you to determine the paths your rules will be applied to. Resource Suites contain one or more Resource Templates. You can chain tools to Resource Templates and configure them to define specific test generation behaviors. Resource Templates also enable you to configure the specific scope that the chained rules will apply to.
When the Smart API Test Generator creates a new API test, it will read and apply the rules specified in the .stt file.
You can create and manage .stt files using the Smart Test Templates View. Additionally, you can add multiple .stt files and organize them into folders.
Choose the type of Resource Suite to create. You can create an empty suite or initialize the suite based on a service definition.
If you are using a definition file, see the following sections for additional information:
Creating Tests from an OpenAPI/Swagger Definition
Choose a method from the Method drop-down menu and specify a pattern in the Match field to identify the endpoints you want the rules in the template to apply to (see Defining Smart API Test Generation Scope). The Resolved field renders a preview of the pattern. Resource Templates inherit the Match settings from the parent Resource Suite. You can disable the Exact Match option if you want to allow the Smart API Test Generator to generate tests for all subpaths specified in the Match field. The Exact Match option is enabled by default.
When the Smart API Test Generator matches the setting in the Resource Template, configurations from all chained tools are applied. You can determine how to structure template files and configure matching patterns accordingly. See Example Smart Test Template for a common use-case.
JSON Assertor tools chained to Resource Templates can be configured to use the values from traffic if present. See Adding JSON Assertions for additional information. |
Generate a test from an existing traffic file or create a new test using the SOAtest Smart API Test Generator browser extension and the configurations defined in the .stt file will be applied.
Patterns you define in Resource Suites and Resource Templates will be matched according to the following rules:
{},
indicate wildcards and can contain any text. For example, you can specify a pattern that translates into scheme, host, and port:{scheme}://{host}:{port}
*
) also indicate wildcards. A single asterisk and curly braces, e.g., {}, may be used interchangeably: {scheme}://{host}:*/parabank/*/accounts/{id}
{scheme}://{host}:*/parabank/**/{id}
/parabank/services_proxy/bank/accounts/{id
}65535
for the port treats the port as a wildcard.By default, the Smart API Test Generator will create tests for all resources called in the scenario and only apply training tools to resources identified with the Resource Template tools. You can configure the Smart API Test Generator, however, to include or exclude specific resource URLs from test generation by specifying Ant-style patterns in the includeURLPatterns
and excludeURLPatterns
in the tst_configuration.properties file. See Test Creation Properties for additional information.
The Smart API Test Generator uses the HTTP Authentication tool for configuring authentication credentials for your tests. The HTTP Authentication tool is a special tool that you can only use in .stt files. When the Smart API Test Generator matches the settings in the Resource Template tool, credentials configured in the HTTP Authentication tool are applied to the generated tests.
See the following sections for additional information on configuring authentication settings:
SOAtest
Virtualize
The Smart API Test Generator uses the HTTP Header tool to add header fields to your tests. The HTTP Header tool is a special tool that you can only use in .stt files. When the Smart API Test Generator matches the settings in the Resource Template tool, any headers configured in the HTTP Header tool will automatically be added to the generated tests. You also can use this tool to override header values captured during test creation.
You can configure JSON Assertions chained to Resource Template tools to use values from traffic. Use ==
or equals
as the operator and set the value field [Smart - From Traffic]
.
There are several types of assertions you can use in your tests (see JSON Assertor for additional information). The following sections describes how the Smart API Test Generator applies settings for each type of assertion.
[Smart - From Traffic]
.[Smart - From Traffic]
and the operation is set to ==
or equal
.1
or 0
if the field is set to [Smart - From Traffic]
and the operation is set to ==
.1
or 0
if the field is set to [Smart - From Traffic]
and the operation is set to ==
.[Smart - From Traffic]
and if the traffic value validates successfully.0
if the field is set to [Smart - From Traffic]
.[Smart - From Traffic]
and the value validates successfully. In this case, the same traffic value will be applied to all fields in the assertion.By default, the Smart API Test Generator ignores timestamps, but it can be configured to ignore other parameters to fit your needs. See Test Creation Parameters for additional information.
You can apply assertion logic from an existing .tst file to train Smart API Test Generator. See Training the Smart API Test Generator Using a .tst File.
You can reference other test suites in your .stt file, which enables you to include additional set-up steps that may be necessary for your tests to execute properly. Only one referenced test suite will be added per Resource Template tool. Tests included by reference are added as the first test in the generated suite. See Reusing and Modularizing Test Suites for End-to-end Testing for additional information about references.
You can use existing REST Clients to teach the Smart API Test Generator authentication settings and JSON assertion logic. You can create training rules from the .tst file, Test Suite, or REST Client node. SOAtest will create an HTTP Authentication or a JSON Assertor rule under the resource template that most closely matches the path specified in the REST Client. If no match is identified, then new .stt files will be created for each rule. The .stt file(s) will contain Resource Suites and Resource Templates with their Match settings configured to match the REST Client's endpoint.
The match pattern for new .stt files is based on the type of rule you are teaching the Smart API Test Generator. For assertions, the parent suite match is set using the REST client's basePath. Subpaths are configured in a nested suite match and/or a resource template match. The resource template will be configured to match the "Exact" field at the specific method type.
For authentication, the parent suite match is set using the REST client's scheme, host, and port. The resource template contained in the parent suite will be configured to match to the REST client's basePath and all subpaths and method types.
Review the rules when prompted. Smart API Test Generator will attempt to match resources in existing .stt files and add new rules accordingly. If a matching .stt is not found, a new file will be created.
Equality assertions (assertions configured with the New assertions will be added to existing assertors in the .stt file. |
The structure of your test templates will depend on how you want to test your application. In this example, an .stt represents an application under test (CTP).
The resource suite is configured to match any scheme, port, and path at host "emdemo." As a result, any tests generated for emdemo will include tools references in the Test Reference Suite. Additionally, tests will be configured with authentication and header settings configured in the HTTP Authentication and HTTP Header tools, respectively.
Each Resource Template points to a specific path under emdemo. Any tests generated for the paths specified in each Resource Template will include configurations from the chained tools. For example, "Resource 3" is configured to match the "/em/virtualassets/manage" path. As a result, tests that contain this path will include a JSON Assertor configured to validate asset configurations that are returned in the response.