Validate multiple values from Database.
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Validate multiple values from Database.
Hi all, I have a bit of a challenge. I am new to soap UI and Groovy scripting. I am comparing few values from my output to the database values. So my test case contains: 1. DataSource which will return few rows. 2. Rest request which will return the json nodes. I am using content assertion to compare values, if the DataSource returns single row my assertion works fine but when there are multiple rows it will only compare 1st row not the other rows. Is there any option to compare multiple rows that are returned?
Example:
My JSON output is something like this:
"parents": [ { "personalTitlePrefix": null, "firstName": "XYZ", "middleName": null, "lastName": "ABC", "generationCodeSuffix": null, "maidenName": null, "gender": "U", "relationship": null, "isPrimaryContact": false }, { "personalTitlePrefix": null, "firstName": "XYZ1", "middleName": null, "lastName": "ABC1", "generationCodeSuffix": null, "maidenName": null, "gender": "U", "relationship": null, "isPrimaryContact": true }, { "personalTitlePrefix": null, "firstName": "XYZ2", "middleName": null, "lastName": "ABC2", "generationCodeSuffix": null, "maidenName": null, "gender": "U", "relationship": null, "isPrimaryContact": true } ],
I need to compare FirstName, LastName,Gender and PrimaryContact values from the database.
Another question is isPrimaryContact value is 1 or 0 in DataBase, where 1 would return true and 0 would be false in Json output. How do I convert them to match the content?
Solved! Go to Solution.
- Labels:
-
Assertions
-
Data-Driven Testing
-
SOAP
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @chsekhar
If I understand correctly - to verify certain attributes have multiple values I think you could use a script assertion (script assertion on the test step) - something like the following:
//courtesy of Rao
def object = new JsonSlurper().parseText(response.text) assert object.Parents.firstName == ['XYZ', 'XYZ1', "XYZ2"]
or perhaps something like the following:
//courtesy of Rao
def json = new groovy.json.JsonSlurper().parseText(context.response) assert json.Parents.firstName.every{it == 'XYZ' || 'XYZ1' || 'XYZ2'}
Hope this helps,
cheers,
rich
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
As far as i know, you can't verify this via content assertion, for this to validate you need to write some groovy code.
1. First you just check size of parent array
2. then iterate and assert through each node you want to validate.
Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓
Thanks and Regards,
Himanshu Tayal
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi all,
@chsekhar, were the above replies helpful? If so, could you please click the button below the appropriate reply to accept it as a solution?
Otherwise, please provide us with updates.
Thank you in advance.
Olga Terentieva
SmartBear Assistant Community Manager
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@richie Thanks for your reply, I will try it out and see how it goes. Also my 2nd question was isPrimaryContact value is 1 or 0 in DataBase, where 1 would return true and 0 would be false in Json output. How do I convert them to match the content?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@HimanshuTayal Thanks for the reply. Do you have any idea how do I convert the values so I can match 1 to true and 0 to false
isPrimaryContact value is 1 or 0 in DataBase, where 1 would return true and 0 would be false in Json output.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can use if condition and setting desired values at your script level.
for ex: if DB return 1 then
def dbVal = "YOUR DB QUERY"
if(dbVal == "1"){
dbVal = "true"
}
else{
dbVal = "false"
}
Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓
Thanks and Regards,
Himanshu Tayal
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you for the replies, Himanshu!
@chsekhar, any updates on your progress?
Olga Terentieva
SmartBear Assistant Community Manager
