Forum Discussion
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 :)
( '${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.
- anagpal6 years agoOccasional Contributor
Hi,
I tired but no luck :(
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)
- anagpal6 years agoOccasional Contributor
Hi,
I tired but no luck :(
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
- avidCoder6 years agoSuper Contributor
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.
- anagpal6 years agoOccasional Contributor
I tried in JSONPath Asertion: Here in example, API Response - $['availableIncome'] = 1420.0
And in Expected result, I am checking the value from my excel (test Data expected output = 1420)
In expected result i added:
def data = ${TestData-StandardLoan#Output_AvailableIncome} def newData = new Double(data).round(2)
printf("${newData}")But it doen't work
Related Content
- 8 years ago
Recent Discussions
- 10 days ago