Forum Discussion

krabhishek_30's avatar
krabhishek_30
Occasional Contributor
8 years ago

Explicitly fail a test step via Groovy script

I would like to explicitly fail a test step based on a condition written in Groovy script.

If the response from API matches the condition (mentioned in Groovy script), do nothing.

If response from API does not match the condition, fail the API test step.

  • Radford's avatar
    Radford
    Super Contributor

    The WsdlTestCaseRunner object has a fail method, this can be accessed via the context variable:

     

    context.getTestRunner().fail("Insert reason here.")
  • nmrao's avatar
    nmrao
    Icon for Champion Level 2 rankChampion Level 2
    I believe that you can do assertion using "Script Assertion".
    For example:
    assert context.response, 'Response is empty or null'

    Simlarly you can do any assertion and followed by Reason for failure.

    Use of "Script Assertion" make your test case one less test steps (as separate groovy script step is not added, instead adding script assertion to your request step itself).