Alerting on a specific HTTP return code

Use a custom action to sent an alert if a test execution generates a specific HTTP return code. For example, you might want to be alerted if a server error — HTTP code 500 — occurs.

Add a Validate action at the end of the script, with Match Text that does not exist in the page source. For example: "Make the test fail with a 500 code". The test will fail because this text is not in the source.

Add a Custom action at the beginning of the script before the Navigate action, with JavaScript code that checks whether the target URL exists and whether it returns HTTP code 500. If these conditions are not met, the Validate action is not executed, and the test succeeds. If the conditions exist, the Validate action is executed, and the test fails because of validation failure. The alert may specify "30500 Content Match Test Failed".

In the JavaScript in the Custom action, replace the placeholder URL with the actual target page URL, and replace return code 500 with the return code for which you want to receive alerts.

var getUrl = new AddEventHookCommand({
"eventType": "replyReceived",
"name": "directNavigate",
"handler":"if(response.request.url.indexOf('')!= -1&& response.getStatusCode()=='500'){alert('this request returns 500 code, then execute the validation action to make the test to fail');}else{script.steps[0].actions[3].type = 'do not execute';}"

See the example Custom action and Validation action in the attached script ValidateIfReturnCodeIs500.gsl.