- getName() : returns the name of the test case as a String
- getTestSuite() : returns the test case's test suite as a WsdlTestSuite object
- getTestStepList() : returns a Java List of test step objects corresponding to the test case's test steps
- getTestStepCount() : returns a count (as an integer) of test steps contained in the test case
- getTestStepAt(int index) : given an integer representing the zero-based index of a test step in the test case, returns an object corresponding to that test step
- getTestStepByName(String name) : returns the test step contained in the test case with name name
- findNextStepOfType(TestStep refStep, Class stepClass) : returns an object representing the next test step after test step refStep belonging to class stepClass
- findPreviousStepOfType(TestStep refStep, Class stepClass) : returns an object representing the previous test step before test step refStep belonging to class stepClass
- getPropertyList() : returns a Java List of TestProperty objects corresponding to the test case's properties
- getPropertyAt(int index) : given an integer representing the zero-based index of a property in the test case's list of properties, returns a TestProperty object corresponding to that property
- getProperty(String name) : returns a TestProperty object corresponding to the property with name name
- getPropertyValue(String name) : returns the value of the property with name name
- setPropertyValue(String name, String value) : sets the value for the property with name name to value value
On to some examples. Here's a sample test suite that compares two different services that provide postal code information:
The Setup script:
import com.eviware.soapui.impl.wsdl.teststeps.* //Getting test case info log.info("Starting TestCase: " + testCase.getName()) log.info(" From TestSuite: " + testCase.getTestSuite().getName()) //Getting test steps by class: log.info("First PropertyTransfer test step after the first test step:") nextPropTestStep = testCase.findNextStepOfType(testCase.getTestStepAt(0),PropertyTransfersTestStep) log.info(" " + nextPropTestStep.getName()) log.info("Last Groovy test step before the GetInfoByZIP-10111 test step:") prevGroovyTestStep = testCase.findPreviousStepOfType(testCase.getTestStepByName("GetInfoByZIP-10111"),WsdlGroovyScriptTestStep) log.info(" " + prevGroovyTestStep.getName())
The steps to get the name of the test case and test suite should be pretty clear, but the findNextStepOfType() and findPreviousStepOfType() methods may require some further explanation. These methods take two arguments; the first is the reference step-- in other words, when we say we're looking for a next or previous step, it's relative to this one. The second argument is a test step class indicating which type of test step we're looking for. For example, with the findNextStepOfType() call (the line starting with "nextPropTestStep="), the reference step is the first test step in our test case, retrieved with the getTestStepAt() method-- in our example suite, this is the "GetInfoByZIP-94043" test step. The second argument is a class-- specifically, the PropertyTransferTestStep class (the import statement at the top of the script saves me some extra typing here-- without it, I'd have to type the fully qualified class name com.eviware.soapui.impl.wsdl.teststeps.PropertyTransferTestStep). So we're asking for the first occurrence of a Property Transfer test step that occurs after the "GetInfoByZIP-94043" test step. Here's the resulting log output from our Setup script:
Here's our TearDown script, which just prints out the test step count and a list of the test steps:
//Test step count: log.info("Test Case contains : " + testCase.getTestStepCount() + " test steps...") //Test step list: stepList = testCase.getTestStepList() for(x in stepList){ log.info(" " + x.getName()) }
The resulting output:
The "SetZipto10111" Groovy Script test step demonstrates some of the methods for dealing with test case properties:
curTestCase = testRunner.getTestCase() //Get Property List and show current values myPropList = curTestCase.getPropertyList() log.info("Properties:") for(i in myPropList){ log.info(" " + i.getName() + " : " + i.getValue()) } //Set the Property "Zip" to "10111" curTestCase.setPropertyValue("Zip","10111")
Output in the log file:
Finally, here's the code for the "SetZipto94043" Groovy Script test case, demonstrating the getPropertyAt() and getProperty() methods:
curTestCase = testRunner.getTestCase() log.info("Current value of Zip property: " + curTestCase.getPropertyAt(1).getValue()) //Change value curTestCase.setPropertyValue("Zip","94043") log.info("Reset value; new value = " + curTestCase.getProperty("Zip").getValue())
And the resulting log output: