【问题标题】:How to Send a SOAP Request in Robot Framework Tool?如何在机器人框架工具中发送 SOAP 请求?
【发布时间】:2020-08-07 01:48:28
【问题描述】:

我正在尝试在机器人工具中自动执行肥皂请求,我尝试了各种组合但徒劳无功。以下是我试图自动化的请求。我已将其保存在一个 XML 文件中,以便在测试用例中调用。 有人可以帮助我如何阅读肥皂请求并将内容发送到端点吗?

SOAP 请求:

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:ns="http://www.example.com/XMLHeader/10"
    xmlns:req="http://www.example.com/cream1/cream11I/deleteemailAddress/xyz/Req">
    <soapenv:Header>
        <ns:vendortool>
            <ns:HeaderVersion>11</ns:HeaderVersion>
            <ns:MessageId>1234556667</ns:MessageId>
            <ns:ServiceRequestorDomain>ABCCCC</ns:ServiceRequestorDomain>
            <ns:ServiceRequestorId>health</ns:ServiceRequestorId>
            <ns:ServiceProviderDomain>zxcvvbb</ns:ServiceProviderDomain>
            <ns:ServiceId>deleteemail</ns:ServiceId>
            <ns:ServiceVersion>000</ns:ServiceVersion>
            <ns:FaultIndication>True</ns:FaultIndication>
            <ns:MessageTimestamp>2020-03-27T11:12:49.418</ns:MessageTimestamp>
        </ns:vendortool>
    </soapenv:Header>
    <soapenv:Body>
        <req:deleteemailAddress_Req>
            <req:EmailAddress>zsdfghklaa9@gmail.com</req:EmailAddress>
        </req:deleteemailAddress_Req>
    </soapenv:Body>
</soapenv:Envelope>

测试用例(我试过)

   create session  deleteemail    ${base_url}     disable_warnings=1

  #Create Request Headers
   &{request_header}=  create dictionary  Content-Type=text/xml; charset=utf-8  User-Agent=Apache- 
   HttpClient/4.1.1

   ${Test_Response}=  post request      deleteemail    ${channel_url}    ${CURDIR}/deleteemail.xml   
   headers=${request_header}

【问题讨论】:

    标签: soap automation automated-tests robotframework


    【解决方案1】:

    * 设置 *

    Library  RequestsLibrary
    Library  Collections
    Library  SeleniumLibrary
    Library  String
    Library  SoapLibrary
    Library  OperatingSystem
    Library  XML
    

    * 变量 *

    ${base_url}=  https://example.com
    ${channel_url}=  /cream11/cream11/deleteemailaddress
    

    * 测试用例 *

    TC_000000_DELETE_EMAIL_ADDRESS
    
        create session  deleteemail    ${base_url}     disable_warnings=1
    
        #Create a dynamic messageId
        ${rand_MessageID}=  generate random string  5  [NUMBERS]
    
        #Set a request variable
        ${SOAP_XML}=   set variable  <?xml version="1.0" encoding="UTF-8"?> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.example.com/XMLHeader/10" xmlns:req=" http://www.example.com/cream1/cream11I/deleteemailAddress/xyz/Req"> <soapenv:Header> <ns:vendortool> <ns:HeaderVersion>11</ns:HeaderVersion> <ns:MessageId>${rand_MessageID}</ns:MessageId> <ns:ServiceRequestorDomain>ABCCCC</ns:ServiceRequestorDomain> <ns:ServiceRequestorId>health</ns:ServiceRequestorId> <ns:ServiceProviderDomain>zxcvvbb</ns:ServiceProviderDomain> <ns:ServiceId>deleteemail</ns:ServiceId> <ns:ServiceVersion>000</ns:ServiceVersion> <ns:FaultIndication>True</ns:FaultIndication>  <ns:MessageTimestamp>2020-03-27T11:12:49.418</ns:MessageTimestamp> </ns:vendortool> </soapenv:Header> <soapenv:Body> <req:deleteemailAddress_Req> <req:EmailAddress>zsdfghklaa9@gmail.com</req:EmailAddress> </req:deleteemailAddress_Req> </soapenv:Body> </soapenv:Envelope>
    
        #Create Request Headers
        ${request_header}=    create dictionary    Content-Type=text/xml; charset=utf-8   User-Agent=Apache-HttpClient/4.1.1
    
        #Send the XML request body
        ${SAVE_Response}=    Post Request    deleteemail    ${channel_url}    headers=${request_header}    data=${SOAP_XML}
    
        #Log Response and Status Code Details
        log to console    ${SAVE_Response.status_code}
        log    ${SAVE_Response.headers}
        log    ${SAVE_Response.content}
        log    ${SOAP_XML}
    

    【讨论】:

    • 另外,将完整的soap请求内联在一行中,同时将其保存在变量中,如上例所示,它将像魅力一样工作。
    猜你喜欢
    • 2022-08-12
    • 1970-01-01
    • 1970-01-01
    • 2020-12-04
    • 2019-07-21
    • 2014-10-31
    • 1970-01-01
    • 1970-01-01
    • 2013-07-01
    相关资源
    最近更新 更多