free seo tool

List testSteps using Groovy Script in soapUI

Let us see how can we get a list of all the test steps available in a particular testCase in soapUI. This is a simple script and might be useful if you need more control on the testSteps individually.


See the example below.

// This will get the list of all testSteps in the testCase
def testSteps = context.testCase.getTestStepList()
testSteps.each{
// This block will loop through the test steps and print the test step name to the log
log.info(it.name)
}
18 comments:
  • Ajay says:
    February 27, 2012

    May I know how can I loop through test cases if I have number of test cases in a test suite?

    In the above example you have loop through test steps. I want to achieve one step higher level.

    Thanks

  • Sudeesh says:
    February 28, 2012

    Thanks Ajay for visiting my website.
    You can loop through the test cases in a test suite by using the below groovy script.

    Use below groovy script If you are planning to do this from a soapUI test step

    def testCases = context.testCase.testSuite.getTestCaseList()
    testCases.each{

    log.info(it.name)

    }

    Use the below code if you are planning to do tis from the testSuite setup script

    def testCases = testSuite.getTestCaseList()
    testCases.each{

    log.info(it.name)

    }

    Hope this helps.

  • Ajay says:
    March 01, 2012

    Thank you very much Sudeesh for giving prompt response. I will try this and let you know if this worked for me. Can you please share your email address to get in touch with you?

    Thanks
    Ajay

  • Sudeesh says:
    March 03, 2012

    Hi Ajay,

    You may post your comments or questions on this blog and it will trigger an email to me and I will respond as early as I can.

  • Ajay says:
    March 09, 2012

    Hi Sudeesh,

    I wanted to iterate through number of testcases and multiple test steps inside a test case to automate something through groovy script. I think to iterate over test suits would it be again api on similar lines of testcases? although I have not looked into the api.

    Anyway thanks for the help.

    -Ajay

  • Sudeesh says:
    March 11, 2012

    You are very welcome Ajay..

  • Anonymous says:
    March 13, 2012

    Hi,

    I've to export the failed test cases along with the test step failure responses, using the groovy script.
    Could you please help me in retrieving the testStep response with its name.

    Thanks in advance.
    Naveen

  • Sudeesh says:
    March 13, 2012

    Hi Naveen,

    Can you be bit more specific? When you say you need to get the test step failure responses, does that mean you need to get all the failed assertion details on a test step? Or you want to capture the webservice response if it has any failed assertion?

    Regards
    Sudeesh

  • Anonymous says:
    March 14, 2012

    Hi Sudeesh,

    Thanks for the immediate response.
    Currently I'm exporting the Test Case Name and Results (means Test Case is Passed or Failed) to an excel sheet. For this functionality I've to add the test step name and all failed assertion details.

    And also I'm seeing more advantages if I capture the webservice response for any failed assertion.

    Regards,
    Naveen

  • Ajay says:
    May 24, 2012

    Hi,
    I have created a TestCase of 10 Test Steps. The First Step is Properties where i have set two diff values for x and y. Now I want a groovy script to add these two numbers. So that I can put a X-Path match Assertion in my request to match the value.

    Thanks,
    Ajay Kumar
    k.ajay95@gmail.com

  • Sudeesh says:
    May 31, 2012

    Sorry for the delay Ajay..Try this
    def x = context.expand( '${Properties#x}' ).toInteger()
    def y = context.expand( '${Properties#y}' ).toInteger()
    log.info(x+y)

  • Shivaraj says:
    August 20, 2013

    HI Sudesh,

    I want to loop through multiple test cases and within that multiple test step ..which is loop within a loop how can i achieve this?

    Thanks & Regards,
    Shivaraj G

  • This comment has been removed by the author.
    Shivaraj says:
    August 20, 2013

    This comment has been removed by the author.

  • Shivaraj says:
    August 20, 2013

    Hey Sudesh,

    I found the solution below is the code for same


    def testCases = context.testCase.testSuite.getTestCaseList()
    testCases.each
    {
    for (testSteps in it.testStepList)
    {
    log.info testSteps.name
    }
    }
    log.info 'Completed...'

  • Anonymous says:
    June 13, 2014

    Hello All,

    I am trying to create a script on a "Test case level", that get Username and Password params, which are set on a project level and set them to all test steps, that belongs to the test case. Do you have any ideas, how can I do that.

    Thank you in advance :)

  • Anonymous says:
    November 20, 2015

    How to get result of each step of the TestCase.

  • Anonymous says:
    April 20, 2017

    Hi...i am executing a SQL query inside groovy and displaying the result in the log..but i want to write the same query results to excel ..how can i do that

  • Anonymous says:
    December 14, 2017

    Nice blog you have created.

    I need to save the testcase/teststep names in a array in order to generate the report so kindly help me on this.

Post a Comment

This is a new website mainly for SOA Testers using soapUI. Let me know your thoughts/ suggestions.