sathyaraj
8 years agoOccasional Contributor
How to get the specific property value from SOPAUI response?
Whenever i am exeuting the testcases i will get the property value in response as myscore Arun/ten2016-12-20
here the key is myscore and value is Arun/ten2016-12-20. the date will be changing dynmically as today date append with the text 'Arun/ten'
i tried by adding the below groovy script code but its not working,
today = new Date().format("yyyy-MM-dd")
log.info today
def s=log.info("Arun/ten" + today);
assert messageExchange.responseHeaders["my_client_update"] == ["Arun/ten2016-12-20"]--i want this script to be passed.
kindly suggest the solution , what is the wrong thing here.
The below is the answer for the above post,
/** * Below is the Script Assertion * Retrieves the specified header and asserts against the expected value **/ //Change the header key as needed. def requiredHeaderKey = 'my_client_update' //Change the expected value for the above Header key //Note that below one is using the regular expression to accommodate dynamic date in the header value def expectedRequiredHeaderValue = "Arun/ten\\d{4}-\\d{2}-\\d{2}" //You may not be required to change beyond this point of the script. //Check if the response has headers assert messageExchange.responseHeaders, "There are no headers in the response" //Get & Check if the response has required Header and its value is not empty def requiredHeaderValue = messageExchange.responseHeaders[requiredHeaderKey] assert requiredHeaderValue, "Value of the response header ${requiredHeaderKey} is empty or null" if (requiredHeaderValue instanceof List) { log.info "Requested header value is ${requiredHeaderValue[0]}" assert requiredHeaderValue[0] ==~ expectedRequiredHeaderValue, "Response header value is not matching with the expected value" }
Observed similar question got answered here