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 } } } } }
Solved! Go to Solution.
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.
Hi ,
It was rest request and its present in soapUI.
Thank you,
roja
Hi @nmrao ,
I have edited my post. I have interpreted wrongly so I have edited my post.
Thank you,
Roja
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.
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
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.