How to Configure a Runscope Test to Pass if Comprised of Multiple Steps/Subtests and One or More of the Steps/Subtests Passes

book

Article ID: 196574

calendar_today

Updated On:

Products

BlazeMeter

Issue/Introduction

Can an API Monitoring (Runscope) test that is made up of multiple steps/subtests be configured to pass if one or more of the steps/subtests passes?  For example, if a test is made up of 3 steps/subtests and one or two of the steps/substeps passes, can the entire test be configured to pass and if so how is this accomplished?

Cause

 

 

Environment

Release : SAAS

Component : BLAZEMETER PERFORMANCE TESTING

Resolution

 

To report an entire API Monitoring (Runscope) test which consists of multiple request/subtest steps as passed when one or more request/subtest steps fails would be accomplished by adding a Post-Response script to the final request/subtest step which checks the result status of all request/subtest steps in the test and asserts the test as failed only if all steps failed otherwise the script asserts the test as passed.  The Post-Response Scripts article provides instructions for creating such a script.

So to summarize:

1.  Remove all assertions (including the default assertion automatically created) for all of the request/subtest steps in your API test.

2.  Setup unique variables in each request/subtest step to capture the results of the request/subtest step (see the Dynamic Data and Request Chaining article for more information about using variables to pass data between steps).

3.  If the last step of your API test is a subtest, you will need to pass the results of all previous request/subtest results into the last subtest step by defining parameters in the last subtest step and passing the variables of the other request/subtest steps as parameters to the last subtest step.

4.  In the last request/subtest step, add a Post-response script where you generate the appropriate assertion based on the results of all steps in the test.  For example, to assert a failed test only when all 3 steps in a test fail, your script could look as follows:

var r1 = variables.get("result1");
var r2 = variables.get("result2");
var r3 = variables.get("result3");

if (r1 == "pass" || r2 == "pass" || r3 == "pass") {
    assert.ok(true, "At least 1 subest passed");
} else {
    assert.ok(false, "All 3 subtests failed");
}