SoapUI: Output TestCase Results to Excel

As you can tell from the rest of my posts, this is again using SoapUI Pro and making use of the DataSink test step and the Extended Script Library.

So, in my test case results, I’d like to see the test case number, description, status, assertion, and the date it was run. In my Excel docs I have each of those as a heading and then SoapUI just starts at the next row. Since I take my initial test cases also from Excel I get the test case Id and description from that Datasource.

The DataSink step I set to be Excel (from the dropdown) and then I get the option to add properties on the left. As mentioned, I create five properties:
1) TestCaseId
2) TestCaseDescription
3) Status
4) Assertions
5) Date

TestCaseId and TestCaseDescription are easy since they are already in my Datasource:

${Datasource#TCId}
${Datasource#TCDesc}

Status can just be called using a Groovy script inline, like so:

${=testRunner.results[testRunner.results.size()-1].status}

The ‘1’ in the above example is the location of the test request in relation to the DataSink.

Assertions references a script in my Script Library, which could look like:

${=new qa.GetFailedAssertions().outputResult(testRunner)}

And then the actual script looks like:

package qa

public class GetFailedAssertions {

	def outputResult(testRunner) {	
		def tcName = testRunner.testCase.name
		def assertionList = testRunner.getTestCase().getTestStepByName(tcName).getAssertionList()
		
		for( assertion in assertionList ) 	{
			for(e in assertion.errors ) {
			return "Assertion Failure: [" + e.message + "]"
			}
		}
	}
}

Date is just today’s date with the time, again inline Groovy script:

${=new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm").format(new Date())}

Now when I run my case all these results are put into the files referenced in the File parameters of the DataSink.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s