Vous êtes sur la page 1sur 4

Groovy 9 capturing RawRequest & Response

Posted: July 15, 2011 in context, groovy, messageexchange, soapUI, teststep Tags: automated testing, automation, automation using soapui, groovy, groovy script, rawrequest soapui teststep, request, soapUI, soapui groovy, soapUI testing, testrunner, teststep

7 Few months back i was struggling to capture the Raw Request data from the test step and to store it (together with response) into a file. Now you might be wondering why to struggle so much if the test step request data can be simply accessed using : testCase.getTestStepByName(myTestStep).getProperty(Request).getValue() or context.testCase.getTestStepAt(0).getProperty(Request).getValue() or testRunner.testCase.getTestStepAt(0).getProperty(Request).getValue() Well above script snippets will fetch the request data from the mentioned/selected test step. However, if your test is parametrized then this (request data) will also appear as in same way as it appears in request window [i.e., not with actual parameter values]. Since, it is a parametrized request the original values of parameters can be found in the Raw tab of the teststep request window. This concept can be compared to PreProcessors in C or Inline function of C++ where the actual values of parameter will be replaced before compiling the program. Here also, before sending out the request data (or say encapsulating it in SOAP envelope) to the server the parameter values will be replaced with each parameter calls in the test request. If raw request data not used, then while performing the comparison of the different request & response data after final run, it would be difficult for us to trace what parameter value was passed during teststep run. To overcome such issues, soapUI team also exposed couple of methods which can be used to extract the RawRequest / RawResponse data and so on. Shared below is one of the ways to get the raw request data : messageExchange.getRequestContent().toString() In this series of Groovy blogs [numbered 10], i will be sharing very frequently used 10 groovy scripts which should be on your finger tips. These would come handy in order to perform any Automation using the Groovy in soapUI. /* @Author : Pradeep Bishnoi @Description : Collection of groovy script snippets required to achieve automation in soapUI */ 1. Using Log variable log.info(Any Text message + anyVariable)

2. Using Context variable def myVar = context.expand( ${#TestCase#SourceTestStep}) //will expand TestCase property value into the new variable context.testCase // returns the current testCase handle 3. Using TestRunner variable testRunner.testCase.getTestStepByName(TestStepName) testRunner.testCase // return the handle to current testCase testRunner.testCase.testSuite.project.testSuites["My_TestSuite"] 4. Using MessageExchange variable messageExchange.getEndpoint() //endpoint to the selected teststep messageExchange.getTimestamp() //timestamp messageExchange.getTimeTaken() //time taken to process the request/response 5. Using Project, TestSuite, TestCase, TestStep methods def project = testRunner.testCase.testSuite.project def project = context.testCase.testSuite.project def myTestSuite = project.getTestSuiteAt(IndexNumber) def myTestSuite = project.getTestSuiteByName(Name of the TestSuite) def myTestCase = myTestSuite.getTestCaseAt(IndexNumber) def myTestCase = myTestSuite.getTestCaseByName(Name of the TestCase) def myTestStep = myTestCase.getTestStepAt(IndexNumber) def myTestStep = myTestCase.getTestStepByName(Name of the TestStep) 6. RawRequest & RawResponse messageExchange.getRequestContentAsXml.toString() messageExchange.getResponseContentAsXml.toString() 7. groovyUtils & XmlHolder def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context ) def holder = groovyUtils.getXmlHolder (Assert_Script#Response) 8. Converting String into Integer & Integer into String using groovy anyStringVar = anyIntegerVar.toString() anyIntegerVar = anyStringVar.toInteger() 9. Reading & Writing user-defined property with Groovy def userIdInStep = testRunner.testCase.getTestStepByName( UserDefinedProperty ) def userIdStr = userIdInStep.getPropertyValue( myPropertyName ); userIdInStep.setPropertyValue(myPropertyName, StringValueAsInput)

Groovy 8 creating and manipulating Excel file using Groovy script in soapUI
Posted: July 4, 2011 in groovy, soapUI Tags: automated testing, automation, automation using soapui, JXL api, soapUI, soapui assertion groovy, soapui excel api, soapUI excel export, soapui groovy, soapUI testing, soapUi tutorial, testing, webservices

48 Many of soapUI users wonder, if they can create and manipulate the data inside an Excel file using the soapUIs groovy scripting. Well answer is YES and through this blog i am putting an end to their concerns / questions. As i might have mentioned in my previous blogs that Groovy Script together with soapUI provides utilitarian, seamless & efficient functionalities with infinite possibilities. So, i would say your thinking is the limit, rest almost everything can be achieved using Groovy in soapUI. From eviware forum, i found that soapUI is using the free Java Excel API to communicate or manipulate data in the Excel files. So, all this can be achieved using the JXL.jar file. All you need do is place the JXL api file in the lib folder of %SOAPUI_INSTALL_DIR%. This file can be downloaded @ http://sourceforge.net/projects/jexcelapi/files/jexcelapi/2.6.12/jexcelapi_2_6_12.zip/download /* @Author : Pradeep Bishnoi @Description : Manipulate the data inside an Excel file using jxl api in groovy @Ref : Thanks to Andy Khan for sharing the reference documents about JXL API. */ import jxl.* import jxl.write.* Workbook workbook = Workbook.getWorkbook(new File(c:\\myfile.xls)) Sheet sheet = workbook.getSheet(0) Cell a1 = sheet.getCell(0,0) // getCell(row,column) place some values in myfile.xls Cell b2 = sheet.getCell(1,1) // then those values will be acessed using a1, b2 & c3 Cell. Cell c2 = sheet.getCell(2,1)

workbook.write() workbook.close() /* code lines second test step*/ WritableWorkbook workbook1 = Workbook.createWorkbook(new File(d:\\output.xls)) WritableSheet sheet1 = workbook1.createSheet(Worksheet Number 1, 0) log.info(sheet1.isHidden()) Label label = new Label(0, 2, Text input in Excel); sheet1.addCell(label); workbook1.write() workbook1.close() Keep watching this space soon i will be posting about how to export the test result & certain other things using the Groovy into the Excel file. NOTE : Off late it has been observed that on performing the copy paste of this code from wordpress to soapui, user are facing some issues. Well it is because soapui script editor doesnt recognize certain character used by wordpress (like double quotes ). Workaround for this issue is, after pasting the code in editor replace all double quotes + special character manually.

Vous aimerez peut-être aussi