How to get pass/fail status of groovy scripting in excel sheet
Hello Everyone, I am taking data from excel sheet for that I am using data source. I have written groovy script for asserting response. I want get status of groovy scripts status as pass or fail and...
I use one Groovy script per condition to test. In my own main test suite, I have approx. 20 groovy scripts.
I suppose you could return an array from your groovy script where each element is a condition test and then update your datasink step to reference the element of interest. Not tried, but I imagine it's possible. You could also return a JSON object from the Groovy script. E.g.
OK, in your test, I'm assuming it looks similar to the following...
So, you have a datasource, where each row is a single 'test'. When the test runs, SoapUI iterates over each row in the data by calling the service itself, then the Check Surname script, then the Check Forename script. It loops back using the datasource loop and does this until there are no more rows.
Based on what you initially asked and then making some assumptions, you have assertions in your Groovy script and what you want are the results of the assertions put into Excel. Assertions are fine to an extent, but if a step fails the test stops. You know which row fails, but you don't know how many more failures you have until you fix this error and re-run.
In my Groovy scripts, and as mentioned at the start, I do not use assertions in Groovy scripts. Instead, I return 'PASS', 'FAIL' or 'Not Checked'.
Here's an example of what my Check Surname Groovy script might look like....
// Let's compare expected surname with the surname returned from API.
// Get the expected value form the datasource.
def expectedSurname = context.expand( '${DataSource#SURNAME}' );
// Get the surname returned from the service
def actualSurname= context.expand( '${Some Service Call - REST Request#Response#$[\'message\'][0]}' );
def result;
// Check!
if (expectedSurname.contains(actualSurname)){
result = 'PASS';
} else {
result = 'FAIL';
}
return result;
Now, I want to record the result of this but I also want to record the result of this check for each row in my datasource. This is where datasinks come into play.
Here's the flow of the test with the Datasink step added.
We're going to use the Datasink to 'record' each iteration. Note how it is the last step before the end of the loop. It has to be here as we need to run the service call and the checks before recording them.
Let's have a look at an example Datasink. Note, I have not configured sink type (file, Excel, db etc.) we're just focussing on how to get certain values.
Each row in the table above shows what columns we want in our output and where to get it from.
When I said you cannot write into your datasource, but you can copy values from the datasource and put then into the datasink, the first two rows show you how to achieve that. The $ thing tells SoapUI we're going interpolate some value. The first part of the $ syntax is the step to refer to; then #, then the value from that step. You also saw examples in the Groovy scripts earlier. Rows three and four show how we 'grab' the results of our checks. The output will look like...
ExpectedSurname
ExpectedForename
SurnameCheckResult
ForenameCheckResult
Scholes
Paul
PASS
PASS
There is no need for custom properties, property transfers on anything like that.
Thank you for this brief answer. I have just one more doubt like in your case you are checking one condition in one groovy script. But in my case I have to check around 20 conditions in a single groovy script. So for that I can't use if else condition for all 20 condition. So how can I write my groovy script.
I use one Groovy script per condition to test. In my own main test suite, I have approx. 20 groovy scripts.
I suppose you could return an array from your groovy script where each element is a condition test and then update your datasink step to reference the element of interest. Not tried, but I imagine it's possible. You could also return a JSON object from the Groovy script. E.g.