Forum Discussion

Said's avatar
Said
Contributor
7 years ago

How to do lookup of related data (from script)

Hi

I have the following teststeps in my testcase:

  • GetBulkData (SOAP) that receives >3000 repeating elements
  • VerifyInDb (groovy): loop through all the repeating elements and check if correctly transformed / stored in db

example of repeating elements

<ns0:EMPDATA>
	<ns0:EMPNO>1</ns0:EMPNO>
	<ns0:LASTNAME>Last Name Emp 1</ns0:LASTNAME>
	<ns0:CREWCODE>AAA</ns0:CREWCODE>
	<ns0:EMP_TYPE>COP</ns0:CREWTYPE>
	<ns0:AD_INDICATOR>D</ns0:AD_INDICATOR>
	<ns0:DATATIME>2018-09-24T02:00:00</ns0:ACTUALTIME>
	<ns0:POS_CODE>WJV</ns0:POSITIONING_CODE>
</ns0:EMPDATA>
<ns0:EMPDATA>
	<ns0:EMPNO>2</ns0:EMPNO>
	<ns0:LASTNAME>Last Name Emp 2</ns0:LASTNAME>
	<ns0:CREWCODE>BBB</ns0:CREWCODE>
	<ns0:EMP_TYPE>COP</ns0:CREWTYPE>
	<ns0:AD_INDICATOR>D</ns0:AD_INDICATOR>
	<ns0:DATATIME>2018-09-24T02:00:00</ns0:ACTUALTIME>
	<ns0:POS_CODE>ABC</ns0:POSITIONING_CODE>
</ns0:EMPDATA>

For each <ns0:EMPNO> I need to make a call to "GetEmpData" SOAP call so that I can verify if <ns0:LASTNAME>, <ns0:CREWCODE> and <ns0:EMP_TYPE> are correct. I guess I need to manipulte the request (put employee Number in the request of "GetEmpData") and I need to have access to the response, so that I can verify elements <ns0:LASTNAME>, <ns0:CREWCODE> and <ns0:EMP_TYPE>.

I have found pages where you can set properties for other testcases / test steps and then run the test case.

import groovy.sql.Sql;
import com.eviware.soapui.support.XmlHolder;
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context );
def source = groovyUtils.getXmlHolder ( "GetBulkData#Response" );

def testCase = testRunner.testCase.getTestSuite().getTestCaseByName("support");
def testStep = testCase.getTestStepByName("GetEmpData");
holder = groovyUtils.getXmlHolder(testStep); // This gives ERROR

The last statement (holder = groovyUtiles...) gives error below:

groovy.lang.MissingMethodException: No signature of method: com.eviware.soapui.support.GroovyUtils.getXmlHolder() is applicable for argument types: (com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep) values: [com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep@68d5f584] Possible solutions: getXmlHolder(java.lang.String) error at line: 16

This is where I am stuck now. My questions:

  1. What is the best way to do a lookup call from script? The call needs to be done for each EMPDATA node.
  2. Can I get an example code to do this?
  3. If above is relevant, what do I need to do to resolve above error?

 

  • Said's avatar
    Said
    7 years ago

    Himanshu,

    Thanks for your response. It did put me in the right direction.I used this statement, becaue "RawRequest" returned null.

    def empRequest = testStep.getProperty("Request").value;

     

    Below is the code that works for me:

     

    import com.eviware.soapui.support.XmlHolder;
    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context );
    def testCase = testRunner.testCase.getTestSuite().getTestCaseByName("support");
    def testStep = testCase.getTestStepByName("GetEmpData");
    def empRequest = testStep.getProperty("Request").value;
    def empReqHolder = groovyUtils.getXmlHolder(empRequest);
    
    String[] empID = new String[3];
    empID[0] = "1";
    empID[1] = "2";
    empID[2] = "3";
    
    for (int i = 0; i<3; i++) {
        log.info "empID " + empID[i];
        empReqHolder.setNodeValue("//ns:EmpID", empID[i]); // update employeenr in request
        empReqHolder.updateProperty();
        testCase.getTestStepByName(testStep.name).setPropertyValue("request", empReqHolder.getPrettyXml()); // Update request
        testStep.run(testRunner, context); // run request (with updated empId)
        def empResponse = testStep.getPropertyValue("Response");
        def empRspHolder = groovyUtils.getXmlHolder(empResponse);    
        log.info "LastName " + empRspHolder.getNodeValue("//ns1:LastName"); // Print lastname belonging to empID
    }

     

     

     

  • Hi Said,

     

    def testCase = testRunner.testCase.getTestSuite().getTestCaseByName("support");
    def testStep = testCase.getTestStepByName("GetEmpData");
    holder = groovyUtils.getXmlHolder(testStep); // This gives ERROR

    You are getting error because you are passing testStep Object to .getXmlHolder, instead of it pass either request or response in XM format to it.

     

    def request = testStep.getPropertyValue("RawRequest") // if you have parameterized request
    def response = testStep.getPropertyValue("Response")
    def holderReq = groovyUtils.getXmlHolder(request);
    def holderRes = groovyUtils.getXmlHolder(response);

     

    Click "Accept as Solution" if my answer has helped, and remember to give "kudos" :)

     

    Thanks and Regards,

    Himanshu Tayal

    • Said's avatar
      Said
      Contributor

      Himanshu,

      Thanks for your response. It did put me in the right direction.I used this statement, becaue "RawRequest" returned null.

      def empRequest = testStep.getProperty("Request").value;

       

      Below is the code that works for me:

       

      import com.eviware.soapui.support.XmlHolder;
      def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context );
      def testCase = testRunner.testCase.getTestSuite().getTestCaseByName("support");
      def testStep = testCase.getTestStepByName("GetEmpData");
      def empRequest = testStep.getProperty("Request").value;
      def empReqHolder = groovyUtils.getXmlHolder(empRequest);
      
      String[] empID = new String[3];
      empID[0] = "1";
      empID[1] = "2";
      empID[2] = "3";
      
      for (int i = 0; i<3; i++) {
          log.info "empID " + empID[i];
          empReqHolder.setNodeValue("//ns:EmpID", empID[i]); // update employeenr in request
          empReqHolder.updateProperty();
          testCase.getTestStepByName(testStep.name).setPropertyValue("request", empReqHolder.getPrettyXml()); // Update request
          testStep.run(testRunner, context); // run request (with updated empId)
          def empResponse = testStep.getPropertyValue("Response");
          def empRspHolder = groovyUtils.getXmlHolder(empResponse);    
          log.info "LastName " + empRspHolder.getNodeValue("//ns1:LastName"); // Print lastname belonging to empID
      }

       

       

       

  • groovyguy's avatar
    groovyguy
    Community Hero

    I believe you need something like the below. You have to use the response content (I use AsXml) to parse the response of the message.

     

    def request = testStep.getTestRequest();
    def response = request.getResponseContentAsXml();
    def holder = groovyUtils.getXmlHolder( response);