2017-09-21 15:15:21 +08:00
|
|
|
|
<!DOCTYPE html>
|
|
|
|
|
<html lang="zh-CN">
|
|
|
|
|
|
|
|
|
|
<head>
|
|
|
|
|
<meta charset="UTF-8">
|
|
|
|
|
<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
|
|
|
|
|
<meta name="format-detection" content="telephone=no,email=no" />
|
|
|
|
|
<meta http-equiv="X-UA-Compatible" content="ie=edge, chrome=1">
|
|
|
|
|
<meta name="description" content="description of your site">
|
|
|
|
|
<meta name="author" content="author of the site">
|
|
|
|
|
<title>YApi 使用手册</title>
|
|
|
|
|
<link rel="stylesheet" href="source/main.css" />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<link rel="stylesheet" href="styles/theme.css" />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</head>
|
|
|
|
|
<body>
|
|
|
|
|
<div class="ydoc">
|
|
|
|
|
<header class="ydoc-header">
|
|
|
|
|
<div class="ydoc-header-area">
|
|
|
|
|
|
|
|
|
|
<a href="http://ued.qunar.com/ymfe/" class="navbar-brand">YMFE</a>
|
|
|
|
|
|
|
|
|
|
<button class="ydocIcon navbar-toggle"></button>
|
|
|
|
|
<nav class="ydoc-nav">
|
|
|
|
|
<ul class="navbar-left">
|
|
|
|
|
|
|
|
|
|
<li class="active">
|
|
|
|
|
|
|
|
|
|
<a href="index.html">使用手册</a>
|
|
|
|
|
</li>
|
|
|
|
|
|
2017-10-10 10:25:50 +08:00
|
|
|
|
<li class="">
|
|
|
|
|
|
|
|
|
|
<a href="devops.html">内网部署</a>
|
|
|
|
|
</li>
|
|
|
|
|
|
2017-10-11 16:09:25 +08:00
|
|
|
|
<li class="">
|
|
|
|
|
|
|
|
|
|
<a href="plugin.html">插件Wiki</a>
|
|
|
|
|
</li>
|
|
|
|
|
|
2017-10-20 10:54:08 +08:00
|
|
|
|
<li class="">
|
|
|
|
|
|
|
|
|
|
<a href="qa.html">常见问题</a>
|
|
|
|
|
</li>
|
|
|
|
|
|
2017-09-21 15:15:21 +08:00
|
|
|
|
<li class="">
|
|
|
|
|
|
|
|
|
|
<a href="releases.html">版本记录</a>
|
|
|
|
|
</li>
|
|
|
|
|
|
2017-09-29 22:11:58 +08:00
|
|
|
|
<li class="">
|
|
|
|
|
|
2017-10-14 13:33:35 +08:00
|
|
|
|
<a href="http://yapi.demo.qunar.com/" target="_blank">demo站点</a>
|
2017-09-29 22:11:58 +08:00
|
|
|
|
</li>
|
|
|
|
|
|
2017-09-21 15:15:21 +08:00
|
|
|
|
<li class="">
|
|
|
|
|
|
|
|
|
|
<a href="api.html"></a>
|
|
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
</ul>
|
|
|
|
|
</nav>
|
|
|
|
|
</div>
|
|
|
|
|
</header>
|
|
|
|
|
|
|
|
|
|
<!-- <header style="height:20px"></header> -->
|
|
|
|
|
|
|
|
|
|
<!-- Docs page layout -->
|
|
|
|
|
|
|
|
|
|
<div class="ydoc-banner-bg">
|
|
|
|
|
<div class="ydoc-banner ">
|
|
|
|
|
<div class="ydoc-banner-area">
|
|
|
|
|
<h1 >YApi</h1>
|
|
|
|
|
<p class="desc ">高效、易用、功能强大的api管理平台,旨在为开发、产品、测试人员提供更优雅的接口管理服务。</p>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="ydoc-container">
|
|
|
|
|
|
|
|
|
|
<div class="ydoc-container-content ">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="content-left staticsidenav" role="complementary">
|
|
|
|
|
<nav class="docs-sidebar hidden-print hidden-xs hidden-sm">
|
|
|
|
|
<ul class="nav docs-sidenav">
|
|
|
|
|
|
|
|
|
|
<!-- <li > -->
|
|
|
|
|
<li >
|
|
|
|
|
|
|
|
|
|
<a href="getfamiliar.html">认识 YApi</a>
|
|
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
<!-- <li > -->
|
|
|
|
|
<li >
|
|
|
|
|
|
|
|
|
|
<a href="quickstart.html">创建第一个API</a>
|
|
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
<!-- <li > -->
|
|
|
|
|
<li >
|
|
|
|
|
|
|
|
|
|
<a href="manage.html">管理分组与项目</a>
|
|
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
<!-- <li > -->
|
|
|
|
|
<li >
|
|
|
|
|
|
|
|
|
|
<a href="project.html">项目操作</a>
|
|
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
<!-- <li > -->
|
|
|
|
|
<li >
|
|
|
|
|
|
|
|
|
|
<a href="interface.html">接口操作</a>
|
|
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
<!-- <li > -->
|
|
|
|
|
<li >
|
|
|
|
|
|
2017-10-25 17:20:55 +08:00
|
|
|
|
<a href="mock.html">普通 Mock</a>
|
|
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
<!-- <li > -->
|
|
|
|
|
<li >
|
|
|
|
|
|
|
|
|
|
<a href="adv_mock.html">高级 Mock</a>
|
2017-09-21 15:15:21 +08:00
|
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
<!-- <li class="active" class="active" > -->
|
|
|
|
|
<li class="active" >
|
|
|
|
|
|
|
|
|
|
<a href="case.html">使用测试集</a>
|
|
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
<ul class="nav docs-sidenav-extend" >
|
|
|
|
|
|
|
|
|
|
<li >
|
|
|
|
|
<a href="#介绍">介绍</a>
|
|
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
<li >
|
2017-09-21 17:20:17 +08:00
|
|
|
|
<a href="#测试列表">测试列表</a>
|
2017-09-21 15:15:21 +08:00
|
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
<li >
|
2017-09-21 17:20:17 +08:00
|
|
|
|
<a href="#编辑测试用例">编辑测试用例</a>
|
2017-09-21 15:15:21 +08:00
|
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
|
|
<!-- <li > -->
|
|
|
|
|
<li >
|
|
|
|
|
|
|
|
|
|
<a href="data.html">数据导入</a>
|
|
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
</ul>
|
|
|
|
|
</nav>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="content-right markdown-body use-sidebar" role="main">
|
|
|
|
|
|
2017-10-25 17:29:20 +08:00
|
|
|
|
<h2 class="subject" id="介绍">介绍 <a class="hashlink" href="#介绍">#</a></h2><p style='text-indent:2em;line-height:1.8em'>在平时的开发过程中,经常遇到的一个问题是每次调试接口都需要重新填写参数,YApi测试集不但能够保存之前填写的参数,方便下次的调试,还可以一次性测试所有接口,每个的请求参数可以通过前面已请求的接口数据读取,或填写mock随机字符串,通过设置断言脚本验证返回数据的正确性,</p>
|
2017-09-21 15:15:21 +08:00
|
|
|
|
|
2017-10-24 15:17:26 +08:00
|
|
|
|
<h2 class="subject" id="测试列表">测试列表 <a class="hashlink" href="#测试列表">#</a></h2><p><img class="doc-img" style="width: 618px;" src="./images/usage/case-list.gif" /></p>
|
2017-09-25 16:14:37 +08:00
|
|
|
|
<p>在测试列表可以看到每个测试用例的 key,还有 开始测试、报告等功能</p>
|
|
|
|
|
<p>点击开始测试会按照 case 定义的参数从上往下一个一个进行测试,如果顺序有问题,可以拖动调整</p>
|
2017-09-21 17:20:17 +08:00
|
|
|
|
<p>测试完成之后,点击报告查看该次请求的结果</p>
|
|
|
|
|
<h2 class="subject" id="编辑测试用例">编辑测试用例 <a class="hashlink" href="#编辑测试用例">#</a></h2><h3 class="subject" id="Mock参数">Mock参数 <a class="hashlink" href="#Mock参数">#</a></h3><p>Mock 参数每次请求都会生成随机字符串</p>
|
|
|
|
|
<p><img class="doc-img" style="width:100%" src="./images/usage/case-edit.jpg" /></p>
|
2017-10-19 17:53:43 +08:00
|
|
|
|
<h4 class="subject" id="变量参数">变量参数 <a class="hashlink" href="#变量参数">#</a></h4><p>YApi 提供了强大的变量参数功能,你可以在测试的时候使用前面接口的 <code>参数</code> 或 <code>返回值</code> 作为 <code>后面接口的参数</code>,即使接口之间存在依赖,也可以轻松 <strong>一键测试~</strong></p>
|
2017-10-19 17:49:25 +08:00
|
|
|
|
<p>格式:</p>
|
|
|
|
|
<pre><code>$.<span class="token punctuation">{</span>key<span class="token punctuation">}</span>.<span class="token punctuation">{</span>params|body<span class="token punctuation">}</span>.<span class="token punctuation">{</span>path<span class="token punctuation">}</span>
|
|
|
|
|
</code></pre><p>例如:现有两个接口,分别是“导航标题”和“文章列表”
|
|
|
|
|
<img class="doc-img" style="width: 678px;" src="./images/usage/case_key_list.png" /></p>
|
2017-10-18 16:29:18 +08:00
|
|
|
|
<p>文章列表接口需要传参数: <code>当前标题(id)</code>,而这个 id 需要通过 <code>导航标题</code> 的返回值获取,这时应在 <code>文章列表</code> 的参数输入框中根据前者的 key 找到对应 id。</p>
|
2017-10-19 17:49:25 +08:00
|
|
|
|
<p><code>导航标题</code> 的参数和返回值有如下结构:</p>
|
|
|
|
|
<div style="margin: 16px 0;">
|
|
|
|
|
<span style="display: inline-block; width: 60px;vertical-align: top;">参数:</span>
|
|
|
|
|
<img style="width: 165px;" src="./images/usage/case_key_res_query.png" />
|
|
|
|
|
</div>
|
|
|
|
|
<div style="margin: 16px 0;">
|
|
|
|
|
<span style="display: inline-block; width: 60px;vertical-align: top;">返回值:</span>
|
|
|
|
|
<img style="width: 122px;" src="./images/usage/case_key_res.png" />
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<p>则 <code>文章列表</code> 的参数可以如下配置:
|
|
|
|
|
<img class="doc-img" style="width: 624px;" src="./images/usage/case_key_query.png" /></p>
|
|
|
|
|
<p>其中 <strong>$.</strong> 是使用 <strong>动态变量</strong> 的标志,$.269.<strong>params</strong> 即表示 key 值为 269 用例的请求参数,$.269.<strong>body</strong> 即表示 key 值为 269 用例的返回值。</p>
|
2017-10-18 16:29:18 +08:00
|
|
|
|
<blockquote>
|
|
|
|
|
<p>Tips: 上下拖动测试集合的列表项可以调整测试的顺序。</p>
|
|
|
|
|
</blockquote>
|
2017-10-25 17:24:33 +08:00
|
|
|
|
<h3 class="subject" id="高级">高级 <a class="hashlink" href="#高级">#</a></h3><p>可通过写断言脚本,实现精准测试,支持 js 所有语法</p>
|
|
|
|
|
<h4 class="subject" id="公共变量">公共变量 <a class="hashlink" href="#公共变量">#</a></h4><ul>
|
|
|
|
|
<li><p>assert </p>
|
|
|
|
|
<p>断言函数,详细 api可查看 <a target="_blank" href="https://nodejs.org/dist/latest-v8.x/docs/api/assert.html">document</a></p>
|
|
|
|
|
</li><li><p>status</p>
|
|
|
|
|
<p>http 状态码</p>
|
|
|
|
|
</li><li><p>body </p>
|
|
|
|
|
<p>返回 response body</p>
|
|
|
|
|
</li><li><p>header </p>
|
|
|
|
|
<p>返回 response header</p>
|
|
|
|
|
</li><li><p>records </p>
|
|
|
|
|
<p>记录的 http 请求信息,假设需要获取 key为555的接口参数或者响应数据,可通过 records[555].params 或 records[555].body 获取 </p>
|
|
|
|
|
</li></ul>
|
|
|
|
|
<h4 class="subject" id="示例">示例 <a class="hashlink" href="#示例">#</a></h4><pre><code>assert.equal(body.errcode<span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span>
|
|
|
|
|
assert.equal(body.data.group_name<span class="token punctuation">,</span> 'testGroup'<span class="token punctuation">)</span>
|
|
|
|
|
</code></pre>
|
2017-09-21 15:15:21 +08:00
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<footer class="footer">
|
|
|
|
|
<div class="copyright">
|
|
|
|
|
© 2016 <a href="http://ued.qunar.com/ymfe/">YMFE</a> Team. Build by <a href="http://ued.qunar.com/ydoc/">ydoc</a>.
|
|
|
|
|
</div>
|
|
|
|
|
</footer>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="open-panel"></div>
|
|
|
|
|
<div class="mask"></div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<script src="source/main.js"></script>
|
|
|
|
|
<script src="source/app.js"></script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</body>
|
|
|
|
|
|
|
|
|
|
</html>
|