Validation Scripts

Document created by DPM Admin on Jul 21, 2017
Version 1Show Document
  • View in full screen mode

This topic presents a variety of SOASTA CloudTest validation scripts. Scripts can be copied and pasted directly into the SOASTA CloudTest Script Editor using Central > Scripts. Longer scripts have an accompanying image that can be clicked to pop out the full example script. Shorter scripts are presented inline (in the right column).

 

Validation Scripts

  1. Script 1: Throw an Error If a Specified Value Does Not Exist in the Prior Response

This example will throw an error if the specified text does not appear in the prior response.


First, get the Message that precedes this Script.

var msg = $context.currentItem.previousItem;

Then, get the response fromthe HTTP_BODY. If there was no response, output an informational message as such.

var response = msg.getResponse(msg.RESPONSE_HTTP_BODY);
if (response == null)
$context.result.postMessage($context.result.LEVEL_INFO, "Message " + msg.name + " received no response to validate.");
else

Then, specify the string to find.

var stringToFind = "Account Information";

Check for the value in the response. If it doesn't exist, output an error.

var searchIndex = response.indexOf(stringToFind);
if (searchIndex == -1)
{
var details = "Response:\n" + response + "\n\nValue searched for:\n" + stringToFind;
$context.result.postMessage($context.result.LEVEL_ERROR, "Expected value not found in response to Message " + msg.name, details);
}
}

msg.clearResponse();

  1. Script 2: Throw an error if a specified value does exist in the prior response

This example will throw an error if the specified text appears in the prior response.


First, get the Message that precedes this Script.

var msg = $context.currentItem.previousItem;

Then, get the response from the HTTP_BODY. If there was no response, output an informational message as such.

var response = msg.getResponse(msg.RESPONSE_HTTP_BODY);
if (response == null)
$context.result.postMessage($context.result.LEVEL_INFO, "Message " + msg.name + " received no response to validate.");
else

Then, specify the string to find.

var stringToFind = "seeing this error because you have";

Check for the value in the response. If the value does exist in the response, output an error.

if (searchIndex > -1)
{
var details = "Response:\n" + response + "\n\nValue searched for:\n" + stringToFind;
$context.result.postMessage($context.result.LEVEL_ERROR, "Error found in response to Message " + msg.name, details);
}
}

msg.clearResponse();

  1. Script 3: Throw an error if a specified value does not exist in the prior header

The Throw an error if a specified value does not exist in the prior header script looks at the previous message’s response header to see if a particular string is present. If the string is present, the validation passes; if not, the validation fails.


Attachments

    Outcomes