Rapise 7.2+

Set Screenshot on Failure option in Test Settings.

Legacy

For this purpose define TestFinish function in your Main.js:

function TestFinish()
{
    if(Tester.GetTestStatus() != Tester.Pass)
    {
        Navigator.DoScreenshot();
    }
}

This example is designed for Web tests. There are other options besides Navigator.DoScreenshot.