Soapui (groovy Script 2) Do not ask why Series 2

Source: Internet
Author: User
Tags soapui groovy script

The returned results may need to be verified during case construction. You can use the groovy script to complete this function. The specific steps are as follows:

(1) Use the groovyutils provided by soapui to retrieve the returned XML message xmlholder

Def policyutils = new COM. eviware. soapui. Support. policyutils (context)

Def holder = policyutils. getxmlholder ("balancequery # response ")

(2) Use XPath in xmlholder to obtain the returned field content
Log.info (holder. getnodevalue ("// Uvs: balancequery/Uvs: balancequeryrequest/Uvs: requestmessage/Uvs: messagebody/Uvs: subscriberno "));

Def messagebody =
Holder. getdomnode ("// Uvs: balancequery/Uvs: balancequeryrequest/Uvs: requestmessage/Uvs: messagebody ")

Log.info (messagebody. getnodevalue ())
Def subscriberno =
Messagebody. getelementsbytagname_r ("subscriberno ");
Log.info (subscriberno)

// Obtain the XML of the Node object
// Log.info (holder. XML)

(3) If you need to obtain other information through xmlholder, refer to the following:

Groovyutils and xmlholder refer:

Policyutils currently provided des
Following (few) methods:

·

Projectpath
: A property holding the path to the containing
Project, useful for accessing data files in same folder

·

Setpropertyvalue (string teststepname, string propertyname, string
Value)
: Sets the specified property value

·

Expand (string)
-Expands the specifiedProperty
ExpansionString

·

Getxmlholder (string xmlpropertyorstring)
: Creates
Xmlholder
Object (see below) for easily accessing/modifying
Contents of an XML document using XPath expressions. The argument
Must either be a teststep property in
Teststepname # propertyname
Format or a valid XML string

Xmlholder object has the following
Methods:

·

Getnodevalue (string XPath)
: Returns the value of the first node pointed
By the specified XPath expression_r (can be replaced by holder [XPath]
Expression, see below)

·

Getnodevalues (string XPath)
: Returns a string array containing the values
All nodes pointed to by the specified XPath expression.

·

Getdomnode (string XPath)
: Returns the DOM node of the first node pointed
To by the specified XPath expression.

·

Getdomnodes (string XPath)
: Returns a DOM node array containing all nodes
Pointed to by the specified XPath expression.

·

Setnodevalue (string XPath, string value)
: Sets the content of the first node pointed
By the specified XPath expression to the specified value (can be
Replaced by holder [XPath] = value expression, see below)

·

Declarenamespace (string prefix, string namespaceuri)
: Declares a namespace that will be used in
Following get/set operation, can also be set
Holder. namespaces [prefix] = namespaceuri (see example below)

·

Getnamespaces ()
-Returns a map of prefixes to namespace URI: S
That will be used in XPath expressions

·

Removedomnodes (XPath)
-Removes all DOM nodes matching the specified
XPATH expression

·

XML
: Property containing the updated XML string

·

Xmlobject
: Property containing the parsed xmlbeans
Xmlobject for the XML string

·

Prettyxml
: Property containing the pretty-printed updated
XML string

·

Updateproperty ()
: If the xmlholder was created from a teststep
Property, that property will be updated with the currently held XML
(See example below)

·

Updateproperty (Boolean prettyprint)
: Same as previous, with option to pretty print
The updated XML. defaults to false when not specified.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.