资讯专栏INFORMATION COLUMN

postman--断言写法

qingshanli1988 / 821人阅读

摘要:断言介绍是一套测试驱动开发行为驱动开发的断言库包含有个断言库支持风格的和风格的可以高效的和任何测试框架搭配使用支持在中应用获取断言方式语法一测试用例名称表达式语法二断言库,可以通过右侧页签点击生成代码截取实际响应信息的

chai.js断言介绍

  1. 是一套TDD(测试驱动开发)/BDD(行为驱动开发)的断言库

  2. List item包含有3个断言库支持BDD风格的expect/should和TDD风格的assert

  3. List item可以高效的和任何js测试框架搭配使用(支持在postman中应用

获取断言方式

语法一:
tests[‘测试用例名称’] = 表达式;
语法二:
Chai.js断言库, 可以通过右侧页签点击生成代码

截取实际响应信息的新老版本代码对比

获取相应状体码:var code = responseCode.code; //旧式做法tests[code] = true;var code1 = pm.response.code; //新式做法tests[code] = true;获取响应信息:var info = responseCode.name;var info1 = pm.response.status;获取响应时间:var time = responseTime;tests["case_demo_02:验证响应时间是否再100-500以内返回"] = time>=100 && time<=500;var time1 = pm.response.responseTime获取响应头:var value = postman.getResponseHeader("Content-Type");var v1 = pm.response.headers;获取响应正文:var body_info = responseBody;var b1 = pm.response.text();

匹配正则表达式 match()

> <title>这是一个标题</title>var title_info = body_info.match(new RegExp("(.+?)"))[1];tests[title_info] = true;//[]只能填010"这是一个标题"1"这是一个标题",去除[]"这是一个标题"</span><span class="token operator">//</span><span class="token punctuation">.</span>匹配一个字符  <span class="token operator">+</span>表示匹配前面的子表达式<span class="token number">1</span>次或多次  ?懒惰字符 首次遇到右边界就停止匹配</code></pre> <h3><a id="test_50"></a>test断言基本语法</h3> <pre><code class="prism language-python">tests<span class="token punctuation">[</span><span class="token string">"case01 验证是否为true"</span><span class="token punctuation">]</span> <span class="token operator">=</span> true<span class="token punctuation">;</span>    <span class="token operator">//</span>falsetests<span class="token punctuation">[</span><span class="token string">"case02 验证是否1+1=2"</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token number">1</span><span class="token operator">+</span><span class="token number">1</span> <span class="token operator">==</span><span class="token operator">=</span> <span class="token number">2</span><span class="token punctuation">;</span>    <span class="token operator">//</span>判断是否相等tests<span class="token punctuation">[</span><span class="token string">"case03 验证是否包含123"</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">"1234567hello"</span><span class="token punctuation">.</span>has<span class="token punctuation">(</span><span class="token string">"123"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>    <span class="token operator">//</span>判断是否包含tests<span class="token punctuation">[</span><span class="token string">"case04 验证是否3>5"</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token number">3</span> <span class="token operator">></span> <span class="token number">5</span> <span class="token punctuation">;</span>    <span class="token operator">//</span>判断是否相等tests<span class="token punctuation">[</span><span class="token string">"case05 与运算"</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token number">3</span> <span class="token operator">></span> <span class="token number">2</span> <span class="token operator">&</span><span class="token operator">&</span> <span class="token number">3</span><span class="token operator">></span><span class="token number">1</span> <span class="token punctuation">;</span>    <span class="token operator">//</span>与运算tests<span class="token punctuation">[</span><span class="token string">"case06 或运算"</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token number">3</span> <span class="token operator">></span> <span class="token number">2</span> <span class="token operator">|</span><span class="token operator">|</span> <span class="token number">3</span><span class="token operator">></span><span class="token number">5</span> <span class="token punctuation">;</span>    <span class="token operator">//</span>或运算tests<span class="token punctuation">[</span><span class="token string">"case07 非运算"</span><span class="token punctuation">]</span> <span class="token operator">=</span> !<span class="token punctuation">(</span><span class="token number">3</span> <span class="token operator">></span> <span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">;</span>    <span class="token operator">//</span>非运算</code></pre> <h3><a id="json_61"></a>把响应正文解析为json对象</h3> <pre><code class="prism language-python">var jsondata <span class="token operator">=</span> JSON<span class="token punctuation">.</span>parse<span class="token punctuation">(</span>responseBody<span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token operator">//</span>旧版本写法var token <span class="token operator">=</span> jsondata<span class="token punctuation">.</span>expires_in<span class="token punctuation">;</span>tests<span class="token punctuation">[</span>token<span class="token punctuation">]</span> <span class="token operator">=</span> true<span class="token punctuation">;</span>var jd <span class="token operator">=</span> pm<span class="token punctuation">.</span>response<span class="token punctuation">.</span>json<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token operator">//</span>新版本写法tests<span class="token punctuation">[</span>jd<span class="token punctuation">.</span>access_token<span class="token punctuation">]</span> <span class="token operator">=</span> true<span class="token punctuation">;</span></code></pre> <pre><code class="prism language-python"><span class="token operator">></span> <span class="token punctuation">{<!-- --></span><span class="token string">"tags"</span><span class="token punctuation">:</span><span class="token punctuation">[</span><span class="token punctuation">{<!-- --></span><span class="token string">"id"</span><span class="token punctuation">:</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token string">"name"</span><span class="token punctuation">:</span><span class="token string">"星标组"</span><span class="token punctuation">,</span><span class="token string">"count"</span><span class="token punctuation">:</span><span class="token number">0</span><span class="token punctuation">}</span><span class="token punctuation">,</span><span class="token punctuation">{<!-- --></span><span class="token string">"id"</span><span class="token punctuation">:</span><span class="token number">100</span><span class="token punctuation">,</span><span class="token string">"name"</span><span class="token punctuation">:</span><span class="token string">"广东"</span><span class="token punctuation">,</span><span class="token string">"count"</span><span class="token punctuation">:</span><span class="token number">0</span><span class="token punctuation">}</span><span class="token punctuation">]</span><span class="token punctuation">}</span>var jd <span class="token operator">=</span> pm<span class="token punctuation">.</span>response<span class="token punctuation">.</span>json<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>var v <span class="token operator">=</span> jd<span class="token punctuation">.</span>tags<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">.</span>name<span class="token punctuation">;</span> tests<span class="token punctuation">[</span>v<span class="token punctuation">]</span> <span class="token operator">=</span> true<span class="token punctuation">;</span></code></pre> <h3><a id="chaijs_79"></a>chai.js断言语法</h3> <pre><code class="prism language-python"><span class="token operator">//</span>chai<span class="token punctuation">,</span>js断言新写法pm<span class="token punctuation">.</span>test<span class="token punctuation">(</span><span class="token string">"case_demo_01 测试用例名称"</span><span class="token punctuation">,</span> function <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{<!-- --></span>    pm<span class="token punctuation">.</span>expect<span class="token punctuation">(</span>true<span class="token punctuation">)</span><span class="token punctuation">.</span>to<span class="token punctuation">.</span>be<span class="token punctuation">.</span>true<span class="token punctuation">;</span>   <span class="token operator">//</span>chai<span class="token punctuation">.</span>js断言编写处<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>pm<span class="token punctuation">.</span>test<span class="token punctuation">(</span><span class="token string">"case_demo_02 相等"</span><span class="token punctuation">,</span> function <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{<!-- --></span>    pm<span class="token punctuation">.</span>expect<span class="token punctuation">(</span><span class="token number">1</span><span class="token operator">+</span><span class="token number">1</span><span class="token operator">==</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">.</span>to<span class="token punctuation">.</span>be<span class="token punctuation">.</span>true<span class="token punctuation">;</span>    <span class="token operator">//</span>判断是否相等<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>pm<span class="token punctuation">.</span>test<span class="token punctuation">(</span><span class="token string">"case_demo_02 测试用例名称"</span><span class="token punctuation">,</span> function <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{<!-- --></span>    pm<span class="token punctuation">.</span>expect<span class="token punctuation">(</span><span class="token number">2</span> <span class="token operator"><</span> <span class="token number">5</span> <span class="token operator">&</span><span class="token operator">&</span> <span class="token number">3</span> <span class="token operator"><</span> <span class="token number">6</span><span class="token punctuation">)</span><span class="token punctuation">.</span>to<span class="token punctuation">.</span>be<span class="token punctuation">.</span>true<span class="token punctuation">;</span>    <span class="token operator">//</span>判断是否为true<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>pm<span class="token punctuation">.</span>test<span class="token punctuation">(</span><span class="token string">"case_demo_03 测试用例名称"</span><span class="token punctuation">,</span> function <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{<!-- --></span>    pm<span class="token punctuation">.</span>expect<span class="token punctuation">(</span><span class="token string">""</span><span class="token punctuation">)</span><span class="token punctuation">.</span>to<span class="token punctuation">.</span>be<span class="token punctuation">.</span>ok<span class="token punctuation">;</span>    <span class="token operator">//</span>判断是否为真值  非空、非<span class="token number">0</span> 即为真<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>pm<span class="token punctuation">.</span>test<span class="token punctuation">(</span><span class="token string">"case_demo_04 测试用例名称"</span><span class="token punctuation">,</span> function <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{<!-- --></span>    pm<span class="token punctuation">.</span>expect<span class="token punctuation">(</span><span class="token string">"hello"</span><span class="token punctuation">)</span><span class="token punctuation">.</span>to<span class="token punctuation">.</span>equal<span class="token punctuation">(</span><span class="token string">"hello"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token operator">//</span>判断是否相等<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>pm<span class="token punctuation">.</span>test<span class="token punctuation">(</span><span class="token string">"case_demo_05 测试用例名称"</span><span class="token punctuation">,</span> function <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{<!-- --></span>    pm<span class="token punctuation">.</span>expect<span class="token punctuation">(</span><span class="token punctuation">{<!-- --></span> <span class="token string">"list"</span><span class="token punctuation">:</span> <span class="token string">"aaa"</span> <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">.</span>to<span class="token punctuation">.</span>eql<span class="token punctuation">(</span><span class="token punctuation">{<!-- --></span> <span class="token string">"list"</span><span class="token punctuation">:</span> <span class="token string">"aaa"</span> <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>    <span class="token operator">//</span>判断是否深度相等<span class="token punctuation">{<!-- --></span><span class="token string">"list"</span><span class="token punctuation">:</span><span class="token string">"aaa"</span><span class="token punctuation">}</span><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>pm<span class="token punctuation">.</span>test<span class="token punctuation">(</span><span class="token string">"case_demo_06 测试用例名称"</span><span class="token punctuation">,</span> function <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{<!-- --></span>    pm<span class="token punctuation">.</span>expect<span class="token punctuation">(</span><span class="token string">"foobar"</span><span class="token punctuation">)</span><span class="token punctuation">.</span>to<span class="token punctuation">.</span>have<span class="token punctuation">.</span>string<span class="token punctuation">(</span><span class="token string">"bar"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>    <span class="token operator">//</span>判断是否包含字符串<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>pm<span class="token punctuation">.</span>test<span class="token punctuation">(</span><span class="token string">"case_demo_07 测试用例名称"</span><span class="token punctuation">,</span> function <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{<!-- --></span>    pm<span class="token punctuation">.</span>expect<span class="token punctuation">(</span><span class="token string">"foobar"</span><span class="token punctuation">)</span><span class="token punctuation">.</span>to<span class="token punctuation">.</span>match<span class="token punctuation">(</span><span class="token operator">/</span><span class="token operator">^</span>foo<span class="token operator">/</span><span class="token punctuation">)</span><span class="token punctuation">;</span>    <span class="token operator">//</span>判断是否包含,支持正则表达式  <span class="token operator">^</span>表示以什么开头<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre> <h3><a id="chaijs_115"></a>chai.js断言语法</h3> <pre><code class="prism language-python">pm<span class="token punctuation">.</span>test<span class="token punctuation">(</span><span class="token string">"case_demo_01 200"</span><span class="token punctuation">,</span> function <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{<!-- --></span>pm<span class="token punctuation">.</span>expect<span class="token punctuation">(</span>pm<span class="token punctuation">.</span>response<span class="token punctuation">.</span>code<span class="token punctuation">)</span><span class="token punctuation">.</span>to<span class="token punctuation">.</span>equal<span class="token punctuation">(</span><span class="token number">200</span><span class="token punctuation">)</span><span class="token punctuation">}</span><span class="token punctuation">)</span>pm<span class="token punctuation">.</span>test<span class="token punctuation">(</span><span class="token string">"case_demo_0"</span><span class="token punctuation">,</span> function <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{<!-- --></span>    pm<span class="token punctuation">.</span>expect<span class="token punctuation">(</span>pm<span class="token punctuation">.</span>response<span class="token punctuation">.</span>text<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">.</span>to<span class="token punctuation">.</span>have<span class="token punctuation">.</span>string<span class="token punctuation">(</span><span class="token string">"文本"</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token punctuation">}</span><span class="token punctuation">)</span></code></pre> <h3><a id="_125"></a>部分基础语法</h3> <pre><code class="prism language-python">设置环境变量token,供后面的接口引用var data <span class="token operator">=</span> JSON<span class="token punctuation">.</span>parse<span class="token punctuation">(</span>responseBody<span class="token punctuation">)</span><span class="token punctuation">;</span>postman<span class="token punctuation">.</span>setGlobalVariable<span class="token punctuation">(</span><span class="token string">"token_id"</span><span class="token punctuation">,</span> value<span class="token punctuation">)</span> <span class="token operator">//</span>旧方法pm<span class="token punctuation">.</span><span class="token builtin">globals</span><span class="token punctuation">.</span><span class="token builtin">set</span><span class="token punctuation">(</span><span class="token string">"token_id"</span><span class="token punctuation">,</span> data<span class="token punctuation">.</span>access_token<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token operator">//</span>新</code></pre> <p>学IT,上博学谷<br /> https://m.boxuegu.com/inviteShare/invited?id=8a2c9bed6aa1c063016ab53099d00037&source=1&from=singlemessage</p>                </div>                <link href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/editerView/markdown_views-d7a94ec6ab.css" rel="stylesheet">                <link href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/style-49037e4d27.css" rel="stylesheet">        </div>        <div id="treeSkill"></div>               
               
                                           
                       
                 </div>
            
                     <div class="mt-64 tags-seach" >
                 <div class="tags-info">
                                                                                                                    
                         <a style="width:120px;" title="GPU云服务器" href="https://www.ucloud.cn/site/product/gpu.html">GPU云服务器</a>
                                             
                         <a style="width:120px;" title="云服务器" href="https://www.ucloud.cn/site/active/kuaijiesale.html?ytag=seo">云服务器</a>
                                                                                                                                                 
                                      
                     
                    
                                                                                               <a style="width:120px;" title="Postman" href="https://www.ucloud.cn/yun/tag/Postman/">Postman</a>
                                                                                                           <a style="width:120px;" title="postman怎么测试云服务器本地" href="https://www.ucloud.cn/yun/tag/postmanzenmeceshiyunfuwuqibendi/">postman怎么测试云服务器本地</a>
                                                                                                           <a style="width:120px;" title="正向断言" href="https://www.ucloud.cn/yun/tag/zhengxiangduanyan/">正向断言</a>
                                                                                                           <a style="width:120px;" title="断言" href="https://www.ucloud.cn/yun/tag/duanyan/">断言</a>
                                                         
                 </div>
               
              </div>
             
               <div class="entry-copyright mb-30">
                   <p class="mb-15"> 文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。</p>
                 
                   <p>转载请注明本文地址:https://www.ucloud.cn/yun/123439.html</p>
               </div>
                      
               <ul class="pre-next-page">
                 
                                  <li class="ellipsis"><a class="hpf" href="https://www.ucloud.cn/yun/123438.html">上一篇:#例程学习# | Git技能学习 |简单Git流程:本地创建、远程建仓、添加上传</a></li>  
                                                
                                       <li class="ellipsis"><a class="hpf" href="https://www.ucloud.cn/yun/123440.html">下一篇:2021-11-15</a></li>
                                  </ul>
              </div>
              <div class="about_topicone-mid">
                <h3 class="top-com-title mb-0"><span data-id="0">相关文章</span></h3>
                <ul class="com_white-left-mid atricle-list-box">
                             
                                                                                                    <li>
                                                <div class="atricle-list-right">
                          <h2 class="ellipsis2"><a class="hpf" href="https://www.ucloud.cn/yun/123266.html"><b><em>Postman</em>快速入门-接口测试教程,取和引用响应值,<em>断言</em>,json路径<em>写法</em></b></a></h2>
                                                     <p class="ellipsis2 good">摘要:目录的基础页面的功能解释的基础页面的功能解释如何创建请求如何创建请求提取响应结果中的值然后再其它接口中调用提取响应结果中的值然后再其它接口中调用新建环境来存储环境变量新建环境来存储环境变量在中通过语句提取响应结果                                                    目录 1.Postman的基础页面的功能解释 2.如何创建请求 3.提取 响应...</p>
                                                   
                          <div class="com_white-left-info">
                                <div class="com_white-left-infol">
                                    <a href="https://www.ucloud.cn/yun/u-1063.html"><img src="https://www.ucloud.cn/yun/data/avatar/000/00/10/small_000001063.jpg" alt=""><span class="layui-hide64">Cc_2011</span></a>
                                    <time datetime="">2021-11-15 11:37</time>
                                    <span><i class="fa fa-commenting"></i>评论0</span> 
                                    <span><i class="fa fa-star"></i>收藏0</span> 
                                </div>
                          </div>
                      </div>
                    </li> 
                                                                                       <li>
                                                <div class="atricle-list-right">
                          <h2 class="ellipsis2"><a class="hpf" href="https://www.ucloud.cn/yun/122099.html"><b>【接口测试—<em>postman</em>】5分钟让你学会接口测试工具——<em>postman</em>的基础常用技巧,看完少走一周</b></a></h2>
                                                     <p class="ellipsis2 good">摘要:今天来和大家分享下,我这段时间做接口测试的一些心得。接口测试就我目前的理解,大部分情况下,接口测试,就是按照接口测试文档,输入相应的请求,看能否得到文档上所写的接口返回消息。这一过程,称之为接口测试,如果没有返回相应的信息,说明有了。                                                    大家好,我是好学的小师弟。今天来和大家分享下,我这段时间...</p>
                                                   
                          <div class="com_white-left-info">
                                <div class="com_white-left-infol">
                                    <a href="https://www.ucloud.cn/yun/u-134.html"><img src="https://www.ucloud.cn/yun/data/avatar/000/00/01/small_000000134.jpg" alt=""><span class="layui-hide64">The question</span></a>
                                    <time datetime="">2021-10-11 10:57</time>
                                    <span><i class="fa fa-commenting"></i>评论0</span> 
                                    <span><i class="fa fa-star"></i>收藏0</span> 
                                </div>
                          </div>
                      </div>
                    </li> 
                                                                                       <li>
                                                <div class="atricle-list-right">
                          <h2 class="ellipsis2"><a class="hpf" href="https://www.ucloud.cn/yun/121600.html"><b><em>Postman</em>接口测试工具</b></a></h2>
                                                     <p class="ellipsis2 good">摘要:简介是一款功能强大的网页调试与发送网页请求,并能运行测试用例的测试工具能够模拟各种从常用的到的等甚至还可以发送文件额外的。                                                                                                                    持续更新… 标记  Postman 1....</p>
                                                   
                          <div class="com_white-left-info">
                                <div class="com_white-left-infol">
                                    <a href="https://www.ucloud.cn/yun/u-193.html"><img src="https://www.ucloud.cn/yun/data/avatar/000/00/01/small_000000193.jpg" alt=""><span class="layui-hide64">awesome23</span></a>
                                    <time datetime="">2021-09-30 09:47</time>
                                    <span><i class="fa fa-commenting"></i>评论0</span> 
                                    <span><i class="fa fa-star"></i>收藏0</span> 
                                </div>
                          </div>
                      </div>
                    </li> 
                                                                                       <li>
                                                <div class="atricle-list-right">
                          <h2 class="ellipsis2"><a class="hpf" href="https://www.ucloud.cn/yun/118961.html"><b><em>PostMan</em>详细介绍</b></a></h2>
                                                     <p class="ellipsis2 good">摘要:无论接口调式还是接口测试,都算的上很优秀的工具,好多接口测试平台,接口测试工具框架的设计也都能看到的影子主要界面功能介绍新建,可以创建请求,请求集,环境变量等。                                                    无论接口调式还是接口测试,postman都算的上很优秀的工具,好多接口测试平台,接口测试工具框架的设计也都能看到 postman的...</p>
                                                   
                          <div class="com_white-left-info">
                                <div class="com_white-left-infol">
                                    <a href="https://www.ucloud.cn/yun/u-172.html"><img src="https://www.ucloud.cn/yun/data/avatar/000/00/01/small_000000172.jpg" alt=""><span class="layui-hide64">mushang</span></a>
                                    <time datetime="">2021-09-03 10:28</time>
                                    <span><i class="fa fa-commenting"></i>评论0</span> 
                                    <span><i class="fa fa-star"></i>收藏0</span> 
                                </div>
                          </div>
                      </div>
                    </li> 
                                                                                       <li>
                                                <div class="atricle-list-right">
                          <h2 class="ellipsis2"><a class="hpf" href="https://www.ucloud.cn/yun/123140.html"><b><em>Postman</em>教程-Pre-request Script和Tests脚本的介绍</b></a></h2>
                                                     <p class="ellipsis2 good">摘要:本章将重点介绍和的相关知识。与文件夹相关联的脚本将在文件夹中的每个请求之前运行。与集合相关的脚本将在集合中的每个请求之后运行。脚本使用场景工具借助测试脚来帮助用户自动判断接口请求是否正确,相当于工具中的检查点或者中的断言功能。                                                                                    ...</p>
                                                   
                          <div class="com_white-left-info">
                                <div class="com_white-left-infol">
                                    <a href="https://www.ucloud.cn/yun/u-804.html"><img src="https://www.ucloud.cn/yun/data/avatar/000/00/08/small_000000804.jpg" alt=""><span class="layui-hide64">Steve_Wang_</span></a>
                                    <time datetime="">2021-11-12 10:34</time>
                                    <span><i class="fa fa-commenting"></i>评论0</span> 
                                    <span><i class="fa fa-star"></i>收藏0</span> 
                                </div>
                          </div>
                      </div>
                    </li> 
                                                                           
                </ul>
              </div>
              
               <div class="topicone-box-wangeditor">
                  
                  <h3 class="top-com-title mb-64"><span>发表评论</span></h3>
                   <div class="xcp-publish-main flex_box_zd">
                                      
                      <div class="unlogin-pinglun-box">
                        <a href="javascript:login()" class="grad">登陆后可评论</a>
                      </div>                   </div>
               </div>
              <div class="site-box-content">
                <div class="site-content-title">
                  <h3 class="top-com-title mb-64"><span>0条评论</span></h3>   
                </div> 
                      <div class="pages"></ul></div>
              </div>
           </div>
           <div class="layui-col-md4 layui-col-lg3 com_white-right site-wrap-right">
              <div class=""> 
                <div class="com_layuiright-box user-msgbox">
                    <a href="https://www.ucloud.cn/yun/u-667.html"><img src="https://www.ucloud.cn/yun/data/avatar/000/00/06/small_000000667.jpg" alt=""></a>
                    <h3><a href="https://www.ucloud.cn/yun/u-667.html" rel="nofollow">qingshanli1988</a></h3>
                    <h6>男<span>|</span>高级讲师</h6>
                    <div class="flex_box_zd user-msgbox-atten">
                     
                                                                      <a href="javascript:attentto_user(667)" id="attenttouser_667" class="grad follow-btn notfollow attention">我要关注</a>
      
                                                                                        <a href="javascript:login()" title="发私信" >我要私信</a>
                     
                                            
                    </div>
                    <div class="user-msgbox-list flex_box_zd">
                          <h3 class="hpf">TA的文章</h3>
                          <a href="https://www.ucloud.cn/yun/ut-667.html" class="box_hxjz">阅读更多</a>
                    </div>
                      <ul class="user-msgbox-ul">
                                                  <li><h3 class="ellipsis"><a href="https://www.ucloud.cn/yun/125022.html">2021年软件测试工具总结——单元测试工具</a></h3>
                            <p>阅读 3758<span>·</span>2021-11-25 09:43</p></li>
                                                       <li><h3 class="ellipsis"><a href="https://www.ucloud.cn/yun/124551.html">DiyVM:50元/月起-双核,2G内存,50G硬盘,香港/日本/洛杉矶机房</a></h3>
                            <p>阅读 2190<span>·</span>2021-11-23 10:13</p></li>
                                                       <li><h3 class="ellipsis"><a href="https://www.ucloud.cn/yun/123439.html">postman--断言写法</a></h3>
                            <p>阅读 822<span>·</span>2021-11-16 11:44</p></li>
                                                       <li><h3 class="ellipsis"><a href="https://www.ucloud.cn/yun/114304.html">CSS font-style斜体字体倾斜体样式</a></h3>
                            <p>阅读 2367<span>·</span>2019-08-29 17:24</p></li>
                                                       <li><h3 class="ellipsis"><a href="https://www.ucloud.cn/yun/114219.html">〔总结系列〕前端技术精华清单</a></h3>
                            <p>阅读 1384<span>·</span>2019-08-29 17:17</p></li>
                                                       <li><h3 class="ellipsis"><a href="https://www.ucloud.cn/yun/111693.html">LESS和SASS的区别与速查表-译文</a></h3>
                            <p>阅读 3478<span>·</span>2019-08-29 11:30</p></li>
                                                       <li><h3 class="ellipsis"><a href="https://www.ucloud.cn/yun/108715.html">React手稿 - Context</a></h3>
                            <p>阅读 2582<span>·</span>2019-08-26 13:23</p></li>
                                                       <li><h3 class="ellipsis"><a href="https://www.ucloud.cn/yun/108136.html">Rxjs 响应式编程-第五章 使用Schedulers管理时间</a></h3>
                            <p>阅读 2343<span>·</span>2019-08-26 12:10</p></li>
                                                
                      </ul>
                </div>

                   <!-- 文章详情右侧广告-->
              
  <div class="com_layuiright-box">
                  <h6 class="top-com-title"><span>最新活动</span></h6> 
           
         <div class="com_adbox">
                    <div class="layui-carousel" id="right-item">
                      <div carousel-item>
                                                                                                                       <div>
                          <a href="https://www.ucloud.cn/site/active/kuaijiesale.html?ytag=seo"  rel="nofollow">
                            <img src="https://www.ucloud.cn/yun/data/attach/240625/2rTjEHmi.png" alt="云服务器">                                 
                          </a>
                        </div>
                                                <div>
                          <a href="https://www.ucloud.cn/site/product/gpu.html"  rel="nofollow">
                            <img src="https://www.ucloud.cn/yun/data/attach/240807/7NjZjdrd.png" alt="GPU云服务器">                                 
                          </a>
                        </div>
                                                                   
                    
                        
                      </div>
                    </div>
                      
                    </div>                    <!-- banner结束 -->
              
<div class="adhtml">

</div>
                <script>
                $(function(){
                    $.ajax({
                        type: "GET",
                                url:"https://www.ucloud.cn/yun/ad/getad/1.html",
                                cache: false,
                                success: function(text){
                                  $(".adhtml").html(text);
                                }
                        });
                    })
                </script>                </div>              </div>
           </div>
        </div>
      </div> 
    </section>
    <!-- wap拉出按钮 -->
     <div class="site-tree-mobile layui-hide">
      <i class="layui-icon layui-icon-spread-left"></i>
    </div>
    <!-- wap遮罩层 -->
    <div class="site-mobile-shade"></div>
    
       <!--付费阅读 -->
       <div id="payread">
         <div class="layui-form-item">阅读需要支付1元查看</div>  
         <div class="layui-form-item"><button class="btn-right">支付并查看</button></div>     
       </div>
      <script>
      var prei=0;

       
       $(".site-seo-depict pre").each(function(){
          var html=$(this).html().replace("<code>","").replace("</code>","").replace('<code class="javascript hljs" codemark="1">','');
          $(this).attr('data-clipboard-text',html).attr("id","pre"+prei);
          $(this).html("").append("<code>"+html+"</code>");
         prei++;
       })
           $(".site-seo-depict img").each(function(){
             
            if($(this).attr("src").indexOf('data:image/svg+xml')!= -1){
                $(this).remove();
            }
       })
     $("LINK[href*='style-49037e4d27.css']").remove();
       $("LINK[href*='markdown_views-d7a94ec6ab.css']").remove();
layui.use(['jquery', 'layer','code'], function(){
  $("pre").attr("class","layui-code");
      $("pre").attr("lay-title","");
       $("pre").attr("lay-skin","");
  layui.code(); 
       $(".layui-code-h3 a").attr("class","copycode").html("复制代码 ").attr("onclick","copycode(this)");
      
});
function copycode(target){
    var id=$(target).parent().parent().attr("id");
  
                  var clipboard = new ClipboardJS("#"+id);

clipboard.on('success', function(e) {


    e.clearSelection();
    alert("复制成功")
});

clipboard.on('error', function(e) {
    alert("复制失败")
});
}
//$(".site-seo-depict").html($(".site-seo-depict").html().slice(0, -5));
</script>
  <link rel="stylesheet" type="text/css" href="https://www.ucloud.cn/yun/static/js/neweditor/code/styles/tomorrow-night-eighties.css">
    <script src="https://www.ucloud.cn/yun/static/js/neweditor/code/highlight.pack.js" type="text/javascript"></script>
    <script src="https://www.ucloud.cn/yun/static/js/clipboard.js"></script>

<script>hljs.initHighlightingOnLoad();</script>

<script>
    function setcode(){
        var _html='';
    	  document.querySelectorAll('pre code').forEach((block) => {
        	  var _tmptext=$.trim($(block).text());
        	  if(_tmptext!=''){
        		  _html=_html+_tmptext;
        		  console.log(_html);
        	  }
    		 
    		  
    		 
      	  });
    	 

    }

</script>

<script>
function payread(){
  layer.open({
      type: 1,
      title:"付费阅读",
      shadeClose: true,
      content: $('#payread')
    });
}
// 举报
function jupao_tip(){
  layer.open({
      type: 1,
      title:false,
      shadeClose: true,
      content: $('#jubao')
    });

}
$(".getcommentlist").click(function(){
var _id=$(this).attr("dataid");
var _tid=$(this).attr("datatid");
$("#articlecommentlist"+_id).toggleClass("hide");
var flag=$("#articlecommentlist"+_id).attr("dataflag");
if(flag==1){
flag=0;
}else{
flag=1;
//加载评论
loadarticlecommentlist(_id,_tid);
}
$("#articlecommentlist"+_id).attr("dataflag",flag);

})
$(".add-comment-btn").click(function(){
var _id=$(this).attr("dataid");
$(".formcomment"+_id).toggleClass("hide");
})
$(".btn-sendartcomment").click(function(){
var _aid=$(this).attr("dataid");
var _tid=$(this).attr("datatid");
var _content=$.trim($(".commenttext"+_aid).val());
if(_content==''){
alert("评论内容不能为空");
return false;
}
var touid=$("#btnsendcomment"+_aid).attr("touid");
if(touid==null){
touid=0;
}
addarticlecomment(_tid,_aid,_content,touid);
})
 $(".button_agree").click(function(){
 var supportobj = $(this);
         var tid = $(this).attr("id");
         $.ajax({
         type: "GET",
                 url:"https://www.ucloud.cn/yun/index.php?topic/ajaxhassupport/" + tid,
                 cache: false,
                 success: function(hassupport){
                 if (hassupport != '1'){






                         $.ajax({
                         type: "GET",
                                 cache:false,
                                 url: "https://www.ucloud.cn/yun/index.php?topic/ajaxaddsupport/" + tid,
                                 success: function(comments) {

                                 supportobj.find("span").html(comments+"人赞");
                                 }
                         });
                 }else{
                	 alert("您已经赞过");
                 }
                 }
         });
 });
 function attenquestion(_tid,_rs){
    	$.ajax({
    //提交数据的类型 POST GET
    type:"POST",
    //提交的网址
    url:"https://www.ucloud.cn/yun/favorite/topicadd.html",
    //提交的数据
    data:{tid:_tid,rs:_rs},
    //返回数据的格式
    datatype: "json",//"xml", "html", "script", "json", "jsonp", "text".
    //在请求之前调用的函数
    beforeSend:function(){},
    //成功返回之后调用的函数
    success:function(data){
    	var data=eval("("+data+")");
    	console.log(data)
       if(data.code==2000){
    	layer.msg(data.msg,function(){
    	  if(data.rs==1){
    	      //取消收藏
    	      $(".layui-layer-tips").attr("data-tips","收藏文章");
    	      $(".layui-layer-tips").html('<i class="fa fa-heart-o"></i>');
    	  }
    	   if(data.rs==0){
    	      //收藏成功
    	      $(".layui-layer-tips").attr("data-tips","已收藏文章");
    	      $(".layui-layer-tips").html('<i class="fa fa-heart"></i>')
    	  }
    	})
    	 
       }else{
    	layer.msg(data.msg)
       }


    }   ,
    //调用执行后调用的函数
    complete: function(XMLHttpRequest, textStatus){
     	postadopt=true;
    },
    //调用出错执行的函数
    error: function(){
        //请求出错处理
    	postadopt=false;
    }
 });
}
</script>
<footer>
        <div class="layui-container">
            <div class="flex_box_zd">
              <div class="left-footer">
                    <h6><a href="https://www.ucloud.cn/"><img src="https://www.ucloud.cn/yun/static/theme/ukd//images/logo.png" alt="UCloud (优刻得科技股份有限公司)"></a></h6>
                    <p>UCloud (优刻得科技股份有限公司)是中立、安全的云计算服务平台,坚持中立,不涉足客户业务领域。公司自主研发IaaS、PaaS、大数据流通平台、AI服务平台等一系列云计算产品,并深入了解互联网、传统企业在不同场景下的业务需求,提供公有云、混合云、私有云、专有云在内的综合性行业解决方案。</p>
              </div>
              <div class="right-footer layui-hidemd">
                  <ul class="flex_box_zd">
                      <li>
                        <h6>UCloud与云服务</h6>
                         <p><a href="https://www.ucloud.cn/site/about/intro/">公司介绍</a></p>
                         <p><a href="https://zhaopin.ucloud.cn/" >加入我们</a></p>
                         <p><a href="https://www.ucloud.cn/site/ucan/onlineclass/">UCan线上公开课</a></p>
                         <p><a href="https://www.ucloud.cn/site/solutions.html" >行业解决方案</a></p>                                                  <p><a href="https://www.ucloud.cn/site/pro-notice/">产品动态</a></p>
                      </li>
                      <li>
                        <h6>友情链接</h6>                                             <p><a href="https://www.compshare.cn/?ytag=seo">GPU算力平台</a></p>                                             <p><a href="https://www.ucloudstack.com/?ytag=seo">UCloud私有云</a></p>
                                             <p><a href="https://www.surfercloud.com/">SurferCloud</a></p>                                             <p><a href="https://www.uwin-link.com/">工厂仿真软件</a></p>                                             <p><a href="https://pinex.it/">Pinex</a></p>                                             <p><a href="https://www.picpik.ai/zh">AI绘画</a></p>
                                             
                      </li>
                      <li>
                        <h6>社区栏目</h6>
                         <p><a href="https://www.ucloud.cn/yun/column/index.html">专栏文章</a></p>
                     <p><a href="https://www.ucloud.cn/yun/udata/">专题地图</a></p>                      </li>
                      <li>
                        <h6>常见问题</h6>
                         <p><a href="https://www.ucloud.cn/site/ucsafe/notice.html" >安全中心</a></p>
                         <p><a href="https://www.ucloud.cn/site/about/news/recent/" >新闻动态</a></p>
                         <p><a href="https://www.ucloud.cn/site/about/news/report/">媒体动态</a></p>                                                  <p><a href="https://www.ucloud.cn/site/cases.html">客户案例</a></p>                                                
                         <p><a href="https://www.ucloud.cn/site/notice/">公告</a></p>
                      </li>
                      <li>
                          <span><img src="https://static.ucloud.cn/7a4b6983f4b94bcb97380adc5d073865.png" alt="优刻得"></span>
                          <p>扫扫了解更多</p></div>
            </div>
            <div class="copyright">Copyright © 2012-2023 UCloud 优刻得科技股份有限公司<i>|</i><a rel="nofollow" href="http://beian.miit.gov.cn/">沪公网安备 31011002000058号</a><i>|</i><a rel="nofollow" href="http://beian.miit.gov.cn/"></a> 沪ICP备12020087号-3</a><i>|</i> <script type="text/javascript" src="https://gyfk12.kuaishang.cn/bs/ks.j?cI=197688&fI=125915" charset="utf-8"></script>
<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?290c2650b305fc9fff0dbdcafe48b59d";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-DZSMXQ3P9N"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'G-DZSMXQ3P9N');
</script>
<script>
(function(){
var el = document.createElement("script");
el.src = "https://lf1-cdn-tos.bytegoofy.com/goofy/ttzz/push.js?99f50ea166557aed914eb4a66a7a70a4709cbb98a54ecb576877d99556fb4bfc3d72cd14f8a76432df3935ab77ec54f830517b3cb210f7fd334f50ccb772134a";
el.id = "ttzz";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(el, s);
})(window)
</script></div> 
        </div>
    </footer>
</body>
<script src="https://www.ucloud.cn/yun/static/theme/ukd/js/common.js"></script>
<<script type="text/javascript">
$(".site-seo-depict *,.site-content-answer-body *,.site-body-depict *").css("max-width","100%");
</script>
</html>