创建Web 服务测试

1、创建一个新的 Web 测试。  浏览器打开后立刻单击“停止”。

2、 在“Web 测试编辑器”中右击该 Web 测试,并选择“添加 Web 服务请求”。

3、在新请求的“Url”属性中,键入 Web 服务的名称,如 :http://localhost:4490/MathService/Service.asmx

4、 打开单独的浏览器会话,然后在“地址”工具栏中键入 .asmx 页的 URL。选择要测试和检查 SOAP 消息的方法。该方法包含 SOAPAction。例如WebAdd。

5、在“Web 测试编辑器”中,右击请求并选择“添加标题”添加新标题。在“名称”属性中键入 SOAP-Action。在“值”属性中,键入在 SOAPAction 中看到的值,例如:http://tempuri.org/WebAdd

6、 在“字符串正文”节点“内容类型”属性中键入 text/xml。

7、  返回到步骤 4 中的浏览器,从 Web 服务描述页中选择 SOAP 请求并将其复制到剪贴板中。这里为:
POST /MathService/Service.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/WebAdd"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <WebAdd xmlns="http://tempuri.org/">
      <db1>double</db1>
      <db2>double</db2>
    </WebAdd>
  </soap:Body>
</soap:Envelope>
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <WebAddResponse xmlns="http://tempuri.org/">
      <WebAddResult>double</WebAddResult>
    </WebAddResponse>
  </soap:Body>
</soap:Envelope>

8、返回到“Web 测试编辑器”,然后单击“字符串正文”属性中的省略号 (…)。将改写后内容粘贴到该属性中。

9、改写XML内容:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <WebAdd xmlns="http://tempuri.org/">
      <db1>1</db1>
      <db2>2</db2>
  <WebAddResult>db1+db2</WebAddResult>
    </WebAdd>
  </soap:Body>
</soap:Envelope>

10、 为使测试通过,必须使用有效值替换所有占位符值。在前面的示例中,将替换3个double。只有注册用户发出请求时才能完成此 Web 服务操作。
必须使用有效值具有局限性,最好能够使用数据绑定。

11、 右击 Web 服务请求并选择“添加 URL QueryString 参数”。

12、  为查询字符串参数赋予一个名称和值。在前面的示例中,名称为 op,值为WebAdd。这标识要执行的 Web 服务操作。

13、通过使用 {{DataSource.DataColumn}} 语法,可以在 SOAP 体中使用数据绑定,以使用数据绑定值替换所有占位符值。

14、Demo下载。

OscarXie.net

关注质量与体验——电子商务与自动化测试
http://www.cnblogs.com/oscarxie/

原文地址:https://www.cnblogs.com/oscarxie/p/615983.html