Forum Discussion

ashkht's avatar
ashkht
Contributor
7 years ago
Solved

How to get TestStep Status as Passed/Failed using groovy

Hello,

 

I am trying out a way which can give me TestStep Status as Failed/Passed using groovy so that based on this status i can update Pass/fail against test case in excel from where it is data driven.

 

I have one assertion step for both positive and negative validations, which in turn consist multiple assertions, I wanted to get TestStep Status for corresponding assertion step, which will help me to decide what should be written in excel either Pass/Fail.

 

In one of community post, i got clue to use tear down script but i am not aware how it has to be run and how result from this tear down script can be implemented to decide status to be written as Pass/Fail in excel.


https://community.smartbear.com/t5/SoapUI-Pro/Get-all-test-step-result-of-a-test-case/td-p/27746

 

Solution Provided as : 

for( r in testRunner.results )
log.info "TestStep [" + r.testStep.name + "] finished with status " + r.status

 

Can you please assist me on the same.

Thanks,

Ashish 

  • You can get the status of individual assertions from the Assertion Test Step with the following script in the Groovy Test Step:

    def testStep = testRunner.testCase.getTestStepByName("Assertion") //change to your name
    def list = testStep.getAssertionEntryList()
     
    for( assertion in list)
    {
      //log.info(assertion.getProperties())
      log.info("Assertion: " + assertion)
      log.info("Assertion: " + assertion.status)
    }

     

6 Replies

  • Nastya_Khovrina's avatar
    Nastya_Khovrina
    SmartBear Alumni (Retired)

    Hi Ashkht,

     

    Thank you for your post. When the test item run finishes, the test engine runs its TearDown script: https://support.smartbear.com/readyapi/docs/soapui/scripts.html

     

    To write to Excel file you can use the DataSink test step:

    https://support.smartbear.com/readyapi/docs/soapui/steps/data-sink.html

     

    BTW, why do you need the test step status, when you can get the status of the whole TestCase: 

    for ( testCaseResult in runner.results )
    {
    testCaseName = testCaseResult.getTestCase().name
    testCaseResult.getStatus().toString() }

     

    • ashkht's avatar
      ashkht
      Contributor

      Hello Anastasia,

      Thanks for your response!

       

      Can we write above mentioned script in "Groovy Script" step at the end of test case before "DataSource Loop" step, instead of being written as Tear Down Script.

       

      I am interested to get status of TestStep , ex: Assertion step, because i am looping my SOAP UI test case using DataSource Loop test step which will loop in multiple rows of excel, wherein each row corresponds to unique test condition, so that before end of loop/ moving to next test condition, i can get "Assertion" test step status and make a decision whether i should write as "Pass/Fail" for corresponding test case in same excel which is already been used as DataSource instead of using separate DataSink Test Step.

       

      Can you please assist with this updated info. PFA snippet of test steps for test case designed in SOAP UI.

      Thanks,

      • Nastya_Khovrina's avatar
        Nastya_Khovrina
        SmartBear Alumni (Retired)

        You can get the status of individual assertions from the Assertion Test Step with the following script in the Groovy Test Step:

        def testStep = testRunner.testCase.getTestStepByName("Assertion") //change to your name
        def list = testStep.getAssertionEntryList()
         
        for( assertion in list)
        {
          //log.info(assertion.getProperties())
          log.info("Assertion: " + assertion)
          log.info("Assertion: " + assertion.status)
        }