Contains Assertion

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

The Contains assertion searches for text or contents matching a specific pattern in the request or response.

To verify a fixed value without using patterns, use the XPath Match or JSONPath Match assertion.

Availability

This assertion is available in multiple ReadyAPI applications. Depending on the application, it validates the following data:

In... Checks... To learn more...
Functional tests The request or response contents. See Working With Assertions in Functional Tests.
Security tests The response contents. See Security Assertions.
Virtual services The request contents. See Assertions in Virtual Services.

Create an assertion

Follow these steps:

Functional test: The Assertions panel

Click the image to enlarge it.

  1. Open a test step.

  2. Click Add assertion.

In the New Assertions dialog, search for the Contains assertion or select it manually in the Property Content category.

Follow these steps:

Security tests: The Assertions panel

Click the image to enlarge it.

  1. Open a security test.

  2. Click Response Assertion next to any scan.

  3. Click in the Assertions panel

In the New Assertions dialog, search for the Contains assertion or select it manually in the Property Content category.

Follow these steps:

Virtual service: The Assertions panel

Click the image to enlarge it.

  1. Open a virtual service.

  2. Open the Assertions drop-down panel.

  3. Click in the Assertions panel

In the New Assertions dialog, search for the Contains assertion or select it manually in the Property Content category.

Setting up properties

  1. In the Content edit box, specify the value you need to find:

    ReadyAPI: Configuring the Contains assertion

    Use one of the following:

    • An ordinary string.

    • A regular expression.

      Note: Make sure to enable the Regular Expression option.

      To separate lines within a regular expression, use the (?m) flag. Also, mark the beginnings of the lines with ^ and the ends with $.

      To learn more about the regular expression syntax, see the Oracle Documentation.

    • A property expansion.

      Expressions like ${#TestCase#CustomPropertyName} command the assertion to get the needed value from the specified property.

      To select such a property visually, simply right-click the edit box and select Get Data from the context menu. This will open the Get Data dialog box. Use it to pick the needed property:

      Web service testing with ReadyAPI: Select a property value for the Contains assertion
  2. Enable additional options if you need them:

    Option Description
    Ignore Case Ignore the content case during the search.
    Regular Expression Treat the value you have entered as a regular expression.
Note: In ReadyAPI, if you use Assertion Contains with an empty string (""), the assertion will pass because an empty string is always found within the response. This is expected behavior. Ensure your tests handle empty strings properly to avoid false positives.
  • The following regular expression gets all strings whose Date value belongs to September 2014.

    <Date>2014-09-\d{2}T.{8}</Date>
  • The following regular expression checks whether the response status was either 200 OK or 202 Accepted

    <status>(OK)|(Accepted)</status>

Add more assertions for response and request contents:

See Also

Property Content Assertions
Not Contains Assertion
Message Content Assertion

Highlight search results