soapUI: Scripting Objects - WsdlTestSuiteRunner Class

Looking over traffic on past posts, I can see that one of the more popular topics has been the walk-through of data looping using scripting in soapUI, so I thought it might be a good idea to return to the topic in general, and the soapUI API in particular.  By Smartbear's own admission, it's pretty massive-- on the one hand, it's a testament to how much is packed into the program to begin with, but wading through the Javadoc (you can find it here) can get a bit tedious.  In the next few posts I'm going to try to review some of the objects you're likely to be interested in when you begin to use scripting in soapUI.

Obviously, these posts will be far from complete; to avoid biting off more than I can chew, I'm going to limit the discussion to scripting via the "containers" provided in soapUI-- in other words, the Setup and TearDown scripts available at the test suite and test case levels and Groovy Script testing steps.  I'm also not providing constructor methods, the assumption being that objects will be accessed directly or indirectly via the variables (like the runner variable) provided by soapUI.

With each post I'll try to tackle one or two objects and some of their methods.  This week we'll look at the WsdlTestSuiteRunner object.

WsdlTestSuiteRunner Class

A WsdlTestSuiteRunner object is easily accessible in soapUI via the runner variable available in a web service test suite's Setup and TearDown scripts.  As you might expect, it controls execution of the test suite, but it can also be used to access run results and other useful scripting objects.

A few of its methods:

- getResults() : returns a Java List of TestCaseRunner objects (see the post for the WsdlTestCaseRunner class, which is generally what you'll be dealing with) corresponding to the suite's test cases; these can be used in turn to access test step results
- getTestSuite() : returns a WsdlTestSuite object representing this test suite runner's test suite
- getStartTime() : returns the time (as a long) the runner was last started
- getTimeTaken() : returns the time taken (as a long) since the runner was last started
- getStatus() : returns the test suite's run status (as defined in the TestRunner.Status enum type; possible statuses include CANCELED, FAILED, FINISHED, INITIALIZED, RUNNING, and WARNING)

Here's a sample script (from the Setup script for a standard web service test suite called "Object Model Test Suite") that demonstrates some of these methods:

//Demonstrating the object type provided by the runner variable
log.info(runner.toString())
//Getting the runner's test suite
tsMySuite = runner.getTestSuite()
log.info("Name of Test Suite is " + tsMySuite.getName())
//Get test suite run start time
tsStart = runner.getStartTime()
//Convert from long to date format and display
startTime = new Date(tsStart)
log.info(startTime)
//Display test suite status
log.info(runner.getStatus())

Here's the corresponding output in the script log window when the test suite is run:



Here's an example TearDown script:

//Get test suite status
log.info(runner.getStatus())
//Get test suite time taken
tsTimeTaken = runner.getTimeTaken()
log.info("Time Taken: " + tsTimeTaken + "ms")
//Get results as List of TestCaseRunners
lstTCRunners = runner.getResults()
//Iterate through test case runners to get test case info and statuses
for(tcr in lstTCRunners){
 log.info("Test case name: " + tcr.getTestCase().getName())
 log.info("Test case status: " + tcr.getStatus())
}

And the TearDown script's corresponding output in the script log window:

3 comments:

  1. HI

    the runner variable is 'testRunner' not 'runner'....i think. :)

    ReplyDelete
    Replies
    1. I see the "runner" variable provided for the test suite level Setup and TearDown scripts; in the test case level Setup and TearDown scripts it's called "testRunner". But I've yet to upgrade to the latest version, so I'm not sure if there may have been a change to make the variable names consistent...

      Delete
  2. The above logic is not working for the Disabled Test Cases. I have a requirement to capture all the Test Case Name and the status. But the above logic is working only for the Enabled Test Cases. Could some of one help me on how to get the Name of the Disabled Test Cases?

    ReplyDelete

Please be respectful of others (myself included!) when posting comments. Unfortunately, I may not be able to address (or even read) all comments immediately, and I reserve the right to remove comments periodically to keep clutter to a minimum ("clean" posts that aren't disrespectful or off-topic should stay on the site for at least 30 days to give others a chance to read them). If you're looking for a solution to a particular issue, you're free to post your question here, but you may have better luck posting your question on the main forum belonging to your tool's home site (links to these are available on the navigation bar on the right).