How do you use stepResult.setFailed() correctly?

Dean33
Tera Contributor

When I use the Run Server Side Script step and I set stepResult.setFailed() the step always results in a successful step when run. Even if that is the only line in script it say it is successful. Any help would be appreciated.

 

Example:

(function(outputs, steps, stepResult, assertEqual) {

stepResult.setOutputMessage('This is a test. I expect this to fail');

stepResult.setFailed();

})(outputs, steps, stepResult, assertEqual);

4 REPLIES 4

Sumanth16
Kilo Patron

Swapnil Soni1
Giga Guru

Hi Dean,

The method stepResult.setSuccess() causes the step to succeed. The method stepResult.setFailed() causes the step to fail.

Try this one-

 (function executeStep(inputs, outputs, stepResult) 
{ if (gs.nil(inputs.table))
{ stepResult.setOutputMessage(gs.getMessage("", 'table')); stepResult.setFailed(); return; }
}

If it's helpful. please mark helpful or correct.
Swapnil Soni
SNOW Developer

Dean33
Tera Contributor

Well that is exactly how I am using it. However, my results are always returning successful results. Like I mentioned in my question description all I had in my test step was the output message and the setFailed() method call. After I run the test everything displays as "All steps passed - Succeeded in 0 seconds" and the status of the step is "Success".

Hey Dean,

I had the exact same problem,  the setFailed didn't work for me, but if you throw an error the step fails because of it.

 

stepResult.setOutputMessage('Error Message');
stepResult.setFailed(); //doesn't work for me
throw 'Error'; //fails the script test step