从soapui groovy脚本

时间:2015-09-15 14:02:17

标签: xml groovy soapui

我的任务是从soapui中的xml获取值,以便在序列中创建下一个测试。

我使用groovy脚本

我的目标是在标签内获取文字。由于它的base64编码字符串很容易识别。

def project = testRunner.testCase.testSuite.project ;
def tcase = project.testSuites["ChangeRetentionByCopyDemoSuite"].testCases["Milestone2"] ; 
def tstep = tcase.getTestStepByName("getDocuments - GetContentURLRequest");

def responseTestSuite1 = tstep.getPropertyValue("response");

log.info(responseTestSuite1.toString());

def gutils = new com.eviware.soapui.support.GroovyUtils( context );
def holder = gutils.getXmlHolder("$responseTestSuite1");

def byteResponse = holder.getNodeValue("/S:Envelope/S:Body/g:getDocumentsResponse/text()");

log.info(byteResponse);

xml响应 getDocuments - GetContentURLRequest

    <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
   <S:Header>
      <Security xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
         <Timestamp xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
            <Created>2015-09-15T13:57:50.844Z</Created>
            <Expires>2015-09-16T13:57:50.844Z</Expires>
         </Timestamp>
      </Security>
   </S:Header>
   <S:Body>
      <getDocumentsResponse xmlns="http://asg.com/2009/03/schemas/tciadapters/getdocument">
         <result>
            <operationStatus>
               <severity>INFO</severity>
               <reasonCode>A300</reasonCode>
               <messageText>All requests completed without errors.</messageText>
            </operationStatus>
            <documents>
               <DocumentData>
                  <docId>
                     <NameValuePair>
                        <keyName>cmis:objectId</keyName>
                        <keyValue>idd_48716F01-F5F7-4702-AC80-4EC70C949121</keyValue>
                     </NameValuePair>
                  </docId>
                  <status xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                  <content>
                     <ContentSegment>
                        <data>aHR0cHM6Ly91c3J5ZTh0Y2k0bTAyLmFzZy5jb206NzQ0My9jbWlzYWRhcHRlci9nZXRjb250ZW50P3VzZXJpZD1kZXY2ZGV2aWQmcGFzc3dvcmQ9ZGV2ZWxvcCUyMzEmY21pc19pbnN0YW5jZT1GaWxlTmV0UDgrLStBdG9tUHViJnJlcG9zaXRvcnk9ZmlsZW5ldG9iamVjdHN0b3JlMSZjbWlzOm9iamVjdElkPWlkZF80ODcxNkYwMS1GNUY3LTQ3MDItQUM4MC00RUM3MEM5NDkxMjE=</data>
                     </ContentSegment>
                  </content>
                  <metadata/>
                  <properties>
                     <subrange xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                     <format xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                     <supportedFormats/>
                  </properties>
                  <retention/>
               </DocumentData>
            </documents>
         </result>
      </getDocumentsResponse>
   </S:Body>
</S:Envelope>

不幸的是,我在运行最后一行代码时遇到异常

1 个答案:

答案 0 :(得分:5)

如果你想在标签内提取文字&#34; messageText&#34;然后,您可以指定父节点和子节点,即将最后一行修改为

func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {


    locationManager.stopUpdatingLocation()

    if(locations.count > 0){


        let location = locations[0] as! CLLocation

        //            println(location.coordinate)


        if let currentLocatino = currLocation {
            if CLLocation(latitude: currentLocatino.latitude, longitude: currentLocatino.longitude).distanceFromLocation(location) > 500 {
                currLocation = location.coordinate
                self.skip = 0
                self.loadObjects()

            }
        }
        else {
            currLocation = location.coordinate
            self.skip = 0
            self.loadObjects()
        }


        CLGeocoder().reverseGeocodeLocation(CLLocation(latitude: currLocation!.latitude, longitude: currLocation!.longitude), completionHandler: {(placemarks, error) -> Void in


            if error != nil {
                println("Reverse geocoder failed with error" + error.localizedDescription)
                return
            }

            if placemarks.count > 0 {
                let date = NSDate()
                let formatter = NSDateFormatter()
                formatter.dateStyle = .MediumStyle
                formatter.stringFromDate(date)
                let pm = placemarks[0] as! CLPlacemark


                var testifempty = "\(pm.subLocality)"
                if testifempty == "nil"
                {
                    self.locationManager.startUpdatingLocation()
                    if let lbutton = self.lbutton{
                        lbutton.text = "Hello  " + "\(pm.locality)" //+ "\n" + formatter.stringFromDate(date)


                    }

                }
                else
                {
                    self.locationManager.startUpdatingLocation()
                    if let lbutton = self.lbutton {
                        lbutton.text = "Hello  " + "\(pm.subLocality)\n" // + formatter.stringFromDate(date)
                    }

                }
            }

            else {
                println("Problem with the data received from geocoder")
            }
        })

    } else {


        println("Cannot fetch your location")

    }

}