0

I use SOAP UI for testing a REST API. I have a few test cases which are independent of each other and can be executed in random order.

I know that one can disable aborting the whole run by disabling the option Fail on error as shown in this answer on SO. However, it can be so that the TestCase1 has prepared certain data to run tests first and it breaks in the middle of its run because an assertion fails or for some other reason. Now, the TestCase2 starts running after it and will test some other things, however, because TestCase1 has not had its all steps (including those that clean up) executed, it may fail.

I would like to be able to run all of the tests even if a certain test fails however I want to be able to execute a number of particular test case specific steps should a test fail. In programming terms, I would like to have a finally where each test case will have a number of steps that will be executed regardless of whether the test failed or passed.

Is there any way to achieve this?

Alex Tereshenkov
  • 3,340
  • 8
  • 36
  • 61
  • May I suggest a slight rewording of your header? From the header it sounds like you only want to run certain steps if your test case fails, but in your description it is clear you want to always run even if it fails. So mayme rewording the header to "How to call certain steps EVEN if ...". Then your header and actual question will be in alignment. :) – Steen Nov 15 '18 at 10:01
  • @Steen, good one, updated, thanks! – Alex Tereshenkov Nov 15 '18 at 11:15

1 Answers1

2

You can use Teardown script at test case level

In below example test step fails but still teardown script runs. So its more like Finally

Alternatively you can try creating your own soft assertion which will not stop the test case even if it fails. for example

def err[]

then whenever there is an error you can do

err.add( "Values did not matched")

at the end you can check

assert err.size()>0 ,"There is an error"

log.info err

This way you can capture errors and do actual assertions at the end or alternatively you can use the below teardown script provided by SoapUI

enter image description here

Gaurav Khurana
  • 3,423
  • 2
  • 29
  • 38
  • thanks for posting this. Is it possible to specify REST requests as part of the TearDown Script instead of using the `log` object? If yes, how? – Alex Tereshenkov Nov 12 '18 at 15:46
  • I mean how can you add test steps that would not be part of your test case yet would be available to the tear down script? – Alex Tereshenkov Nov 12 '18 at 15:56
  • you can just add a single script not teststeps as finally keyword also provides you to write a single step. Also please note teardown you can run some teststeps as well. Also what you can do is. create 5 request and one groovy step and run all teststeps form there using testRunner. i.e. disable all steps and run it via groovy. Then you can control the execution. Dont fail the steps via assertion you can check status of the steps and then run the next step via groovy – Gaurav Khurana Nov 13 '18 at 02:32