﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-Noah-文章分类-Test Tools(Postman.etc.)</title><link>http://www.blogjava.net/Noah/category/55350.html</link><description>&lt;span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri" lang="ZH-CN"&gt;不是经典我不发&lt;/span&gt;</description><language>zh-cn</language><lastBuildDate>Wed, 26 Feb 2020 11:12:39 GMT</lastBuildDate><pubDate>Wed, 26 Feb 2020 11:12:39 GMT</pubDate><ttl>60</ttl><item><title>Postman 测试常用脚本</title><link>http://www.blogjava.net/Noah/articles/435164.html</link><dc:creator>眼镜蛇</dc:creator><author>眼镜蛇</author><pubDate>Tue, 25 Feb 2020 03:50:00 GMT</pubDate><guid>http://www.blogjava.net/Noah/articles/435164.html</guid><wfw:comment>http://www.blogjava.net/Noah/comments/435164.html</wfw:comment><comments>http://www.blogjava.net/Noah/articles/435164.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Noah/comments/commentRss/435164.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Noah/services/trackbacks/435164.html</trackback:ping><description><![CDATA[<div>//得到URL，问号后面的参数，<br />
var index = pm.request.url.query.all()[0].value;<br /><br /><div>//JSON.stringify(json);&nbsp;保存json到变量的方式</div><div></div><div>var valuesArray = JSON.parse(pm.variables.get('channelValues'));//从变量中读取字符串再转化成Json格式的方式</div><div></div><div>if(index &lt; 0){</div><div>&nbsp; &nbsp; index = 0;</div><div>}</div><div>else if(index &gt;= valuesArray.length){</div><div>&nbsp; &nbsp; index = valuesArray.length-1;</div><div>}</div><div>var valuesObj = valuesArray[index];</div><div></div><div>var num=0;</div><div>var paramsArray = [];<br />//对动态参数进行取值，并整理成key，value值对。</div><div>for(var key in valuesObj) {</div><div>&nbsp; &nbsp; if (valuesObj.hasOwnProperty(key)) {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; console.log(key + " = " + valuesObj[key]);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; paramsArray.push({"key":key, "value": encodeURIComponent(valuesObj[key])});</div><div>&nbsp; &nbsp; &nbsp; &nbsp; num++;</div><div>&nbsp; &nbsp; }</div><div>}<br />//移除不需要的参数</div><div>pm.request.url.query.remove("index");<br />//对整理好的动态参数进行追加</div><div>pm.request.url.addQueryParams(paramsArray);</div><div></div><div>//可以通过这种方式，跳过本次不需要测试的集体脚本</div><div>pm.variables.set("skipTest","true");<br />//统一执行的脚本，可以写在Collection里面</div><div><div>var skipTest = pm.variables.get("skipTest");</div><div>(skipTest ? pm.test.skip : pm.test)("Status test 200", function () {</div><div>&nbsp; &nbsp; pm.response.to.have.status(200);</div><div>});</div></div><div></div><div></div>
<br />
通过脚本发送请求，body格式是Raw时<br />
<div style="display: inline-block;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, monospace; font-size: 11.9px; margin-top: 0px; overflow-wrap: normal; padding: 16px; overflow: auto; line-height: 1.45; background-color: #f6f8fa; border-radius: 3px; color: #24292e; margin-bottom: 0px !important;"><code style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, monospace; padding: 0px; margin: 0px; background: initial; border-radius: 3px; word-break: normal; border: 0px; display: inline; overflow: visible; line-height: inherit; overflow-wrap: normal;">pm.sendRequest({
url: pm.environment.get("api-url") + 'v1/authenticate',
method: 'POST',
header: {
'content-type': 'application/json',
'x-site-code': pm.environment.get("x-site-code")
},
body: {
mode: 'raw',
raw: JSON.stringify({ email: pm.environment.get("email"), password: pm.environment.get("password") })
}
}, function (err, res) {
pm.environment.set("authorization", "Bearer " + res.json().token);
});<br />
</code></pre>
</div>
</div>
<br />
<br />
通过脚本发送请求，body格式是<span style="font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, monospace; color: #24292e; font-size: 11.9px;">x-www-form-urlencoded</span>时<br />
<div style="display: inline-block;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, monospace; font-size: 11.9px; margin-top: 0px; overflow-wrap: normal; padding: 16px; overflow: auto; line-height: 1.45; background-color: #f6f8fa; border-radius: 3px; color: #24292e; margin-bottom: 0px !important;"><code style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, monospace; padding: 0px; margin: 0px; background: initial; border-radius: 3px; word-break: normal; border: 0px; display: inline; overflow: visible; line-height: inherit; overflow-wrap: normal;">pm.sendRequest({
url: pm.environment.get("OAUTH_URL")+"/uaa/oauth/token",
method: 'POST',
header: {
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Basic Abcdefghijk=='
},
body: {
mode: 'urlencoded',
urlencoded: [
{key: "grant_type", value: "password", disabled: false},
{key: "username", value: pm.environment.get("OAUTH_USERNAME"), disabled: false},
{key: "password", value: pm.environment.get("OAUTH_PASSWORD"), disabled: false}
]
}
}, function (err, res) {
pm.globals.set("token", res.json().access_token);
});</code></pre>
</div>
<br /><br /><br /><img src ="http://www.blogjava.net/Noah/aggbug/435164.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Noah/" target="_blank">眼镜蛇</a> 2020-02-25 11:50 <a href="http://www.blogjava.net/Noah/articles/435164.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Different types of Asserts in Postman(自动化测试，断言)</title><link>http://www.blogjava.net/Noah/articles/435143.html</link><dc:creator>眼镜蛇</dc:creator><author>眼镜蛇</author><pubDate>Fri, 21 Feb 2020 07:10:00 GMT</pubDate><guid>http://www.blogjava.net/Noah/articles/435143.html</guid><wfw:comment>http://www.blogjava.net/Noah/comments/435143.html</wfw:comment><comments>http://www.blogjava.net/Noah/articles/435143.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Noah/comments/commentRss/435143.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Noah/services/trackbacks/435143.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: In the previous tutorial of&nbsp;Chai Assertion Library&nbsp; we covered Postman Assertions using&nbsp;expect&nbsp;keyword.&nbsp;Also there are many other assertions in Postman which works around&nbsp...&nbsp;&nbsp;<a href='http://www.blogjava.net/Noah/articles/435143.html'>阅读全文</a><img src ="http://www.blogjava.net/Noah/aggbug/435143.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Noah/" target="_blank">眼镜蛇</a> 2020-02-21 15:10 <a href="http://www.blogjava.net/Noah/articles/435143.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>