序文
アサーション後リターンの実行を要求します、そしてパスの主張によると、\決勝に反映状況失敗したテスト結果を。
まず、アサーションステップ
ここで情報確認応答を含むセット、上:「Baiduのニュース - 世界最大の中国のニュースプラットフォーム、」言葉、
応答httpCode 200を設定し、同時に、正常な応答をアサートします。
2. [テスト]以下のURL、ここでアサーションを設定します。
ポイントはここに来たあなたは、JavaScriptの機能に精通している場合は、空になった後、右側に慣れていない、郵便配達がテストフラグメントを提供されている場合は、手動で、入力することができます。
より多くのスニペットを学ぶために多くのテストをご覧くださいクリックしてください。
発見レスポンスボディ:文字列のレスポンスボディは、文字列が含まれ含まれています。クリックします。
コードフラグメントのテストピースは、ボックスに表示され、他の人を気にしないでください、で置き換えるだけでstring_you_want_to_search文字列:Baiduのニュース - 世界最大の中国のニュースプラットフォーム
それはあなたがセットアップする方法を学ぶことができ、英語の意味から、非常に明確に書かれたコードの断片であること、およびすることができます。
スニペットを探します。ステータスコード:コードは200をクリックします。
HttpCodeアサーションは、コードフラグメント200を生成します。
Ctrlキー+ Sは、要求の設定について保存します。
その後、応答を参照するには、要求を送信するために送信]をクリックします。
レスポンスチェックテストの結果。すべての成功の設定を確認してください。
第二に、アサーションが詳細内容
1.環境変数を--Setting環境変数を設定します。
postman.setEnvironmentVariable( "キー"、 "値");
2.设置全局变量--Set a global variable
postman.setGlobalVariable("key", "value");
3.检查响应中包含string--Check if response body contains a string
tests["Body matches string"] = responseBody.has("string_you_want_to_search");
4.转化XML格式的响应成JSON对象---Convert XML body to a JSON object
var jsonObject = xml2Json(responseBody);
5.检查响应body中等于指定string--Check if response body is equal to a string
tests["Body is correct"] = responseBody === "response_body_string";
6.检查JSON某字段值--Check for a JSON value
var data = JSON.parse(responseBody);
tests["Your test name"] = data.value === 100;
7.检查Content-Type是否包含在header返回(大小写不敏感)--Content-Type is present (Case-insensitive checking)
tests["Content-Type is present"] = postman.getResponseHeader("Content-Type"); //Note: the getResponseHeader() method returns the header value, if it exists.
8.检查Content-Type是否包含在header返回(大小写敏感)--Content-Type is present (Case-sensitive)
tests["Content-Type is present"] = responseHeaders.hasOwnProperty("Content-Type");
9.检查请求耗时时间小于200ms--Response time is less than 200ms
tests["Response time is less than 200ms"] = responseTime < 200;
10.检查Status code为200--Status code is 200
tests["Status code is 200"] = responseCode.code === 200;
11.检查Code name是否指定string--Code name contains a string
tests["Status code name has string"] = responseCode.name.has("Created");
12.检查成功post的请求status code--Succesful POST request status code
tests["Successful POST request"] = responseCode.code === 201 || responseCode.code === 202;
这里就设置,检查响应信息里面包含:“百度新闻——全球最大的中文新闻平台”这几个字、
同时设置响应httpCode为200,断言响应成功。
2、点击Url下方的Tests,这里设置断言。
点进来后这里是空的,你如果熟悉JavaScript的函数,可以直接手动输入,如果不熟悉,postman在右侧已经提供了tests片段。
点击Learn more tests可以了解更多代码片段。
找到Response body:Contains string响应body包含字符串。点击。
在Tests框内出现一段代码片段,其他不用管,只需要将string_you_want_to_search字符串,替换为:百度新闻——全球最大的中文新闻平台
即可,而且代码片段写的很明白,从英文意思就可以了解该如何设置。
找到代码片段。Status code:code is 200.点击。
生成断言httpCode为200的代码片段。
Ctrl+s保存一下请求的设置。
然后点击Send发送请求,查看响应信息。
响应中查看Tests Results。设置的检查全部成功。
二、断言内容详解
1.设置环境变量--Setting an environment variable
postman.setEnvironmentVariable("key", "value");
2.设置全局变量--Set a global variable
postman.setGlobalVariable("key", "value");
3.检查响应中包含string--Check if response body contains a string
tests["Body matches string"] = responseBody.has("string_you_want_to_search");
4.转化XML格式的响应成JSON对象---Convert XML body to a JSON object
var jsonObject = xml2Json(responseBody);
5.检查响应body中等于指定string--Check if response body is equal to a string
tests["Body is correct"] = responseBody === "response_body_string";
6.检查JSON某字段值--Check for a JSON value
var data = JSON.parse(responseBody);
tests["Your test name"] = data.value === 100;
7.检查Content-Type是否包含在header返回(大小写不敏感)--Content-Type is present (Case-insensitive checking)
tests["Content-Type is present"] = postman.getResponseHeader("Content-Type"); //Note: the getResponseHeader() method returns the header value, if it exists.
8.检查Content-Type是否包含在header返回(大小写敏感)--Content-Type is present (Case-sensitive)
tests["Content-Type is present"] = responseHeaders.hasOwnProperty("Content-Type");
9.检查请求耗时时间小于200ms--Response time is less than 200ms
tests["Response time is less than 200ms"] = responseTime < 200;
10.检查Status code为200--Status code is 200
tests["Status code is 200"] = responseCode.code === 200;
11.检查Code name是否指定string--Code name contains a string
tests["Status code name has string"] = responseCode.name.has("Created");
12.检查成功post的请求status code--Succesful POST request status code
試験[ "成功POSTリクエスト"] = responseCode.codeの=== 201 || responseCode.codeの=== 202;