Postman_JavaScript
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">使用语法:JavaScript</div><div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">结构:</div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">测试工具主要包括三部分</div>
<div><ol style="margin: 0">
<li style="text-align: left; line-height: 1.75; font-size: 14px; list-style-position: inside; white-space: pre-wrap; list-style-type: decimal; font-family: "Microsoft YaHei", STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">在发起请求之前运行的Pre-request,预处理数据,作用:在发送请求前编辑请求数据,比如用户名或时间戳</li>
<li style="text-align: left; line-height: 1.75; font-size: 14px; list-style-position: inside; white-space: pre-wrap; list-style-type: decimal; font-family: "Microsoft YaHei", STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">对响应后的数据运行的Test,检查数据并做断言,作用:对响应的数据检查和断言,例如检查状态码、检查响应串、验证JSON、检查header、限制应答时间</li>
<li style="text-align: left; line-height: 1.75; font-size: 14px; list-style-position: inside; white-space: pre-wrap; list-style-type: decimal; font-family: "Microsoft YaHei", STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">批量运行所有请求的Collection Runner,批量执行接口测试</li>
</ol></div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px"> </div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px"><span style="font-weight: bold">基本流程:</span></div>
<div><ol style="margin: 0">
<li style="text-align: left; line-height: 1.75; font-size: 14px; list-style-position: inside; white-space: pre-wrap; list-style-type: decimal; font-family: "Microsoft YaHei", STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">确认接口信息</li>
<li style="text-align: left; line-height: 1.75; font-size: 14px; list-style-position: inside; white-space: pre-wrap; list-style-type: decimal; font-family: "Microsoft YaHei", STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">对单个接口进行调试</li>
<ol style="margin: 0">
<li style="text-align: left; line-height: 1.75; font-size: 14px; list-style-position: inside; white-space: pre-wrap; list-style-type: lower-alpha; font-family: "Microsoft YaHei", STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">输入URL地址</li>
<li style="text-align: left; line-height: 1.75; font-size: 14px; list-style-position: inside; white-space: pre-wrap; list-style-type: lower-alpha; font-family: "Microsoft YaHei", STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">输入参数</li>
<li style="text-align: left; line-height: 1.75; font-size: 14px; list-style-position: inside; white-space: pre-wrap; list-style-type: lower-alpha; font-family: "Microsoft YaHei", STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">获取响应数据,并对数据进行检查和断言处理</li>
<li style="text-align: left; line-height: 1.75; font-size: 14px; list-style-position: inside; white-space: pre-wrap; list-style-type: lower-alpha; font-family: "Microsoft YaHei", STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">保存响应数据到环境变量:比如校验信息csrf令牌,cooking值,token值</li>
<li style="text-align: left; line-height: 1.75; font-size: 14px; list-style-position: inside; white-space: pre-wrap; list-style-type: lower-alpha; font-family: "Microsoft YaHei", STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">预编译模块处理Pre-request:比如时间戳</li>
</ol>
<li style="text-align: left; line-height: 1.75; font-size: 14px; list-style-position: inside; white-space: pre-wrap; list-style-type: decimal; font-family: "Microsoft YaHei", STXihei; color: rgba(0, 0, 0, 1); font-weight: normal; font-style: normal; text-decoration: none">最后对接口进行批量测试:Collection Runner</li>
</ol></div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px"> </div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px"> </div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">如果要使用自动化测试,需要购买9.99美金的Jetpacks,暂时不想购买的话可以试一下<span style="color: rgba(0, 56, 132, 1); text-decoration: underline">Team版Postman</span>。现在是可以免费试用的,不但拥有Jetpacks的功能,还能与其他账户同步Collection。</div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px"> </div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">全局变量:仅有一组</div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">环境变量:可有多组,就有点像局部变量,用户自定义,当与全局变量重名时,可覆盖全局变量,</div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px"><span style="font-size: 18px; font-weight: bold">postman接口实例</span></div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">1.get类型 </div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px"> 可以直接在浏览器中进行测试,?后写参数,&拼参数</div>
<div style="text-align: left; float: none"><img src="https://img2018.cnblogs.com/blog/868136/201906/868136-20190611195820120-1306755761.png">
<p> </p>
</div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">2.post类型</div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">请求选择post,添加参数即可</div>
<div style="text-align: left; float: none"><img src="https://img2018.cnblogs.com/blog/868136/201906/868136-20190611195838479-2112014849.png">
<p> </p>
</div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">3.入参是jason类型</div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">选择Body-raw-JSON(application/json),直接将jason串复制进来</div>
<div style="text-align: left; float: none"><img src="https://img2018.cnblogs.com/blog/868136/201906/868136-20190611195856019-649462144.png">
<p> </p>
</div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">4.请求头加cookie</div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">在Headers中添加cookie的key和value</div>
<div style="text-align: left; float: none"><img src="https://img2018.cnblogs.com/blog/868136/201906/868136-20190611195913689-1071113313.png">
<p> </p>
</div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">5.请求头加refer</div>
<div style="text-align: left; float: none"><img src="https://img2018.cnblogs.com/blog/868136/201906/868136-20190611195933228-329118195.png">
<p> </p>
</div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">6.上传文件</div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">body-form-data-File-选择文件即可</div>
<div style="text-align: left; float: none"><img src="https://img2018.cnblogs.com/blog/868136/201906/868136-20190611195949327-144313972.png">
<p> </p>
</div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px"> </div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px"><span style="font-size: 18px; font-weight: bold"> jmeter基础</span></div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px"><span style="font-size: 16px; font-weight: bold">1.添加http请求</span></div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px"> sep1测试计划-添加-Threads-线程组</div>
<div style="text-align: left; float: none"><img src="https://img2018.cnblogs.com/blog/868136/201906/868136-20190611200007762-958762372.png">
<p> </p>
</div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">sep2 线程组-添加-Sample-http请求</div>
<div style="text-align: left; float: none"><img src="https://img2018.cnblogs.com/blog/868136/201906/868136-20190611200030379-896638712.png">
<p> </p>
</div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">sep3 添加域名、端口号、协议、请求方法、路径、编码格式、参数</div>
<div style="text-align: left; float: none"><img src="https://img2018.cnblogs.com/blog/868136/201906/868136-20190611200105429-2049758051.png">
<p> </p>
</div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">参数为文件 Files Upload --添加--文件名称:文件的绝对路径,或直接把文件放在jmeter的bin路径下,直接添加文件名,参数名称:参数名</div>
<div style="text-align: left; float: none"><img src="https://img2018.cnblogs.com/blog/868136/201906/868136-20190611200122324-284067159.png">
<p> </p>
</div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px"> </div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">sep4添加断言(相当于LR中的检查点) 请求-添加-断言-响应断言---断言内容请求response中的值</div>
<div style="text-align: left; float: none"><img src="https://img2018.cnblogs.com/blog/868136/201906/868136-20190611200158008-274023921.png">
<p> </p>
</div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">sep5 添加监听查看请求结果 线程组、请求-添加-监听器-察看结果树</div>
<div style="text-align: left; float: none"><img src="https://img2018.cnblogs.com/blog/868136/201906/868136-20190611200218993-1084369136.png">
<p> </p>
</div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px"> </div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">sep6 根据需要添加配置原件(例如cookie或http信息头)</div>
<div style="text-align: left; float: none"> <img src="https://img2018.cnblogs.com/blog/868136/201906/868136-20190611211030665-1305592232.png">
<p> </p>
</div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px"><span style="font-size: 16px; font-weight: bold">2.参数化、关联</span></div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px"><span style="font-size: 18px"> 参数化-----服务器或程序校验输入值的唯一性需要参数化,例如新加用户,手机后不能重复添加</span></div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">方法一:添加-配置元件-CSV Data Set Config</div>
<div style="text-align: left; float: none"><img src="https://img2018.cnblogs.com/blog/868136/201906/868136-20190611214221451-1052817380.png">
<p> </p>
</div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px"> 参数化文件首行不用写参数名,引用参数时 -----${参数名}</div>
<div style="text-align: left; float: none"><img src="https://img2018.cnblogs.com/blog/868136/201906/868136-20190611214250839-2060951641.png">
<p> </p>
</div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">方法二:使用函数助手</div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">选项---函数助手 常用的time取到秒级可以用做唯一性的参数的取值,random生成一个取值范围,任意取其中的一个值</div>
<div style="text-align: left; float: none"><img src="https://img2018.cnblogs.com/blog/868136/201906/868136-20190611214308744-488534639.png">
<p> </p>
</div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">方法三:配置原件-----用户定义的变量,一 一写出来</div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px"> </div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px"><span style="font-size: 18px">关联----服务器返回动态码,为了通过服务器的验证,使用关联,例如,添加金币,需要服务器返回动态的记录用户登录状态的sign串</span></div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">方法一:正则表达式</div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">添加-后置处理器-正则表达式提取器</div>
<div style="text-align: left; float: none"><img src="https://img2018.cnblogs.com/blog/868136/201906/868136-20190611214330086-697497263.png">
<p> </p>
</div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px"> 正则表达式,需要看从哪个请求返回,就去那个请求的返回集中找,找到后复制该动态值以及左右边界,动态值替换为正则表达式即可</div>
<div style="text-align: left; float: none"><img src="https://img2018.cnblogs.com/blog/868136/201906/868136-20190611214350441-475818982.png">
<p> </p>
</div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">方法二 jason path(需要安装插件)$.login_info.sign 代表返回jason串中,取真个jason下面的login_info节点下面的sign的值</div>
<div style="text-align: left; float: none"><img src="https://img2018.cnblogs.com/blog/868136/201906/868136-20190611214418828-1766080953.png">
<p> </p>
</div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px"><span style="font-size: 18px; font-weight: bold"> 3.jmeter操作数据库</span></div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">sep1测试计划加载java连接mysql的jar包</div>
<div style="text-align: left; float: none"><img src="https://img2018.cnblogs.com/blog/868136/201906/868136-20190611214439966-211739450.png">
<p> </p>
</div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">sep2 添加JDBC Connection Configuration 线程组-添加-配置元件-JDBC Connection Configuration</div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">Variable Name 可以任意添写</div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">database url:jdbc:mysql://ip:端口号/库名?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true <span style="font-size: 16px">注:characterEncoding=UTF-8保证新增修改数据库中文不乱码,allowMultiQueries=true 允许同一个请求同时写增删改查操作</span></div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">JDBC driver Class:com.mysql.jdbc.Driver 固定写法</div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">username:数据路用户名 Password 数据库密码</div>
<div style="text-align: left; float: none"><img src="https://img2018.cnblogs.com/blog/868136/201906/868136-20190611214509469-632370256.png">
<p> </p>
</div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">sep3 添加 jdbc request 线程组-添加-Sample-JDBC Request</div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">Variable Name 一定要和JDBC Connection Configuration中Variable Name已知,否则报错</div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">Query Type 选Callables Statement 可以同时写增删改查</div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px"><img src="https://img2018.cnblogs.com/blog/868136/201906/868136-20190611214554060-2101421529.png">
<p> </p>
</div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px"> </div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px"><span style="font-size: 18px; font-weight: bold">4.jmeter解决乱码</span></div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">在jmeter.properties 这个文件里面</div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">找到sampleresult.default.encoding=xx</div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">后面xx改成utf-8,然后取消注释</div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">解决jmeterbody里面中文显示不出来</div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">找到 JSyntaxTextArea</div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">然后把注释取消就行了,以js开头的</div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px"><span style="font-style: italic">解决请求参数中午乱码 请求页面</span></div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px"><span style="font-style: italic">content encoding 填写utf-8</span></div>
<div style="text-align: left; float: none"><img src="https://img2018.cnblogs.com/blog/868136/201906/868136-20190611214619011-860501062.png">
<p> </p>
</div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">解决数据库操作中文乱码</div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px">database url后添加<span style="font-style: italic">characterEncoding=UTF-8</span></div>
<div style="white-space: pre-wrap; text-align: left; line-height: 1.75; font-size: 14px"> </div>
</div>
<div id="MySignature" role="contentinfo">
Henry<br><br>
来源:https://www.cnblogs.com/TomBombadil/p/11006297.html
頁:
[1]