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...
  • 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
    }