问题
i am struggling to create this part of the soap message using robot framework with SUDS library.
<ns1:Request>
<ns0:ID objectType="SomeType">Value</ns0:ID>
</ns1:Request>
If i do like this, then i get all i need but not the objectType.
${object}= Create Wsdl Object ns19:RequestTypeSingle
Set Wsdl Object Attribute ${object} ID 1234
Output
<ns1:Request>
<ns0:ID>1234</ns0:ID>
</ns1:Request>
If i check what my ns19:RequestTypeSingle wants i get this:
${object} = (RequestTypeSingle){
ID =
(ID){
_objectType = ""
}
}
"RequestTypeSingle" definition
<xs:complexType name="RequestTypeSingle">
<xs:sequence>
<xs:element minOccurs="1" maxOccurs="1" name="ID" nillable="true">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="objectType" type="xs:string"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
So how can i declare this "(ID){_objectType = ""} with SUDS or some other?
Thanks to ombre42 this can be done like this (first question answered):
${req}= Create WSDL Object ns19:RequestTypeSingle # may need namespace prefix here
Set Wsdl Object Attribute ${req.ID} _objectType SomeType
(Continuing question). How ever this will not set the value as i mentioned in my request example. It would seem that this kind of syntax would work but it did not. Any great ideas on this one?
This will give an error: "ValueError: Object must be a WSDL object (suds.sudsobject.Object)."
${req}= Create WSDL Object ns19:RequestTypeSingle # may need namespace prefix here
Set Wsdl Object Attribute ${req} ID 1234
Set Wsdl Object Attribute ${req.ID} _objectType SomeType
And this will overwrite the first _objectType definition.
${req}= Create WSDL Object ns19:RequestTypeSingle # may need namespace prefix here
Set Wsdl Object Attribute ${req.ID} _objectType SomeType
Set Wsdl Object Attribute ${req} ID 1234
What i mean by overwrite is that i get this:
<ns1:Request>
<ns0:ID>1234</ns0:ID>
</ns1:Request>
回答1:
When assigning a value to property that is expressed as an XML attribute instead of an element, prefix the name with an underscore (why _objectType instead of objectType).
${req}= Create WSDL Object RequestTypeSingle # may need namespace prefix here
Set Wsdl Object Attribute ${req.ID} _objectType SomeType
来源:https://stackoverflow.com/questions/37567439/creating-soap-messages-with-objecttypes-using-suds-library-in-robot-framework