Forum Discussion

anagpal's avatar
anagpal
Occasional Contributor
7 years ago

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)

  • avidCoder's avatar
    avidCoder
    Super Contributor

    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.

    • anagpal's avatar
      anagpal
      Occasional Contributor

      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 :)

       

      Thanks,
      Amit

       

      • avidCoder's avatar
        avidCoder
        Super Contributor

        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.