API 自动化测试
JMeter
ApiPost产生的初衷是为了提高研发团队各个角色的效率!产品的使用受众为由前端开发、后端开发和测试人员以及技术经理组成的整个研发技术团队。
APIPOST通过协作功能将研发团队的每个角色整合打通。
安装
ApiPost目前提供Window64位,Window32位、Mac、Linux版本的安装包下载。
使用
发送HTTP请求
API界面功能布局

API请求参数
Header 参数
你可以设置或者导入 Header 参数,cookie也在Header进行设置
Query 参数

Query 支持构造URL参数,同时支持 RESTful 的 PATH 参数(如:id)
Body 参数
Body 提供三种类型 form-data / x-www-form-urlencoded / raw ,每种类型提供三种不同的UI界面
当你需要提交表单时,切换到 x-www-form-urlencoded

当你需要提交有文件的表单时,切换到 form-data

当您需要发送JSON对象或者其他对象时,切换到对应的raw类型即可

API 请求响应

点击发送按钮后,如果有数据返回,则会显示返回数据,响应时间,响应码,Cookie等。
注意:返回数据默认是Pretty模式,便于查看 JSON XML 格式。您可以通过切换 原生 或 预览 模式 查看其它类型的类型。
返回Headers

全局参数和目录参数
实际的企业级应用开发常见下,通常会约定一些通用的数据,比如token、时间、终端这些,如果每个接口都去独立去维护,势必会对开发、调试带来一些不必要的工作量;此时,我们就需要有一个能设置全局参数的地方来统一管理这些公共参数
全局参数
我们打开全局参数管理器,在全局header除填上token参数:

每次在接口请求的时候,就会自动带上这些公共配置的参数。
目录参数
目录参数和全局参数的作用一样,属于一个更细化的功能,可以通过目录,来区分全局参数的作用域;可以为不同的目录设置不用的公共参数:

参数的优先级
当全局参数、目录参数、接口中都使用了同一个参数时,最终会按照以下优先级读取参数值:
单个接口 > 目录参数 > 全局参数
响应和断言
响应

当Http请求发送之后,得到的服务端返回的结果表示一个响应;其中会得到状态码、数据、Headers、Cookie等。
Headers

断言
服务器返回了响应数据,并不代表着接口就一定正常了,很可能以为bug或者数据异常导致得到的结果并没有达到实际的预期;因此,我们就可以使用断言功能,来判断最终响应的结果是不是我们想要的;

常用断言表达式
1、检查response body中是否包含某个string
apt.assert('response.raw.responseText=="test"'); // 检查响应文本是否等于test字符串
apt.assert('response.raw.responseText.indexOf("test") > -1'); // 检查响应文本是否含有test字符串