Quantcast
Channel: Runscope Blog - API Monitoring and Testing
Viewing all articles
Browse latest Browse all 231

New Testing Features: Conditional Step and Cookie Handling

$
0
0

We’re happy to announce two of Runscope’s newest feature improvements for API testing  — condition steps and cookie handling. The condition step is the newest test step type that makes tests more dynamic and flexible by coupling logic to actions. Cookie handling is a new feature for testing APIs that utilize client-side cookies (i.e. JWT with single page apps).

Conditional Test Step

This new test step allows you to define an assertion and embed additional test steps that are executed only if the assertion is true. If the assertion evaluates false, those embedded steps are skipped, and the test continues to the next step. Note that a condition step assertion that evaluates to false does not make the overall test fail; however, any assertions embedded underneath the condition step that fail will make the overall test fail.

While there are many different testing scenarios that can benefit from the conditional step, here are a couple of examples of how you might use it:

  1. Consolidate multiple environment tests into a single test to improve manageability. A common practice for testing different environments (e.g. local dev, staging, production) is to create individual Radar tests for each unique environment. Doing so can introduce more complexity in terms of test case management. With the conditional test step, you can consolidate those into a single test, grouping the environment-specific test steps beneath a conditional assertion. Doing so also means having only one trigger URL across all environments.
     
  2. Create more robust and flexible tests that can react to dynamic payload responses. For performing tests in environments where API responses may vary from request to request, using conditional test steps are particularly useful. Your tests can now be fluid with those response changes, helping to reduce failure false positives with binary test assertions. For example, imagine an API method called /billing/transaction/last that returns the last transaction made by a customer. The transaction type is either a payment or dispute. Using a conditional test step you can create specific test steps for each transaction type, all within a single Runscope Radar test.
In the screenshot above, the first step is a GET request to /billing/transaction/last, and the variables {{transaction_type}} and {{transaction_id}} are extracted from the response. The second is a condition step that states: if the value of {{transaction_type}} equals payment then make a GET request to /payments/{{transaction_id}}. The third is also a condition step that checks if the transaction type is a dispute, and if so, executes a GET to the /disputes method. If either of these condition steps evaluates to false, the corresponding embedded requests would be skipped without making the entire test fail.

In the screenshot above, the first step is a GET request to /billing/transaction/last, and the variables {{transaction_type}} and {{transaction_id}} are extracted from the response. The second is a condition step that states: if the value of {{transaction_type}} equals payment then make a GET request to /payments/{{transaction_id}}. The third is also a condition step that checks if the transaction type is a dispute, and if so, executes a GET to the /disputes method. If either of these condition steps evaluates to false, the corresponding embedded requests would be skipped without making the entire test fail.

Cookie Handling

Some APIs use client-side cookies to store information about a resource or client state. For example, in a single page app, an API server may store an authentication token in a client-side cookie. Runscope test runs now have the ability to automatically handle cookies, just like a web browser.

Cookie handling is a behavior that can be turned on or off on a per test basis (off by default). When turned on, cookies will be automatically stored and sent which each request. Every test run begins with an empty cookie jar. To activate this feature for a test, navigate to the test's settings page and locate the Behaviors section.

We'd love to hear about the interesting ways that you will use conditional steps or cookie handling. If you need any help using these new features see the documentation or contact our support team. 


Viewing all articles
Browse latest Browse all 231