简体   繁体   中英

Sending XML file in Soap call with elements in variables - Robot Framework

I'm automating tests using Robot Framework (Libraries XML and Soap)) and i have a big doubt...

I have the following XML file (.xml):

<?xml version="1.0" encoding="UTF-8"?>
<datas>
    <data id="person">
        <phone>83910388</price>
        <name>Test</name>
    </data id>
</datas>

I would like to leave a dynamic data (variable) in my "phone" and "name" attribute. This variable would be filled in my test case, through the Faker Library.

Can I do this? As?

I've tried several ways, like the example below, but all without success... =/

*** Variables ***
${PHONE}    928466190

*** Test Cases ***

Test XML
    ${file}    Parse Xml    ${path_to_file}
    
    ${element}    Get Element Attribute    ${file}    //datas

    Set Element Attribute    ${element}    phone    ${PHONE}

Can I do this? As?

I've tried it in different ways. I used the keyword "Set Element Attribute", for example. This keyword adds dynamic data but is not saved inside the file and sent.

Thanks very much!!!!

Try xml linq. You have typos in your xml that I corrected. Also when reading from a File use Load instead of Parse. You original code was not correct and used Parse instead of load.

using assembly System.Xml.Linq

$xml = @'
<?xml version="1.0" encoding="UTF-8"?>
<datas>
    <data id="person">
        <phone>83910388</phone>
        <name>Test</name>
    </data>
</datas>
'@
 $doc = [System.Xml.Linq.XDocument]::Parse([string]$xml)
$phone = $doc.Descendants().Where( {$_.Name.LocalName -eq "phone"})
$phone = [System.Linq.Enumerable]::Last($phone)
$phone.Value = "1234567"
$data
$doc.Save(Filename)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM