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.
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:
HI
ReplyDeletethe runner variable is 'testRunner' not 'runner'....i think. :)
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...
DeleteThe 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