Forum Discussion

SriAchar's avatar
SriAchar
Occasional Contributor
8 years ago

Validating response through templates

Hello Experts,

 

In my project, I have test cases and each test case has multiple APIs being called sequentially. I have created templates for the API from where the requests contents are being pulled:

 

void insertRequestContent(tCase){

    for(int tStepCount=0; tStepCount<tCase.getTestStepCount(); tStepCount++){

        def tStep=tCase.getTestStepAt(tStepCount)

        def tStepName=tStep.getLabel()

        def directory = new File(projectPath+"\\Templates") //path where I have stored the templates

        // for each file in the directory

        directory.eachFile{ file ->

            def templateName = file.getName()

            if(tStepName.startsWith(templateName.split("\\.")[0])){   //I have named the templates as *.txt files

                tStep.getTestRequest().setRequestContent(file.getText())

           }

       }

    }
}

 

This is inserting the content of the request. The data which is being sent into these requests are parameterized using Custom Properties. I am also executing the tests using testCase.run.

 

Now my question is:

I know the format of the response. Say, the format is:

 

<Student>

    <StudentNo>1234</StudentNo>

    <StudentFirstName>ABC</StudentFirstName>

    <StudentLastName>XYZ</StudentLastName>

    <StudentGrade>5</StudentGrade>

</Student>

Can I create a template for this and validate the response data? The Groovy assertion script should pick the response tags from the template and validate each of the response data.

 

I have both xml and JSON types of responses

 

Thanks,

Srikanth 

3 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3
    Have you tried any? if you are sure that you would get that response, then try using Property Expansion instead of fixed values and see.
    • SriAchar's avatar
      SriAchar
      Occasional Contributor

      Hi Rao,

       

      Can we use Property Expansion in Response too?

       

      Thanks,

      Srikanth

      • nmrao's avatar
        nmrao
        Champion Level 3
        I meant that use property expansion in the xpath expected response with xml snippet you mentioned earlier.