【问题标题】:Include requests saved in file in soapUI project在soapUI项目中包含保存在文件中的请求
【发布时间】:2015-01-02 06:54:42
【问题描述】:

我有一个包含我的肥皂请求的目录,我想重用它们来构建测试套件。 我尝试使用 ENTITY 定义但无法使其工作,而使用 xi:include 来包含我想要包含的代码似乎soapUI 无法识别它。

我的实际项目结构如下:

<con:soapui-project>

    <con:interface >
        <con:endpoints>
            <con:endpoint>http://localhost/GestionePreventiviRemoteImpl/GestionePreventiviService_v1</con:endpoint>
        </con:endpoints>

        <con:operation isOneWay="false" action="" name="aggiornaPreventivo" bindingOperationName="aggiornaPreventivo" >
            <con:settings/>
        </con:operation>

        <con:operation isOneWay="false" action="" name="creaPreventivo" bindingOperationName="creaPreventivo" >
            <con:settings/>
        </con:operation>

        <con:operation isOneWay="false" action="" name="recuperaPreventivo" bindingOperationName="recuperaPreventivo">
            <con:settings/>
        </con:operation>
    </con:interface>

    <con:testSuite name="GestioneServicePortBinding TestSuite">
        <con:testCase name="aggiornaPreventivo TestCase">
            <con:testStep name="aggiornaPreventivo">
                <con:config>
                    <con:interface>GestioneServicePortBinding</con:interface>
                    <con:operation>aggiornaPreventivo</con:operation>
                    <con:request name="aggiornaPreventivo">
                        <con:endpoint>http://localhost/GestionePreventiviRemoteImpl/GestionePreventiviService_v1</con:endpoint>

                        <con:request>
                            <![CDATA[
                            <?xml version="1.0" encoding="UTF-8"?>
                            <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://simulatore.Prodotto.be.service.bmed.it/v1">
                               <soapenv:Header/>
                               <soapenv:Body>
                                  <v1:aggiornaPreventivo>
                                     <input>
                                        <aggiornaPreventivoDTO>
                                           <codPrev>1001</codPrev>
                                           <codCliente>205</codCliente>
                                           .....
                                        </aggiornaPreventivoDTO>
                                     </input>
                                  </v1:aggiornaPreventivo>
                               </soapenv:Body>
                            </soapenv:Envelope>
                            ]]>
                        </con:request>
                    </con:request>
                </con:config>
            </con:testStep>
        </con:testCase>
    </con:testSuite>

</con:soapui-project>

我需要将请求包含在测试用例中,以便在测试套件之外处理输入参数。所以像:

<con:testStep name="aggiornaPreventivo">
    <con:config>
        <con:interface>GestioneServicePortBinding</con:interface>
        <con:operation>aggiornaPreventivo</con:operation>
        <con:request name="aggiornaPreventivo">
            <con:endpoint>http://localhost/GestionePreventiviRemoteImpl/GestionePreventiviService_v1</con:endpoint>
            <con:request>
                <xi:include href="aggiornaPreventivoRequest.xml" parse="xml" xpointer="title"/>
            </con:request>
        </con:request>
    </con:config>
</con:testStep>

aggiornaPreventivoRequest.xml 的内容如下:

<v1:aggiornaPreventivo>
    <input>
        <aggiornaPreventivoDTO>
           <codPrev>1001</codPrev>
           <codCliente>205</codCliente>
           .....
        </aggiornaPreventivoDTO>
    </input>
</v1:aggiornaPreventivo>

感谢您的帮助!

【问题讨论】:

    标签: soapui test-suite


    【解决方案1】:

    我不知道你是否可以在 SOAPUI 中使用 http://www.w3.org/2001/XInclude 中的 &lt;include&gt;,但是如果你想在请求本身之外控制请求的节点值,你可以使用属性。

    您可以在projecttestSuitetestCasetestStep 级别等上添加属性,要直接在您的请求中使用它,您必须使用以下符号取决于您定义的级别你的属性。来自SOAPUI documentation

    ${#Project#yourProperty} - 引用项目属性(跨特定 SoapUI 项目的引用属性)

    ${#TestSuite#yourProperty} - 引用包含 TestSuite 中的 TestSuite 属性

    ${#TestCase#yourProperty} - 在包含的 TestCase 中引用一个 TestCase 属性

    ${TestStep name#yourProperty} - 引用一个 TestStep 属性

    例如,如果您在 testSuite 上添加属性:

    <v1:aggiornaPreventivo>
        <input>
            <aggiornaPreventivoDTO>
               <codPrev>${#TestSuite#codPrevValue}</codPrev>
               <codCliente>${#TestSuite#codClienteValue}</codCliente>
               .....
            </aggiornaPreventivoDTO>
        </input>
    </v1:aggiornaPreventivo>
    

    如果您不知道如何向项目添加属性,请查看this

    如果您真的有兴趣从本地文件发送请求,还有另一种可能性,您也可以使用 groovy testStep 和以下代码从特定文件位置发送请求:

    import java.io.IOException;
    import java.io.FileInputStream;
    import org.apache.http.entity.FileEntity
    import org.apache.http.client.HttpClient;
    import org.apache.http.client.ResponseHandler;
    import org.apache.http.client.methods.HttpPost;
    import org.apache.http.impl.client.BasicResponseHandler;
    import org.apache.http.impl.client.DefaultHttpClient;
    import org.apache.http.params.DefaultedHttpParams;
    import org.apache.http.params.HttpParams;
    
    def httpclient = new DefaultHttpClient();
    // the directory with your xml requests
    def directory = new File("/tmp/myRequests/")
    // for each file in the directory
    directory.eachFile{ file -> 
        // create the request
        HttpPost post = new HttpPost("http://your_endpoint")
        def reqEntity = new FileEntity(file,"application/xml");
         post.setEntity(reqEntity)
        // make the post and get the response
        def responseHandler = new BasicResponseHandler()
        def responseBody = httpclient.execute(post, responseHandler)
        log.info responseBody
    };
    

    希望这会有所帮助,

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-03
      • 2019-02-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-12
      • 2017-01-20
      • 1970-01-01
      相关资源
      最近更新 更多