cancel
Showing results for 
Search instead for 
Did you mean: 

SoapUI (Pro) > DataDriven > Message Content Assertion - How to handle decimal values

Occasional Contributor

SoapUI (Pro) > DataDriven > Message Content Assertion - How to handle decimal values

I am using ReadyAPI(SoapUI Pro) for testing of a RestAPI. For TestData I'm using DataSource (DataDriven), where i am giving the Inputs (API Input) from excel. And to test the API response i am comparing the Output from Excel (Expected results are already in excel).
For that I am using Message Content Assertion (as its easy and im not much technical). Now problem is, In excel Expected Output is say 10.0 but when i use this excel field for assertion in SoapUI (Pro) it reads 10.0 > 10. But from API Response value is 10.0. So Assertion failed. I tried to handle it in excel but no luck.
 

So need help. In SoapUI we can handle it? (so that API response(10.0) match with Assertion value 10)

 

If its not possible using Message Content Assertion, then is it possible with JSONPath Existence Match ( I have not much knowledge of Json)

11 REPLIES 11
Community Leader

Re: SoapUI (Pro) > DataDriven > Message Content Assertion - How to handle decimal values

Format cell and take data as text like this - '176.98 and then call it. Else try this code:-

def data = 176.98
log.info new Double(data).round(2)
assert new Double(result).round(2)==176.98 

Hope it works for you.

Occasional Contributor

Re: SoapUI (Pro) > DataDriven > Message Content Assertion - How to handle decimal values

Hi  


Thank you so much for your reply, your solution '176.98 works. But in my spreadsheet (which I'm using for Data Source) there are so many columns which are using formulas. And if im doing the changes ('176.98 ) then formulas does not work.
Regrading your 2nd solution, I am not sure where to add this code as i am new to ReadyAPI (SoapUI Pro) so please provide my more details where i need to add the code in ReadyAPI. Do i need to add custom properties?

I will be very thankful to you Smiley Happy

 

Thanks,
Amit

 

Community Leader

Re: SoapUI (Pro) > DataDriven > Message Content Assertion - How to handle decimal values

yes.. got your issue.. In this case, You should go for second approach:-

 

def data = 176.98
log.info new Double(data).round(2)
assert new Double(result).round(2)==176.98 

Whatever column name (Output_loanTerm) data you want to fetch for assertion.

Read that column data using Java/Groovy code and convert it into double value rounded upto 2 digit.

If you want all the column data to be changed use for loop and implement the same.

Occasional Contributor

Re: SoapUI (Pro) > DataDriven > Message Content Assertion - How to handle decimal values

Hi avidCode,

 

Thnaks for your reply. I am little bit confuser here, i tried but assetion is always pass even for wrong values as well. 

I need youe help to create the assetion: (we are using JSON as API request/response)

 

Scenarios: DataSource Testing

In Excel I have inputs as well ouputs, for one of scenario My excel (DataSource) output is :

( '${DataSource#Output_LoanTerm}' )   --> Value is 45

 

Now when i used Data Source for executing my test case API returns:
$['LoanTerm']  --> Value is 45.0

 

I want to match ( '${DataSource#Output_LoanTerm}' )  =  $['LoanTerm'] 
(45 = 45.0)

 

Assertion failed, (due to .0). I tried the Assertion using Groovy script but no luck (may be i have no experience of Groovy Script). Can you please send me an example with above case.

 

Or can we use the JSONPath Asseretion for contect match as well, If yes please help, sorry as i have no knowledge of JSON Smiley Happy

 

Occasional Contributor

Re: SoapUI (Pro) > DataDriven > Message Content Assertion - How to handle decimal values

Hi avidCode,

 

Thnaks for your reply. I am little bit confuser here, i tried but assetion is always pass even for wrong values as well. 

I need youe help to create the assetion: (we are using JSON as API request/response)

 

Scenarios: DataSource Testing

In Excel I have inputs as well ouputs, for one of scenario My excel (DataSource) output is :

( '${DataSource#Output_LoanTerm}' )   --> Value is 45

 

Now when i used Data Source for executing my test case API returns:
$['LoanTerm']  --> Value is 45.0

 

I want to match ( ${DataSource#Output_LoanTerm})  =  $[LoanTerm] 
(45 = 45.0)

 

Assertion failed, (due to .0). I tried the Assertion using Groovy script but no luck (may be i have no experience of Groovy Script). Can you please send me an example with above case.

 

Or can we use the JSONPath Asseretion for contect match as well, If yes please help, sorry as i have no knowledge of JSON Smiley Happy

 

Community Leader

Re: SoapUI (Pro) > DataDriven > Message Content Assertion - How to handle decimal values

( '${DataSource#Output_LoanTerm}' )   --> Value is 45

After this convert it into double like the below code:-

def data = 45
def newData = new Double(data).round(2)
printf("${newData}")

 So, this will give you 45.0 as output and then

$['LoanTerm']  --> Value is 45.0

Match ( ${DataSource#Output_LoanTerm})  =  $[LoanTerm] 

 

Try this again and let me know.

 

If you are ok with answer. please don't forget to accpet as solution and kudos.

Occasional Contributor

Re: SoapUI (Pro) > DataDriven > Message Content Assertion - How to handle decimal values

Hi,

 

I tired but no luck Smiley Sad

So where to add this code: 

def data = 45
def newData = new Double(data).round(2)
printf("${newData}")

In excel or Assetion window (JSON Path Expression) 

Occasional Contributor

Re: SoapUI (Pro) > DataDriven > Message Content Assertion - How to handle decimal values

Hi,

 

I tired but no luck Smiley Sad

So where to add this code: 

def data = 45
def newData = new Double(data).round(2)
printf("${newData}")

In excel or Assetion JSON Path Expression

Community Leader

Re: SoapUI (Pro) > DataDriven > Message Content Assertion - How to handle decimal values

Hey, you need to add this code where erver you are trying to do assertion.

 

And also if you are using Ready API tool use, log.info to print anything.

New Here?
Join us and watch the welcome video:
Top Kudoed Authors