Contributions
Re: How to pass NULL, BLANK and remove a field from JOSN using ready API
Hirichie, I tried below appoach to pass null, Blank("") and value for a field to json payload. 1) created datasource step ( getData), which has property bookName 2) created a groovy which will do below. def strBookName = context.expand( '${getData#bookName}' ) if(!(strBookName == "null")) { testRunner.testCase.testSteps["excelToJson"].setPropertyValue("bookName","\""+ strBookName + "\"") } else{ testRunner.testCase.testSteps["excelToJson"].setPropertyValue("bookName", "null" ) } 3)excelToJson is properties step which has property bookName 4) now my Post request payload looks like : { "job": ${excelToJson#id}, "name": ${excelToJson#bookName} } So when we have null value in excel cell, the else part of groovy will be executed and property bookName in step excelToJson will have null as value. When we have actual value than if part of the groovy will be executed and that actual value will be prefixed and postfixed by double quotes and same will be stored in bookName property of excelToJson. Thus we can achive "", null, "Jhon" all this scenarios. But really thanks for all the responses. Thanks Hemant5 years agoPlace ReadyAPI QuestionsReadyAPI Questions6.2KViews0likes2CommentsRe: How to pass NULL, BLANK and remove a field from JOSN using ready API
Hey richie, Thanks for the reply. So Is there any way to pass NULL in a field B using data-parametrization ?? I tried below in the groovy script. testRunner.testCase.testSteps["excelToJson"].setPropertyValue("job",null) log.info testRunner.testCase.testSteps["excelToJson"].getPropertyValue("job") excelToJson ==> is a properties step and it has property named job. now I use this property value in a field B of POST request in below manner. {"B":"${excelToJson#job}", "A":"String"} when we run the test case , rather than passing NULL to field B , value passed in BLANK and actual request sent out is{"B": "", "A":"String"}. So not sure how do we transfer NULL value in the request. Steps in test case are in below sequence 1) groovy 2)excelToJson (properties step) 3) Post Request Thanks Hemant5 years agoPlace ReadyAPI QuestionsReadyAPI Questions6.3KViews0likes4CommentsHow to pass NULL, BLANK and remove a field from JOSN using ready API
Hi , Please help on creating post request for below three scenarios using ready API. Suppose I have JSON object with below definition. {"A" : "String","B" : "String" } Field A and B both are mandatory field. Case 1 I want to pass below json { "A" : "Jhon" , "B": null} Case 2 I want to pass below json { "A" : "Jhon" , "B": ""} Case 3 I want to pass below json { "A" : "Jhon" } All three request are acceptable and once we post will say that "Filed B is missing as it is a mandatory parameter". Now I do not want to create three different request for above because my actual request would have lot many mandatory fields so cannot keep on creating different test request with respect to each field. How do I solve above in a same request such that i get the data from Excel for both fields and at the same time i can pass null, blank in the field B and in third case I do not pass the field it self. Thanks HemantSolved5 years agoPlace ReadyAPI QuestionsReadyAPI Questions6.5KViews0likes6Comments