roja1
5 years agoContributor
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 } } } } }