22.8.18

API status code assertions



S-1: Status Code Assertion:-




S-2: Access Points Parameterization:-




Define access points as below




S-3: Payload – Parameterization

Define payload parameters at test suite level and refer them in pay load



S-4: Path Parameterization:-

Define property at test suite level and do the following in the request tab


S-5:Data Driven Testing:-

Add data source



Add Data source loop




Create XL – file as below





Define File path and sheet name and on run in configuration section





It will load the data as below




Click on Rest request à Form see the navigation


Request will be modify as below





S-6:Validate the response using script:-
import groovy.json.*

//grab the response
def ResponseMessage = testRunner.testCase.getTestStepByName("Req1").getPropertyValue("response")
def qa = new JsonSlurper().parseText(ResponseMessage)

//verify the slurper isn't empty
assert !(qa.isEmpty())
def arr = qa.id

//verify the Id, Type and Guid aren't null
log.info (qa.id)
log.info(arr.size())
//log.info(arr.sort())
assert qa.id!=null
assert qa.location!=null

for (int i=0;i<arr.size();i++)
{
                  log.info(arr[i])
}

S-7:- Convert XML to Json response and compare with expected values
//def response = context.expand('${Request 1#Response}')
//def User = new XmlParser().parseText(response)

import groovy.json.JsonSlurper
def response = context.expand( '${TryAddingAPIWithNewService#Response}' )
def slurper = new JsonSlurper() 
def result = slurper.parseText(response)
def errorMessageWhenAddingAPIWithNewServiceDisabled = result.faultstring.toString() 
log.info errorMessageWhenAddingAPIWithNewServiceDisabled

assert errorMessageWhenAddingAPIWithNewServiceDisabled == "The feature for adding an API or API version with new service is disabled.  For assistance, please contact the Site Administrator."

S- 8: Concatenation




S-9: Test Suite Report:-
Click on below icon to generate common reports and click on ‘Ok’.



Following report will be generated





S-10: JsonPath Match - Verifies the value specified by a JsonPath expression matches some expected value



Click on ‘Select node from to validate from current page’ and select any node. Click on ‘Ok and Save’




Assertion is passed as expected




S-11: JsonPath Existence Match - Verifies the element specified by a JsonPath expression exists in the target JSON




Click on ‘135’,





Click on ‘Save’ and send request