cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to read response of one rest test step

SOLVED
Highlighted
Contributor

Unable to read response of one rest test step

Hi,

 

I have 4 test steps in my test case.  My groovy script is able to read and compare response of all the test steps except the last test step. So I have tried removing all the steps and kept only one step.I'm not sure why my script is not able to read the last step. In my excel file I have 5 rows in my excel. In excel I have test step name in the col A and expected response in the col D.Basically I'm reading expected response from excel and comparing the response from soapUI.Below is the code I have used.

Appreciate your help in advance

 

def k=1
(0..context.testCase.testStepCount-1).each{
	def step1 = context.testCase.testStepList[it]
	if ( step1 instanceof RestTestRequestStep) {
		for(j=1;j<no_of_rows;j++){
			Cell f=inputSheet.getCell(0,j)
 		     step_name=f.getContents()
 		     Cell f1=inputSheet.getCell(3,j)
 		     def String step_response=f1.getContents()
 		     def String response = context.expand(step1.getPropertyValue('Response')) 
 		     if(response!=null)
 		     {
 		     response=response.replaceAll(" ","")
 		     }
 		     if(step_response!=null)
 		     {
 		     step_response=step_response.replaceAll(" ","") 
 		     }
 		     if((step1.name==step_name)&&(step_response!='')){
 		     	try{	     
 		     		JSONAssert.assertEquals(step_response,response,false)
 		     		log.info k
 		     		log.info step_name
 		     		log.info "from excel"+step_response
 		     		log.info "from UI"+response
 		     		jxl.write.Label status =  new jxl.write.Label(1,k ,"Passed")
 		     	     sheet_writable.addCell(status)
 		     	     pass_count=pass_count+1
 		     	}catch(AssertionError  e){
 		     		log.info "${e}"
 		     		String exception = e.toString()
 		     		exception=exception.replace("java.lang.AssertionError:","")
 		     		jxl.write.Label status =  new jxl.write.Label(1,k ,"Failed")
 		     	     sheet_writable.addCell(status) 
 		     	     jxl.write.Label reason =  new jxl.write.Label(5,k ,exception)
 		     	     sheet_writable.addCell(reason)
 		     	     fail_count=fail_count+1
 		     	}
 		     	k=k+1
 		     }
 		     else 
 		     if((step1.name==step_name)&&(response==null))
 		     {
 		     	 if(response==null)
				{
 		     	log.info "from else "+k
 		     	log.info "response from if"+response
 		     	jxl.write.Label status =  new jxl.write.Label(1,k ,"Passed")
 		     	sheet_writable.addCell(status)
 		     	k=k+1
 		     	pass_count=pass_count+1
				}
				else
				{
				  jxl.write.Label status =  new jxl.write.Label(1,k ,"Failed")
 		     	  sheet_writable.addCell(status)
 		     	   k=k+1
 		     	   fail_count=fail_count+1
				}
 		     }
 		     
		}
	}
}

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Hero

Re: Unable to read response of one rest test step

23 REPLIES 23
Highlighted
Community Hero

Re: Unable to read response of one rest test step

What is the type of each test step in the test case such as SOAP, REST, JDBC etc?

And where is the above script present?

NOTE: request you to format the code for better readability.



Regards,
Rao.
Highlighted
Contributor

Re: Unable to read response of one rest test step

Hi ,

 

It was rest request and its present in soapUI.

 

Thank you,

roja

Highlighted
Contributor

Re: Unable to read response of one rest test step

Hi @nmrao ,

 

I have edited my post. I have interpreted wrongly so I have edited  my post.

 

Thank you,

Roja 

Highlighted
Community Hero

Re: Unable to read response of one rest test step

Are all 4 steps of rest type? What about groovy script step? A screen shot of test case (with steps) possible?


Regards,
Rao.
Highlighted
Community Hero

Re: Unable to read response of one rest test step

By the way, why K is incremented twice?


Regards,
Rao.
Highlighted
Community Hero

Re: Unable to read response of one rest test step

Please see if the below helps.

 

Note that, don't know exactly in which cell you want to put the data n could not test. Give it a try.

context.testCase.testStepList.findAll { it instanceof RestTestRequestStep}.each { step ->	
	def k = context.testCase.getTestStepIndexByName(step.name) + 1	
	for (j = 1; j < no_of_rows; j++) {
		Cell f = inputSheet.getCell(0, j)
		step_name = f.getContents()
		Cell f1 = inputSheet.getCell(3, j)
		def step_response = f1.getContents()
		def response = context.expand(step.getPropertyValue('Response'))
		if (response != null) {
			response = response.replaceAll(" ", "")
		}
		if (step_response != null) {
			step_response = step_response.replaceAll(" ", "")
		}
		if ((step.name == step_name) && (step_response != '')) {
			try {
				JSONAssert.assertEquals(step_response, response, false)
				log.info k
				log.info step_name
				log.info "from excel" + step_response
				log.info "from UI" + response
				jxl.write.Label status = new jxl.write.Label(1, k, "Passed")
				sheet_writable.addCell(status)
				pass_count = pass_count + 1
			} catch (AssertionError e) {
				log.info "${e}"
				String exception = e.toString()
				exception = exception.replace("java.lang.AssertionError:", "")
				jxl.write.Label status = new jxl.write.Label(1, k, "Failed")
				sheet_writable.addCell(status)
				jxl.write.Label reason = new jxl.write.Label(5, k, exception)
				sheet_writable.addCell(reason)
				fail_count = fail_count + 1
			}
		} else if ((step.name == step_name) && (response == null)) {
			if (response == null) {
				log.info "from else " + k
				log.info "response from if" + response
				jxl.write.Label status = new jxl.write.Label(1, k, "Passed")
				sheet_writable.addCell(status)
				pass_count = pass_count + 1
			} else {
				jxl.write.Label status = new jxl.write.Label(1, k, "Failed")
				sheet_writable.addCell(status)
				fail_count = fail_count + 1
			}
		}
	}
}

Removed incremens of k as not needed.

 



Regards,
Rao.
Highlighted
Contributor

Re: Unable to read response of one rest test step

Hi @nmrao ,

 

All the test steps are of rest type only.I have increased k once in if and once in else. I have tried the code you have provided and it still didn't help. I have attached the screenshot of my test steps.

 

Thank you,

Roja

Highlighted
Community Hero

Re: Unable to read response of one rest test step

Thanks for that.

When you say didn't work, can you elaborate the nature of issue?


Regards,
Rao.
Highlighted
Contributor

Re: Unable to read response of one rest test step

Hi @nmrao ,

 

I have replaced the code with the one you have provided. Even after replacing one of my test step is not getting executed . I have attached the screenshot of the excel file that is generated.In the output file for the 11th step status is not getting generated.When I tried debugging its not entering the loop where comparision needs to be done. 

 

New Here?
Join us and watch the welcome video:
Top Kudoed Authors