0

我使用 tsung 来测试一个 web 应用程序。当请求时,服务器以 xml 响应。

我想要做什么:如果发生错误,请在请求中使用 tsung 匹配标记来记录。

如果发生错误,xml 响应如下:

<?xml version="1.0" encoding="UTF-8" ?>
 <toto:root xmlns:toto="toto_url" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <toto:header>
  <toto:trace-id>Testing</toto:trace-id>
  <toto:timestamp>1420441279107</toto:timestamp>
  <toto:command>MyServiceName</toto:command>
  <toto:version>2.4</toto:version>
  <toto:operation-id/>
  <toto:calling-user>Tester</toto:calling-user>
  <toto:calling-application>Tester</toto:calling-application>
  <toto:calling-channel/>
  <toto:locale-code>en</toto:locale-code>
  <toto:country-code>EN</toto:country-code>
  <toto:error>
   <toto:applicative>
     <toto:code>002</toto:code>
     <toto:message>No record found</toto:message>
   </toto:applicative>
  </toto:error>
 </toto:header>
 <app:data xmlns:app="url_toto_service">
  <app:totoNullPayload>
    <app:result>OK</app:result>
  </app:totoNullPayload>
</app:data>

我需要为错误代码值 002 和其他错误代码值登录 match.log 特定名称。

到目前为止,我有这个工作。当我在响应中获得值 002 时,它会登录匹配日志。问题是它匹配 002 值,即使它不在标签内。因此,它有时会匹配包含该值的常规 xml 响应。002 008

我的问题是如何匹配错误值和它在标签内的事实?

tsung 请求部分是:

   <request subst="true">
            <match name="Norecord" do="log" when="match" skip_headers="http" subst="true">002</match>
    <match name="Request Error" do="log" when="match" skip_headers="http" subst="true">008</match>
   <http url="/myApp/XmlHttpInbound" method="POST" version="1.1"
     content_type="application/xml"
     contents_from_file="/tmp/query.xml">
   </http>
4

1 回答 1

0

更新:

Tsung 测试计划指定为 xml 文件,因此您应该以您期望的响应方式转义 xml 符号。要匹配标签内的 002 和 008 错误代码,您可以使用:

<request subst="true">
    <match do="log" when="match" skip_headers="http" subst="true">&lt;toto:code&gt;002&lt;/toto:code&gt;</match>
    <match do="log" when="match" skip_headers="http" subst="true">&lt;toto:code&gt;008&lt;/toto:code&gt;</match>
    <http url="/myApp/XmlHttpInbound" method="POST" version="1.1"
        content_type="application/xml"
        contents_from_file="/tmp/query.xml">
    </http>
</request>
于 2015-05-13T21:56:57.417 回答