Deployed d0e4df6
with MkDocs version: 1.1.2
This commit is contained in:
parent
50ae3737c1
commit
8cd6f4bd30
24
404.html
24
404.html
|
@ -268,6 +268,30 @@
|
|||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="/user/run_testcase/" title="Run Testcase" class="md-nav__link">
|
||||
Run Testcase
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="/user/testing_report/" title="Testing Report" class="md-nav__link">
|
||||
Testing Report
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
</li>
|
||||
|
|
|
@ -273,6 +273,30 @@
|
|||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../user/run_testcase/" title="Run Testcase" class="md-nav__link">
|
||||
Run Testcase
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../user/testing_report/" title="Testing Report" class="md-nav__link">
|
||||
Testing Report
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
</li>
|
||||
|
|
|
@ -273,6 +273,30 @@
|
|||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../../user/run_testcase/" title="Run Testcase" class="md-nav__link">
|
||||
Run Testcase
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../../user/testing_report/" title="Testing Report" class="md-nav__link">
|
||||
Testing Report
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
</li>
|
||||
|
|
24
index.html
24
index.html
|
@ -329,6 +329,30 @@
|
|||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="user/run_testcase/" title="Run Testcase" class="md-nav__link">
|
||||
Run Testcase
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="user/testing_report/" title="Testing Report" class="md-nav__link">
|
||||
Testing Report
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
</li>
|
||||
|
|
|
@ -318,6 +318,30 @@
|
|||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../user/run_testcase/" title="Run Testcase" class="md-nav__link">
|
||||
Run Testcase
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../user/testing_report/" title="Testing Report" class="md-nav__link">
|
||||
Testing Report
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
</li>
|
||||
|
|
|
@ -273,6 +273,30 @@
|
|||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../user/run_testcase/" title="Run Testcase" class="md-nav__link">
|
||||
Run Testcase
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../user/testing_report/" title="Testing Report" class="md-nav__link">
|
||||
Testing Report
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
</li>
|
||||
|
@ -319,65 +343,6 @@
|
|||
|
||||
|
||||
|
||||
<label class="md-nav__title" for="__toc">
|
||||
<span class="md-nav__icon md-icon">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12z"/></svg>
|
||||
</span>
|
||||
目录
|
||||
</label>
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#write-the-first-test-case" class="md-nav__link">
|
||||
Write the first test case
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#run-test-cases" class="md-nav__link">
|
||||
Run test cases
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#optimize-test-case-correlation" class="md-nav__link">
|
||||
Optimize test case: correlation
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#optimize-test-case-parameterization" class="md-nav__link">
|
||||
Optimize test case: parameterization
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#optimize-test-case-overall-config-block" class="md-nav__link">
|
||||
Optimize test case: overall config block
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#run-test-cases-and-generate-report" class="md-nav__link">
|
||||
Run test cases and generate report
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#further-more" class="md-nav__link">
|
||||
Further more
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -394,260 +359,6 @@
|
|||
|
||||
<h1 id="quick-start">Quick Start<a class="headerlink" href="#quick-start" title="Permanent link">¶</a></h1>
|
||||
<p>First of all, remember HttpRunner is a simple yet powerful HTTP(S) testing framework. This document will help you to learn HttpRunner in 10 minutes.</p>
|
||||
<h2 id="write-the-first-test-case">Write the first test case<a class="headerlink" href="#write-the-first-test-case" title="Permanent link">¶</a></h2>
|
||||
<p>Open your favorite text editor and you can write test cases like this.</p>
|
||||
<div class="codehilite"><pre><span></span><code><span class="p p-Indicator">-</span> <span class="nt">test</span><span class="p">:</span>
|
||||
<span class="nt">name</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">get token</span>
|
||||
<span class="nt">request</span><span class="p">:</span>
|
||||
<span class="nt">url</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">http://127.0.0.1:5000/api/get-token</span>
|
||||
<span class="nt">method</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">POST</span>
|
||||
<span class="nt">headers</span><span class="p">:</span>
|
||||
<span class="nt">user_agent</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">iOS/10.3</span>
|
||||
<span class="nt">device_sn</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">9TN6O2Bn1vzfybF</span>
|
||||
<span class="nt">os_platform</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">ios</span>
|
||||
<span class="nt">app_version</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">2.8.6</span>
|
||||
<span class="nt">json</span><span class="p">:</span>
|
||||
<span class="nt">sign</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">19067cf712265eb5426db8d3664026c1ccea02b9</span>
|
||||
|
||||
<span class="p p-Indicator">-</span> <span class="nt">test</span><span class="p">:</span>
|
||||
<span class="nt">name</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">create user which does not exist</span>
|
||||
<span class="nt">request</span><span class="p">:</span>
|
||||
<span class="nt">url</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">http://127.0.0.1:5000/api/users/1000</span>
|
||||
<span class="nt">method</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">POST</span>
|
||||
<span class="nt">headers</span><span class="p">:</span>
|
||||
<span class="nt">device_sn</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">9TN6O2Bn1vzfybF</span>
|
||||
<span class="nt">token</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">F8prvGryC5beBr4g</span>
|
||||
<span class="nt">json</span><span class="p">:</span>
|
||||
<span class="nt">name</span><span class="p">:</span> <span class="s">"user1"</span>
|
||||
<span class="nt">password</span><span class="p">:</span> <span class="s">"123456"</span>
|
||||
<span class="nt">validate</span><span class="p">:</span>
|
||||
<span class="p p-Indicator">-</span> <span class="p p-Indicator">{</span><span class="s">"check"</span><span class="p p-Indicator">:</span> <span class="s">"status_code"</span><span class="p p-Indicator">,</span> <span class="s">"comparator"</span><span class="p p-Indicator">:</span> <span class="s">"eq"</span><span class="p p-Indicator">,</span> <span class="s">"expect"</span><span class="p p-Indicator">:</span> <span class="nv">201</span><span class="p p-Indicator">}</span>
|
||||
<span class="p p-Indicator">-</span> <span class="p p-Indicator">{</span><span class="s">"check"</span><span class="p p-Indicator">:</span> <span class="s">"content.success"</span><span class="p p-Indicator">,</span> <span class="s">"comparator"</span><span class="p p-Indicator">:</span> <span class="s">"eq"</span><span class="p p-Indicator">,</span> <span class="s">"expect"</span><span class="p p-Indicator">:</span> <span class="nv">true</span><span class="p p-Indicator">}</span>
|
||||
</code></pre></div>
|
||||
|
||||
|
||||
<p>As you see, each API request is described in a <code>test</code> block. And in the <code>request</code> field, it describes the detail of HTTP request, includes url, method, headers and data, which are in line with the captured traffic.</p>
|
||||
<p>You may wonder why we use the <code>json</code> field other than <code>data</code>. That's because the post data is in <code>JSON</code> format, when we use <code>json</code> to indicate the post data, we do not have to specify <code>Content-Type</code> to be <code>application/json</code> in request headers or dump data before request.</p>
|
||||
<p>Have you recalled some familiar scenes?</p>
|
||||
<p>Yes! That's what we did in <a href="requests.request"><code>requests.request</code></a>! Since <code>HttpRunner</code> takes full reuse of <a href="http://docs.python-requests.org/en/master/"><code>Requests</code></a>, it inherits all powerful features of <a href="http://docs.python-requests.org/en/master/"><code>Requests</code></a>, and we can handle HTTP request as the way we do before.</p>
|
||||
<h2 id="run-test-cases">Run test cases<a class="headerlink" href="#run-test-cases" title="Permanent link">¶</a></h2>
|
||||
<p>Suppose the test case file is named as <a href="../examples/quickstart-demo-rev-0.yml"><code>quickstart-demo-rev-0.yml</code></a> and is located in <code>examples</code> folder, then we can run it in this way.</p>
|
||||
<div class="codehilite"><pre><span></span><code>ate examples/demo-rev-0.yml
|
||||
Running tests...
|
||||
----------------------------------------------------------------------
|
||||
get token ... INFO:root: Start to POST http://127.0.0.1:5000/api/get-token
|
||||
INFO:root: status_code: 200, response_time: 48 ms, response_length: 46 bytes
|
||||
OK (0.049669)s
|
||||
create user which does not exist ... INFO:root: Start to POST http://127.0.0.1:5000/api/users/1000
|
||||
ERROR:root: Failed to POST http://127.0.0.1:5000/api/users/1000! exception msg: 403 Client Error: FORBIDDEN for url: http://127.0.0.1:5000/api/users/1000
|
||||
ERROR (0.006471)s
|
||||
----------------------------------------------------------------------
|
||||
Ran 2 tests in 0.056s
|
||||
|
||||
FAILED
|
||||
(Errors=1)
|
||||
</code></pre></div>
|
||||
|
||||
|
||||
<p>Oops! The second test case failed with 403 status code.</p>
|
||||
<p>That is because we request with the same data as we captured in <code>Charles Proxy</code>, while the <code>token</code> is generated dynamically, thus the recorded data can not be be used twice directly.</p>
|
||||
<h2 id="optimize-test-case-correlation">Optimize test case: correlation<a class="headerlink" href="#optimize-test-case-correlation" title="Permanent link">¶</a></h2>
|
||||
<p>To fix this problem, we should correlate <code>token</code> field in the second API test case, which is also called <code>correlation</code>.</p>
|
||||
<div class="codehilite"><pre><span></span><code><span class="p p-Indicator">-</span> <span class="nt">test</span><span class="p">:</span>
|
||||
<span class="nt">name</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">get token</span>
|
||||
<span class="nt">request</span><span class="p">:</span>
|
||||
<span class="nt">url</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">http://127.0.0.1:5000/api/get-token</span>
|
||||
<span class="nt">method</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">POST</span>
|
||||
<span class="nt">headers</span><span class="p">:</span>
|
||||
<span class="nt">user_agent</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">iOS/10.3</span>
|
||||
<span class="nt">device_sn</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">9TN6O2Bn1vzfybF</span>
|
||||
<span class="nt">os_platform</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">ios</span>
|
||||
<span class="nt">app_version</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">2.8.6</span>
|
||||
<span class="nt">json</span><span class="p">:</span>
|
||||
<span class="nt">sign</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">19067cf712265eb5426db8d3664026c1ccea02b9</span>
|
||||
<span class="nt">extract</span><span class="p">:</span>
|
||||
<span class="p p-Indicator">-</span> <span class="nt">token</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">content.token</span>
|
||||
<span class="nt">validate</span><span class="p">:</span>
|
||||
<span class="p p-Indicator">-</span> <span class="p p-Indicator">{</span><span class="s">"check"</span><span class="p p-Indicator">:</span> <span class="s">"status_code"</span><span class="p p-Indicator">,</span> <span class="s">"comparator"</span><span class="p p-Indicator">:</span> <span class="s">"eq"</span><span class="p p-Indicator">,</span> <span class="s">"expect"</span><span class="p p-Indicator">:</span> <span class="nv">200</span><span class="p p-Indicator">}</span>
|
||||
<span class="p p-Indicator">-</span> <span class="p p-Indicator">{</span><span class="s">"check"</span><span class="p p-Indicator">:</span> <span class="s">"content.token"</span><span class="p p-Indicator">,</span> <span class="s">"comparator"</span><span class="p p-Indicator">:</span> <span class="s">"len_eq"</span><span class="p p-Indicator">,</span> <span class="s">"expect"</span><span class="p p-Indicator">:</span> <span class="nv">16</span><span class="p p-Indicator">}</span>
|
||||
|
||||
<span class="p p-Indicator">-</span> <span class="nt">test</span><span class="p">:</span>
|
||||
<span class="nt">name</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">create user which does not exist</span>
|
||||
<span class="nt">request</span><span class="p">:</span>
|
||||
<span class="nt">url</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">http://127.0.0.1:5000/api/users/1000</span>
|
||||
<span class="nt">method</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">POST</span>
|
||||
<span class="nt">headers</span><span class="p">:</span>
|
||||
<span class="nt">device_sn</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">9TN6O2Bn1vzfybF</span>
|
||||
<span class="nt">token</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">$token</span>
|
||||
<span class="nt">json</span><span class="p">:</span>
|
||||
<span class="nt">name</span><span class="p">:</span> <span class="s">"user1"</span>
|
||||
<span class="nt">password</span><span class="p">:</span> <span class="s">"123456"</span>
|
||||
<span class="nt">validate</span><span class="p">:</span>
|
||||
<span class="p p-Indicator">-</span> <span class="p p-Indicator">{</span><span class="s">"check"</span><span class="p p-Indicator">:</span> <span class="s">"status_code"</span><span class="p p-Indicator">,</span> <span class="s">"comparator"</span><span class="p p-Indicator">:</span> <span class="s">"eq"</span><span class="p p-Indicator">,</span> <span class="s">"expect"</span><span class="p p-Indicator">:</span> <span class="nv">201</span><span class="p p-Indicator">}</span>
|
||||
<span class="p p-Indicator">-</span> <span class="p p-Indicator">{</span><span class="s">"check"</span><span class="p p-Indicator">:</span> <span class="s">"content.success"</span><span class="p p-Indicator">,</span> <span class="s">"comparator"</span><span class="p p-Indicator">:</span> <span class="s">"eq"</span><span class="p p-Indicator">,</span> <span class="s">"expect"</span><span class="p p-Indicator">:</span> <span class="nv">true</span><span class="p p-Indicator">}</span>
|
||||
</code></pre></div>
|
||||
|
||||
|
||||
<p>As you see, the <code>token</code> field is no longer hardcoded, instead it is extracted from the first API request with <code>extract</code> mechanism. In the meanwhile, it is assigned to <code>token</code> variable, which can be referenced by the subsequent API requests.</p>
|
||||
<p>Now we save the test cases to <a href="../examples/quickstart-demo-rev-1.yml"><code>quickstart-demo-rev-1.yml</code></a> and rerun it, and we will find that both API requests to be successful.</p>
|
||||
<h2 id="optimize-test-case-parameterization">Optimize test case: parameterization<a class="headerlink" href="#optimize-test-case-parameterization" title="Permanent link">¶</a></h2>
|
||||
<p>Let's look back to our test set <code>quickstart-demo-rev-1.yml</code>, and we can see the <code>device_sn</code> field is still hardcoded. This may be quite different from the actual scenarios.</p>
|
||||
<p>In actual scenarios, each user's <code>device_sn</code> is different, so we should parameterize the request parameters, which is also called <code>parameterization</code>. In the meanwhile, the <code>sign</code> field is calculated with other header fields, thus it may change significantly if any header field changes slightly.</p>
|
||||
<p>However, the test cases are only <code>YAML</code> documents, it is impossible to generate parameters dynamically in such text. Fortunately, we can combine <code>Python</code> scripts with <code>YAML/JSON</code> test cases in <code>HttpRunner</code>.</p>
|
||||
<p>To achieve this goal, we can utilize <code>debugtalk.py</code> plugin and <code>variables</code> mechanisms.</p>
|
||||
<p>To be specific, we can create a Python file (<code>examples/debugtalk.py</code>) and implement the related algorithm in it. The <code>debugtalk.py</code> file can not only be located beside <code>YAML/JSON</code> testcase file, but also can be in any upward recursive folder. Since we want <code>debugtalk.py</code> to be importable, we should put a <code>__init__.py</code> in its folder to make it as a Python module.</p>
|
||||
<div class="codehilite"><pre><span></span><code><span class="kn">import</span> <span class="nn">hashlib</span>
|
||||
<span class="kn">import</span> <span class="nn">hmac</span>
|
||||
<span class="kn">import</span> <span class="nn">random</span>
|
||||
<span class="kn">import</span> <span class="nn">string</span>
|
||||
|
||||
<span class="n">SECRET_KEY</span> <span class="o">=</span> <span class="s2">"DebugTalk"</span>
|
||||
|
||||
<span class="k">def</span> <span class="nf">get_sign</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">):</span>
|
||||
<span class="n">content</span> <span class="o">=</span> <span class="s1">''</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">args</span><span class="p">)</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s1">'ascii'</span><span class="p">)</span>
|
||||
<span class="n">sign_key</span> <span class="o">=</span> <span class="n">SECRET_KEY</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s1">'ascii'</span><span class="p">)</span>
|
||||
<span class="n">sign</span> <span class="o">=</span> <span class="n">hmac</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="n">sign_key</span><span class="p">,</span> <span class="n">content</span><span class="p">,</span> <span class="n">hashlib</span><span class="o">.</span><span class="n">sha1</span><span class="p">)</span><span class="o">.</span><span class="n">hexdigest</span><span class="p">()</span>
|
||||
<span class="k">return</span> <span class="n">sign</span>
|
||||
|
||||
<span class="k">def</span> <span class="nf">gen_random_string</span><span class="p">(</span><span class="n">str_len</span><span class="p">):</span>
|
||||
<span class="n">random_char_list</span> <span class="o">=</span> <span class="p">[]</span>
|
||||
<span class="k">for</span> <span class="n">_</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">str_len</span><span class="p">):</span>
|
||||
<span class="n">random_char</span> <span class="o">=</span> <span class="n">random</span><span class="o">.</span><span class="n">choice</span><span class="p">(</span><span class="n">string</span><span class="o">.</span><span class="n">ascii_letters</span> <span class="o">+</span> <span class="n">string</span><span class="o">.</span><span class="n">digits</span><span class="p">)</span>
|
||||
<span class="n">random_char_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">random_char</span><span class="p">)</span>
|
||||
|
||||
<span class="n">random_string</span> <span class="o">=</span> <span class="s1">''</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">random_char_list</span><span class="p">)</span>
|
||||
<span class="k">return</span> <span class="n">random_string</span>
|
||||
</code></pre></div>
|
||||
|
||||
|
||||
<p>And then, we can revise our demo test case and reference the functions. Suppose the revised file named <a href="../examples/quickstart-demo-rev-2.yml"><code>quickstart-demo-rev-2.yml</code></a>.</p>
|
||||
<div class="codehilite"><pre><span></span><code><span class="p p-Indicator">-</span> <span class="nt">test</span><span class="p">:</span>
|
||||
<span class="nt">name</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">get token</span>
|
||||
<span class="nt">variables</span><span class="p">:</span>
|
||||
<span class="p p-Indicator">-</span> <span class="nt">user_agent</span><span class="p">:</span> <span class="s">'iOS/10.3'</span>
|
||||
<span class="p p-Indicator">-</span> <span class="nt">device_sn</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">${gen_random_string(15)}</span>
|
||||
<span class="p p-Indicator">-</span> <span class="nt">os_platform</span><span class="p">:</span> <span class="s">'ios'</span>
|
||||
<span class="p p-Indicator">-</span> <span class="nt">app_version</span><span class="p">:</span> <span class="s">'2.8.6'</span>
|
||||
<span class="nt">request</span><span class="p">:</span>
|
||||
<span class="nt">url</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">http://127.0.0.1:5000/api/get-token</span>
|
||||
<span class="nt">method</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">POST</span>
|
||||
<span class="nt">headers</span><span class="p">:</span>
|
||||
<span class="nt">user_agent</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">$user_agent</span>
|
||||
<span class="nt">device_sn</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">$device_sn</span>
|
||||
<span class="nt">os_platform</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">$os_platform</span>
|
||||
<span class="nt">app_version</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">$app_version</span>
|
||||
<span class="nt">json</span><span class="p">:</span>
|
||||
<span class="nt">sign</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">${get_sign($user_agent, $device_sn, $os_platform, $app_version)}</span>
|
||||
<span class="nt">extract</span><span class="p">:</span>
|
||||
<span class="p p-Indicator">-</span> <span class="nt">token</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">content.token</span>
|
||||
<span class="nt">validate</span><span class="p">:</span>
|
||||
<span class="p p-Indicator">-</span> <span class="p p-Indicator">{</span><span class="s">"check"</span><span class="p p-Indicator">:</span> <span class="s">"status_code"</span><span class="p p-Indicator">,</span> <span class="s">"comparator"</span><span class="p p-Indicator">:</span> <span class="s">"eq"</span><span class="p p-Indicator">,</span> <span class="s">"expect"</span><span class="p p-Indicator">:</span> <span class="nv">200</span><span class="p p-Indicator">}</span>
|
||||
<span class="p p-Indicator">-</span> <span class="p p-Indicator">{</span><span class="s">"check"</span><span class="p p-Indicator">:</span> <span class="s">"content.token"</span><span class="p p-Indicator">,</span> <span class="s">"comparator"</span><span class="p p-Indicator">:</span> <span class="s">"len_eq"</span><span class="p p-Indicator">,</span> <span class="s">"expect"</span><span class="p p-Indicator">:</span> <span class="nv">16</span><span class="p p-Indicator">}</span>
|
||||
|
||||
<span class="p p-Indicator">-</span> <span class="nt">test</span><span class="p">:</span>
|
||||
<span class="nt">name</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">create user which does not exist</span>
|
||||
<span class="nt">request</span><span class="p">:</span>
|
||||
<span class="nt">url</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">http://127.0.0.1:5000/api/users/1000</span>
|
||||
<span class="nt">method</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">POST</span>
|
||||
<span class="nt">headers</span><span class="p">:</span>
|
||||
<span class="nt">device_sn</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">$device_sn</span>
|
||||
<span class="nt">token</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">$token</span>
|
||||
<span class="nt">json</span><span class="p">:</span>
|
||||
<span class="nt">name</span><span class="p">:</span> <span class="s">"user1"</span>
|
||||
<span class="nt">password</span><span class="p">:</span> <span class="s">"123456"</span>
|
||||
<span class="nt">validate</span><span class="p">:</span>
|
||||
<span class="p p-Indicator">-</span> <span class="p p-Indicator">{</span><span class="s">"check"</span><span class="p p-Indicator">:</span> <span class="s">"status_code"</span><span class="p p-Indicator">,</span> <span class="s">"comparator"</span><span class="p p-Indicator">:</span> <span class="s">"eq"</span><span class="p p-Indicator">,</span> <span class="s">"expect"</span><span class="p p-Indicator">:</span> <span class="nv">201</span><span class="p p-Indicator">}</span>
|
||||
<span class="p p-Indicator">-</span> <span class="p p-Indicator">{</span><span class="s">"check"</span><span class="p p-Indicator">:</span> <span class="s">"content.success"</span><span class="p p-Indicator">,</span> <span class="s">"comparator"</span><span class="p p-Indicator">:</span> <span class="s">"eq"</span><span class="p p-Indicator">,</span> <span class="s">"expect"</span><span class="p p-Indicator">:</span> <span class="nv">true</span><span class="p p-Indicator">}</span>
|
||||
</code></pre></div>
|
||||
|
||||
|
||||
<p>In this revised test case, <code>variable reference</code> and <code>function invoke</code> mechanisms are both used.</p>
|
||||
<p>To make fields like <code>device_sn</code> can be used more than once, we bind values to variables in <code>variables</code> block. When we bind variables, we can not only bind exact value to a variable name, but also can call a function and bind the evaluated value to it.</p>
|
||||
<p>When we want to reference a variable in the test case, we can do this with a escape character <code>$</code>. For example, <code>$user_agent</code> will not be taken as a normal string, and <code>HttpRunner</code> will consider it as a variable named <code>user_agent</code>, search and return its binding value.</p>
|
||||
<p>When we want to reference a function, we shall use another escape character <code>${}</code>. Any content in <code>${}</code> will be considered as function calling, so we should guarantee that we call functions in the right way. At the same time, variables can also be referenced as parameters of function.</p>
|
||||
<h2 id="optimize-test-case-overall-config-block">Optimize test case: overall config block<a class="headerlink" href="#optimize-test-case-overall-config-block" title="Permanent link">¶</a></h2>
|
||||
<p>There is still one issue unsolved.</p>
|
||||
<p>The <code>device_sn</code> field is defined in the first API test case, thus it may be impossible to reference it in other test cases. Context separation is a well-designed mechanism, and we should obey this good practice.</p>
|
||||
<p>To handle this case, overall <code>config</code> block is supported in <code>HttpRunner</code>. If we define variables or import functions in <code>config</code> block, these variables and functions will become global and can be referenced in the whole test set.</p>
|
||||
<div class="codehilite"><pre><span></span><code><span class="c1"># examples/quickstart-demo-rev-3.yml</span>
|
||||
<span class="p p-Indicator">-</span> <span class="nt">config</span><span class="p">:</span>
|
||||
<span class="nt">name</span><span class="p">:</span> <span class="s">"smoketest</span><span class="nv"> </span><span class="s">for</span><span class="nv"> </span><span class="s">CRUD</span><span class="nv"> </span><span class="s">users."</span>
|
||||
<span class="nt">variables</span><span class="p">:</span>
|
||||
<span class="p p-Indicator">-</span> <span class="nt">device_sn</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">${gen_random_string(15)}</span>
|
||||
<span class="nt">request</span><span class="p">:</span>
|
||||
<span class="nt">base_url</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">http://127.0.0.1:5000</span>
|
||||
<span class="nt">headers</span><span class="p">:</span>
|
||||
<span class="nt">device_sn</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">$device_sn</span>
|
||||
|
||||
<span class="p p-Indicator">-</span> <span class="nt">test</span><span class="p">:</span>
|
||||
<span class="nt">name</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">get token</span>
|
||||
<span class="nt">variables</span><span class="p">:</span>
|
||||
<span class="p p-Indicator">-</span> <span class="nt">user_agent</span><span class="p">:</span> <span class="s">'iOS/10.3'</span>
|
||||
<span class="p p-Indicator">-</span> <span class="nt">os_platform</span><span class="p">:</span> <span class="s">'ios'</span>
|
||||
<span class="p p-Indicator">-</span> <span class="nt">app_version</span><span class="p">:</span> <span class="s">'2.8.6'</span>
|
||||
<span class="nt">request</span><span class="p">:</span>
|
||||
<span class="nt">url</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">/api/get-token</span>
|
||||
<span class="nt">method</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">POST</span>
|
||||
<span class="nt">headers</span><span class="p">:</span>
|
||||
<span class="nt">user_agent</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">$user_agent</span>
|
||||
<span class="nt">os_platform</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">$os_platform</span>
|
||||
<span class="nt">app_version</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">$app_version</span>
|
||||
<span class="nt">json</span><span class="p">:</span>
|
||||
<span class="nt">sign</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">${get_sign($user_agent, $device_sn, $os_platform, $app_version)}</span>
|
||||
<span class="nt">extract</span><span class="p">:</span>
|
||||
<span class="p p-Indicator">-</span> <span class="nt">token</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">content.token</span>
|
||||
<span class="nt">validate</span><span class="p">:</span>
|
||||
<span class="p p-Indicator">-</span> <span class="p p-Indicator">{</span><span class="s">"check"</span><span class="p p-Indicator">:</span> <span class="s">"status_code"</span><span class="p p-Indicator">,</span> <span class="s">"comparator"</span><span class="p p-Indicator">:</span> <span class="s">"eq"</span><span class="p p-Indicator">,</span> <span class="s">"expect"</span><span class="p p-Indicator">:</span> <span class="nv">200</span><span class="p p-Indicator">}</span>
|
||||
<span class="p p-Indicator">-</span> <span class="p p-Indicator">{</span><span class="s">"check"</span><span class="p p-Indicator">:</span> <span class="s">"content.token"</span><span class="p p-Indicator">,</span> <span class="s">"comparator"</span><span class="p p-Indicator">:</span> <span class="s">"len_eq"</span><span class="p p-Indicator">,</span> <span class="s">"expect"</span><span class="p p-Indicator">:</span> <span class="nv">16</span><span class="p p-Indicator">}</span>
|
||||
|
||||
<span class="p p-Indicator">-</span> <span class="nt">test</span><span class="p">:</span>
|
||||
<span class="nt">name</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">create user which does not exist</span>
|
||||
<span class="nt">request</span><span class="p">:</span>
|
||||
<span class="nt">url</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">/api/users/1000</span>
|
||||
<span class="nt">method</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">POST</span>
|
||||
<span class="nt">headers</span><span class="p">:</span>
|
||||
<span class="nt">token</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">$token</span>
|
||||
<span class="nt">json</span><span class="p">:</span>
|
||||
<span class="nt">name</span><span class="p">:</span> <span class="s">"user1"</span>
|
||||
<span class="nt">password</span><span class="p">:</span> <span class="s">"123456"</span>
|
||||
<span class="nt">validate</span><span class="p">:</span>
|
||||
<span class="p p-Indicator">-</span> <span class="p p-Indicator">{</span><span class="s">"check"</span><span class="p p-Indicator">:</span> <span class="s">"status_code"</span><span class="p p-Indicator">,</span> <span class="s">"comparator"</span><span class="p p-Indicator">:</span> <span class="s">"eq"</span><span class="p p-Indicator">,</span> <span class="s">"expect"</span><span class="p p-Indicator">:</span> <span class="nv">201</span><span class="p p-Indicator">}</span>
|
||||
<span class="p p-Indicator">-</span> <span class="p p-Indicator">{</span><span class="s">"check"</span><span class="p p-Indicator">:</span> <span class="s">"content.success"</span><span class="p p-Indicator">,</span> <span class="s">"comparator"</span><span class="p p-Indicator">:</span> <span class="s">"eq"</span><span class="p p-Indicator">,</span> <span class="s">"expect"</span><span class="p p-Indicator">:</span> <span class="nv">true</span><span class="p p-Indicator">}</span>
|
||||
</code></pre></div>
|
||||
|
||||
|
||||
<p>As you see, we define variables in <code>config</code> block. Also, we can set <code>base_url</code> in <code>config</code> block, thereby we can specify relative path in each API request url. Besides, we can also set common fields in <code>config</code> <code>request</code>, such as <code>device_sn</code> in headers.</p>
|
||||
<p>Until now, the test cases are finished and each detail is handled properly.</p>
|
||||
<h2 id="run-test-cases-and-generate-report">Run test cases and generate report<a class="headerlink" href="#run-test-cases-and-generate-report" title="Permanent link">¶</a></h2>
|
||||
<p>Finally, let's run test set <a href="../examples/quickstart-demo-rev-3.yml"><code>quickstart-demo-rev-3.yml</code></a> once more.</p>
|
||||
<div class="codehilite"><pre><span></span><code>$ ate examples/quickstart-demo-rev-4.yml
|
||||
Running tests...
|
||||
----------------------------------------------------------------------
|
||||
get token ... INFO:root: Start to POST http://127.0.0.1:5000/api/get-token
|
||||
INFO:root: status_code: 200, response_time: 33 ms, response_length: 46 bytes
|
||||
OK (0.037027)s
|
||||
create user which does not exist ... INFO:root: Start to POST http://127.0.0.1:5000/api/users/1000
|
||||
INFO:root: status_code: 201, response_time: 15 ms, response_length: 54 bytes
|
||||
OK (0.016414)s
|
||||
----------------------------------------------------------------------
|
||||
Ran 2 tests in 0.054s
|
||||
OK
|
||||
|
||||
Generating HTML reports...
|
||||
Template is not specified, load default template instead.
|
||||
Reports generated: /Users/Leo/MyProjects/HttpRunner/reports/quickstart-demo-rev-0/2017-08-01-16-51-51.html
|
||||
</code></pre></div>
|
||||
|
||||
|
||||
<p>Great! The test case runs successfully and generates a <code>HTML</code> test report.</p>
|
||||
<p><img alt="" src="images/ate-quickstart-demo-report.jpg" /></p>
|
||||
<h2 id="further-more">Further more<a class="headerlink" href="#further-more" title="Permanent link">¶</a></h2>
|
||||
<p>This is just a starting point, see the <code>advanced guide</code> for the advanced features.</p>
|
||||
<ul>
|
||||
<li>templating</li>
|
||||
<li><a href="write-testcases.md#extraction-and-validation"><code>data extraction and validation</code></a></li>
|
||||
<li><a href="write-testcases.md#comparator"><code>comparator</code></a></li>
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
22
sitemap.xml
22
sitemap.xml
|
@ -1,31 +1,39 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><url>
|
||||
<loc>None</loc>
|
||||
<lastmod>2020-06-16</lastmod>
|
||||
<lastmod>2020-06-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>None</loc>
|
||||
<lastmod>2020-06-16</lastmod>
|
||||
<lastmod>2020-06-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>None</loc>
|
||||
<lastmod>2020-06-16</lastmod>
|
||||
<lastmod>2020-06-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>None</loc>
|
||||
<lastmod>2020-06-16</lastmod>
|
||||
<lastmod>2020-06-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>None</loc>
|
||||
<lastmod>2020-06-16</lastmod>
|
||||
<lastmod>2020-06-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>None</loc>
|
||||
<lastmod>2020-06-16</lastmod>
|
||||
<lastmod>2020-06-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>None</loc>
|
||||
<lastmod>2020-06-16</lastmod>
|
||||
<lastmod>2020-06-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>None</loc>
|
||||
<lastmod>2020-06-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>None</loc>
|
||||
<lastmod>2020-06-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
</urlset>
|
BIN
sitemap.xml.gz
BIN
sitemap.xml.gz
Binary file not shown.
|
@ -273,6 +273,30 @@
|
|||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../user/run_testcase/" title="Run Testcase" class="md-nav__link">
|
||||
Run Testcase
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../user/testing_report/" title="Testing Report" class="md-nav__link">
|
||||
Testing Report
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
</li>
|
||||
|
@ -487,7 +511,7 @@
|
|||
<div class="md-footer-nav">
|
||||
<nav class="md-footer-nav__inner md-grid" aria-label="Footer">
|
||||
|
||||
<a href="../user/write_testcase/" title="Write Testcase" class="md-footer-nav__link md-footer-nav__link--prev" rel="prev">
|
||||
<a href="../user/testing_report/" title="Testing Report" class="md-footer-nav__link md-footer-nav__link--prev" rel="prev">
|
||||
<div class="md-footer-nav__button md-icon">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12z"/></svg>
|
||||
</div>
|
||||
|
@ -496,7 +520,7 @@
|
|||
<span class="md-footer-nav__direction">
|
||||
上一页
|
||||
</span>
|
||||
Write Testcase
|
||||
Testing Report
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
|
|
|
@ -358,6 +358,30 @@
|
|||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../run_testcase/" title="Run Testcase" class="md-nav__link">
|
||||
Run Testcase
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../testing_report/" title="Testing Report" class="md-nav__link">
|
||||
Testing Report
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
</li>
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -331,6 +331,30 @@
|
|||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../run_testcase/" title="Run Testcase" class="md-nav__link">
|
||||
Run Testcase
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../testing_report/" title="Testing Report" class="md-nav__link">
|
||||
Testing Report
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
</li>
|
||||
|
|
|
@ -0,0 +1,585 @@
|
|||
|
||||
|
||||
|
||||
<!doctype html>
|
||||
<html lang="zh" class="no-js">
|
||||
<head>
|
||||
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
|
||||
<meta name="description" content="HttpRunner V3.x User Documentation">
|
||||
|
||||
|
||||
|
||||
<meta name="author" content="debugtalk">
|
||||
|
||||
<link rel="shortcut icon" href="../../assets/images/favicon.png">
|
||||
<meta name="generator" content="mkdocs-1.1.2, mkdocs-material-5.2.2">
|
||||
|
||||
|
||||
|
||||
<title>Testing Report - HttpRunner V3.x Docs</title>
|
||||
|
||||
|
||||
|
||||
<link rel="stylesheet" href="../../assets/stylesheets/main.a2408e81.min.css">
|
||||
|
||||
<link rel="stylesheet" href="../../assets/stylesheets/palette.a46bcfb3.min.css">
|
||||
|
||||
|
||||
|
||||
|
||||
<meta name="theme-color" content="#3f51b5">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<link href="https://fonts.gstatic.com" rel="preconnect" crossorigin>
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,400i,700%7CRoboto+Mono&display=fallback">
|
||||
<style>body,input{font-family:"Roboto",-apple-system,BlinkMacSystemFont,Helvetica,Arial,sans-serif}code,kbd,pre{font-family:"Roboto Mono",SFMono-Regular,Consolas,Menlo,monospace}</style>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<link rel="preconnect dns-prefetch" href="https://www.google-analytics.com">
|
||||
<script>window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)},ga.l=+new Date,ga("create","UA-114587036-3","auto"),ga("set","anonymizeIp",!0),ga("send","pageview"),document.addEventListener("DOMContentLoaded",function(){document.forms.search&&document.forms.search.query.addEventListener("blur",function(){if(this.value){var e=document.location.pathname;ga("send","pageview",e+"?q="+this.value)}})}),document.addEventListener("DOMContentSwitch",function(){ga("send","pageview")})</script>
|
||||
<script async src="https://www.google-analytics.com/analytics.js"></script>
|
||||
|
||||
|
||||
|
||||
</head>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<body dir="ltr" data-md-color-scheme="" data-md-color-primary="indigo" data-md-color-accent="indigo">
|
||||
|
||||
<input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
|
||||
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
|
||||
<label class="md-overlay" for="__drawer"></label>
|
||||
<div data-md-component="skip">
|
||||
|
||||
|
||||
<a href="#testing-report" class="md-skip">
|
||||
跳转至
|
||||
</a>
|
||||
|
||||
</div>
|
||||
<div data-md-component="announce">
|
||||
|
||||
</div>
|
||||
|
||||
<header class="md-header" data-md-component="header">
|
||||
<nav class="md-header-nav md-grid" aria-label="Header">
|
||||
<a href="../.." title="HttpRunner V3.x Docs" class="md-header-nav__button md-logo" aria-label="HttpRunner V3.x Docs">
|
||||
|
||||
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 003-3 3 3 0 00-3-3 3 3 0 00-3 3 3 3 0 003 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54z"/></svg>
|
||||
|
||||
</a>
|
||||
<label class="md-header-nav__button md-icon" for="__drawer">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18v2H3V6m0 5h18v2H3v-2m0 5h18v2H3v-2z"/></svg>
|
||||
</label>
|
||||
<div class="md-header-nav__title" data-md-component="header-title">
|
||||
|
||||
<div class="md-header-nav__ellipsis">
|
||||
<span class="md-header-nav__topic md-ellipsis">
|
||||
HttpRunner V3.x Docs
|
||||
</span>
|
||||
<span class="md-header-nav__topic md-ellipsis">
|
||||
|
||||
Testing Report
|
||||
|
||||
</span>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<label class="md-header-nav__button md-icon" for="__search">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0116 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 019.5 16 6.5 6.5 0 013 9.5 6.5 6.5 0 019.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5z"/></svg>
|
||||
</label>
|
||||
|
||||
<div class="md-search" data-md-component="search" role="dialog">
|
||||
<label class="md-search__overlay" for="__search"></label>
|
||||
<div class="md-search__inner" role="search">
|
||||
<form class="md-search__form" name="search">
|
||||
<input type="text" class="md-search__input" name="query" aria-label="搜索" placeholder="搜索" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="search-query" data-md-state="active">
|
||||
<label class="md-search__icon md-icon" for="__search">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0116 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 019.5 16 6.5 6.5 0 013 9.5 6.5 6.5 0 019.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5z"/></svg>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12z"/></svg>
|
||||
</label>
|
||||
<button type="reset" class="md-search__icon md-icon" aria-label="Clear" data-md-component="search-reset" tabindex="-1">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41z"/></svg>
|
||||
</button>
|
||||
</form>
|
||||
<div class="md-search__output">
|
||||
<div class="md-search__scrollwrap" data-md-scrollfix>
|
||||
<div class="md-search-result" data-md-component="search-result">
|
||||
<div class="md-search-result__meta">
|
||||
Initializing search
|
||||
</div>
|
||||
<ol class="md-search-result__list"></ol>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="md-header-nav__source">
|
||||
|
||||
<a href="https://github.com/httprunner/httprunner" title="前往 GitHub 仓库" class="md-source">
|
||||
<div class="md-source__icon md-icon">
|
||||
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><path d="M439.55 236.05L244 40.45a28.87 28.87 0 00-40.81 0l-40.66 40.63 51.52 51.52c27.06-9.14 52.68 16.77 43.39 43.68l49.66 49.66c34.23-11.8 61.18 31 35.47 56.69-26.49 26.49-70.21-2.87-56-37.34L240.22 199v121.85c25.3 12.54 22.26 41.85 9.08 55a34.34 34.34 0 01-48.55 0c-17.57-17.6-11.07-46.91 11.25-56v-123c-20.8-8.51-24.6-30.74-18.64-45L142.57 101 8.45 235.14a28.86 28.86 0 000 40.81l195.61 195.6a28.86 28.86 0 0040.8 0l194.69-194.69a28.86 28.86 0 000-40.81z"/></svg>
|
||||
</div>
|
||||
<div class="md-source__repository">
|
||||
HttpRunner
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
<div class="md-container" data-md-component="container">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<main class="md-main" data-md-component="main">
|
||||
<div class="md-main__inner md-grid">
|
||||
|
||||
|
||||
<div class="md-sidebar md-sidebar--primary" data-md-component="navigation">
|
||||
<div class="md-sidebar__scrollwrap">
|
||||
<div class="md-sidebar__inner">
|
||||
<nav class="md-nav md-nav--primary" aria-label="Navigation" data-md-level="0">
|
||||
<label class="md-nav__title" for="__drawer">
|
||||
<a href="../.." title="HttpRunner V3.x Docs" class="md-nav__button md-logo" aria-label="HttpRunner V3.x Docs">
|
||||
|
||||
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 003-3 3 3 0 00-3-3 3 3 0 00-3 3 3 3 0 003 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54z"/></svg>
|
||||
|
||||
</a>
|
||||
HttpRunner V3.x Docs
|
||||
</label>
|
||||
|
||||
<div class="md-nav__source">
|
||||
|
||||
<a href="https://github.com/httprunner/httprunner" title="前往 GitHub 仓库" class="md-source">
|
||||
<div class="md-source__icon md-icon">
|
||||
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><path d="M439.55 236.05L244 40.45a28.87 28.87 0 00-40.81 0l-40.66 40.63 51.52 51.52c27.06-9.14 52.68 16.77 43.39 43.68l49.66 49.66c34.23-11.8 61.18 31 35.47 56.69-26.49 26.49-70.21-2.87-56-37.34L240.22 199v121.85c25.3 12.54 22.26 41.85 9.08 55a34.34 34.34 0 01-48.55 0c-17.57-17.6-11.07-46.91 11.25-56v-123c-20.8-8.51-24.6-30.74-18.64-45L142.57 101 8.45 235.14a28.86 28.86 0 000 40.81l195.61 195.6a28.86 28.86 0 0040.8 0l194.69-194.69a28.86 28.86 0 000-40.81z"/></svg>
|
||||
</div>
|
||||
<div class="md-source__repository">
|
||||
HttpRunner
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../.." title="Introduction" class="md-nav__link">
|
||||
Introduction
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../../installation/" title="Installation" class="md-nav__link">
|
||||
Installation
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item md-nav__item--active md-nav__item--nested">
|
||||
|
||||
<input class="md-nav__toggle md-toggle" data-md-toggle="nav-3" type="checkbox" id="nav-3" checked>
|
||||
|
||||
<label class="md-nav__link" for="nav-3">
|
||||
User Guide
|
||||
<span class="md-nav__icon md-icon">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M8.59 16.58L13.17 12 8.59 7.41 10 6l6 6-6 6-1.41-1.42z"/></svg>
|
||||
</span>
|
||||
</label>
|
||||
<nav class="md-nav" aria-label="User Guide" data-md-level="1">
|
||||
<label class="md-nav__title" for="nav-3">
|
||||
<span class="md-nav__icon md-icon">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12z"/></svg>
|
||||
</span>
|
||||
User Guide
|
||||
</label>
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../scaffold/" title="Scaffold" class="md-nav__link">
|
||||
Scaffold
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../gen_tests/" title="Record & Generate testcase" class="md-nav__link">
|
||||
Record & Generate testcase
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../write_testcase/" title="Write Testcase" class="md-nav__link">
|
||||
Write Testcase
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../run_testcase/" title="Run Testcase" class="md-nav__link">
|
||||
Run Testcase
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item md-nav__item--active">
|
||||
|
||||
<input class="md-nav__toggle md-toggle" data-md-toggle="toc" type="checkbox" id="__toc">
|
||||
|
||||
|
||||
|
||||
|
||||
<label class="md-nav__link md-nav__link--active" for="__toc">
|
||||
Testing Report
|
||||
<span class="md-nav__icon md-icon">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 9h14V7H3v2m0 4h14v-2H3v2m0 4h14v-2H3v2m16 0h2v-2h-2v2m0-10v2h2V7h-2m0 6h2v-2h-2v2z"/></svg>
|
||||
</span>
|
||||
</label>
|
||||
|
||||
<a href="./" title="Testing Report" class="md-nav__link md-nav__link--active">
|
||||
Testing Report
|
||||
</a>
|
||||
|
||||
|
||||
<nav class="md-nav md-nav--secondary" aria-label="目录">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<label class="md-nav__title" for="__toc">
|
||||
<span class="md-nav__icon md-icon">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12z"/></svg>
|
||||
</span>
|
||||
目录
|
||||
</label>
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#builtin-html-report" class="md-nav__link">
|
||||
builtin html report
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#allure-report" class="md-nav__link">
|
||||
allure report
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
||||
</nav>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../../sponsors/" title="Sponsors" class="md-nav__link">
|
||||
Sponsors
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../../CHANGELOG/" title="CHANGELOG" class="md-nav__link">
|
||||
CHANGELOG
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="md-sidebar md-sidebar--secondary" data-md-component="toc">
|
||||
<div class="md-sidebar__scrollwrap">
|
||||
<div class="md-sidebar__inner">
|
||||
|
||||
<nav class="md-nav md-nav--secondary" aria-label="目录">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<label class="md-nav__title" for="__toc">
|
||||
<span class="md-nav__icon md-icon">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12z"/></svg>
|
||||
</span>
|
||||
目录
|
||||
</label>
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#builtin-html-report" class="md-nav__link">
|
||||
builtin html report
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#allure-report" class="md-nav__link">
|
||||
allure report
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="md-content">
|
||||
<article class="md-content__inner md-typeset">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h1 id="testing-report">Testing Report<a class="headerlink" href="#testing-report" title="Permanent link">¶</a></h1>
|
||||
<p>Benefit from the integration of <code>pytest</code>, HttpRunner v3.x can make use of all the pytest plugins, including testing report plugins like <code>pytest-html</code> and <code>allure-pytest</code>.</p>
|
||||
<h2 id="builtin-html-report">builtin html report<a class="headerlink" href="#builtin-html-report" title="Permanent link">¶</a></h2>
|
||||
<p><code>pytest-html</code> plugin comes with HttpRunner installation. When you want to generate a html report for testcase execution, you can add a command argument <code>--html</code>.</p>
|
||||
<div class="codehilite"><pre><span></span><code>$ hrun /path/to/testcase --html=report.html
|
||||
</code></pre></div>
|
||||
|
||||
|
||||
<p>If you want to create a self-contained report, which is a single HTML file that can be more convenient when sharing results, you can add another command argument <code>--self-contained-html</code>.</p>
|
||||
<div class="codehilite"><pre><span></span><code>$ hrun /path/to/testcase --html=report.html --self-contained-html
|
||||
</code></pre></div>
|
||||
|
||||
|
||||
<p>You can refer to <a href="https://pypi.org/project/pytest-html/"><code>pytest-html</code></a> for more details.</p>
|
||||
<h2 id="allure-report">allure report<a class="headerlink" href="#allure-report" title="Permanent link">¶</a></h2>
|
||||
<p><code>allure-pytest</code> is an optional dependency for HttpRunner, thus if you want to generate allure report, you should install <code>allure-pytest</code> plugin separately.</p>
|
||||
<div class="codehilite"><pre><span></span><code>$ pip3 install "allure-pytest"
|
||||
</code></pre></div>
|
||||
|
||||
|
||||
<p>Or you can install HttpRunner with allure extra package.</p>
|
||||
<div class="codehilite"><pre><span></span><code>$ pip3 install "httprunner[allure]"
|
||||
</code></pre></div>
|
||||
|
||||
|
||||
<p>Once <code>allure-pytest</code> is ready, the following arguments can be used with <code>hrun/pytest</code> command.</p>
|
||||
<ul>
|
||||
<li><code>--alluredir=DIR</code>: Generate Allure report in the specified directory (may not exist)</li>
|
||||
<li><code>--clean-alluredir</code>: Clean alluredir folder if it exists</li>
|
||||
<li><code>--allure-no-capture</code>: Do not attach pytest captured logging/stdout/stderr to report</li>
|
||||
</ul>
|
||||
<p>To enable Allure listener to collect results during the test execution simply add <code>--alluredir</code> option and provide path to the folder where results should be stored. E.g.:</p>
|
||||
<div class="codehilite"><pre><span></span><code>$ hrun /path/to/testcase --alluredir=/tmp/my_allure_results
|
||||
</code></pre></div>
|
||||
|
||||
|
||||
<p>To see the actual report after your tests have finished, you need to use Allure commandline utility to generate report from the results.</p>
|
||||
<div class="codehilite"><pre><span></span><code>$ allure serve /tmp/my_allure_results
|
||||
</code></pre></div>
|
||||
|
||||
|
||||
<p>This command will show you generated report in your default browser.</p>
|
||||
<p>You can refer to <a href="https://docs.qameta.io/allure/#_pytest"><code>allure-pytest</code></a> for more details.</p>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</article>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
|
||||
<footer class="md-footer">
|
||||
|
||||
<div class="md-footer-nav">
|
||||
<nav class="md-footer-nav__inner md-grid" aria-label="Footer">
|
||||
|
||||
<a href="../run_testcase/" title="Run Testcase" class="md-footer-nav__link md-footer-nav__link--prev" rel="prev">
|
||||
<div class="md-footer-nav__button md-icon">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12z"/></svg>
|
||||
</div>
|
||||
<div class="md-footer-nav__title">
|
||||
<div class="md-ellipsis">
|
||||
<span class="md-footer-nav__direction">
|
||||
上一页
|
||||
</span>
|
||||
Run Testcase
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
|
||||
<a href="../../sponsors/" title="Sponsors" class="md-footer-nav__link md-footer-nav__link--next" rel="next">
|
||||
<div class="md-footer-nav__title">
|
||||
<div class="md-ellipsis">
|
||||
<span class="md-footer-nav__direction">
|
||||
下一页
|
||||
</span>
|
||||
Sponsors
|
||||
</div>
|
||||
</div>
|
||||
<div class="md-footer-nav__button md-icon">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M4 11v2h12l-5.5 5.5 1.42 1.42L19.84 12l-7.92-7.92L10.5 5.5 16 11H4z"/></svg>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
<div class="md-footer-meta md-typeset">
|
||||
<div class="md-footer-meta__inner md-grid">
|
||||
<div class="md-footer-copyright">
|
||||
|
||||
<div class="md-footer-copyright__highlight">
|
||||
Copyright © 2017 - 2020 debugtalk
|
||||
</div>
|
||||
|
||||
Made with
|
||||
<a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
|
||||
Material for MkDocs
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="md-footer-social">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a href="https://debugtalk.com" target="_blank" rel="noopener" title="debugtalk.com" class="md-footer-social__link">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 003-3 3 3 0 00-3-3 3 3 0 00-3 3 3 3 0 003 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54z"/></svg>
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a href="https://github.com/httprunner" target="_blank" rel="noopener" title="github.com" class="md-footer-social__link">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 480 512"><path d="M186.1 328.7c0 20.9-10.9 55.1-36.7 55.1s-36.7-34.2-36.7-55.1 10.9-55.1 36.7-55.1 36.7 34.2 36.7 55.1zM480 278.2c0 31.9-3.2 65.7-17.5 95-37.9 76.6-142.1 74.8-216.7 74.8-75.8 0-186.2 2.7-225.6-74.8-14.6-29-20.2-63.1-20.2-95 0-41.9 13.9-81.5 41.5-113.6-5.2-15.8-7.7-32.4-7.7-48.8 0-21.5 4.9-32.3 14.6-51.8 45.3 0 74.3 9 108.8 36 29-6.9 58.8-10 88.7-10 27 0 54.2 2.9 80.4 9.2 34-26.7 63-35.2 107.8-35.2 9.8 19.5 14.6 30.3 14.6 51.8 0 16.4-2.6 32.7-7.7 48.2 27.5 32.4 39 72.3 39 114.2zm-64.3 50.5c0-43.9-26.7-82.6-73.5-82.6-18.9 0-37 3.4-56 6-14.9 2.3-29.8 3.2-45.1 3.2-15.2 0-30.1-.9-45.1-3.2-18.7-2.6-37-6-56-6-46.8 0-73.5 38.7-73.5 82.6 0 87.8 80.4 101.3 150.4 101.3h48.2c70.3 0 150.6-13.4 150.6-101.3zm-82.6-55.1c-25.8 0-36.7 34.2-36.7 55.1s10.9 55.1 36.7 55.1 36.7-34.2 36.7-55.1-10.9-55.1-36.7-55.1z"/></svg>
|
||||
</a>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
</div>
|
||||
|
||||
<script src="../../assets/javascripts/vendor.d710d30a.min.js"></script>
|
||||
<script src="../../assets/javascripts/bundle.5f27aba8.min.js"></script><script id="__lang" type="application/json">{"clipboard.copy": "\u590d\u5236", "clipboard.copied": "\u5df2\u590d\u5236", "search.config.lang": "ja", "search.config.pipeline": "trimmer, stopWordFilter", "search.config.separator": "[\\uff0c\\u3002]+", "search.result.placeholder": "\u952e\u5165\u4ee5\u5f00\u59cb\u641c\u7d22", "search.result.none": "\u6ca1\u6709\u627e\u5230\u7b26\u5408\u6761\u4ef6\u7684\u7ed3\u679c", "search.result.one": "\u627e\u5230 1 \u4e2a\u7b26\u5408\u6761\u4ef6\u7684\u7ed3\u679c", "search.result.other": "# \u4e2a\u7b26\u5408\u6761\u4ef6\u7684\u7ed3\u679c"}</script>
|
||||
|
||||
<script>
|
||||
app = initialize({
|
||||
base: "../..",
|
||||
features: [],
|
||||
search: Object.assign({
|
||||
worker: "../../assets/javascripts/worker/search.27c6a5e6.min.js"
|
||||
}, typeof search !== "undefined" && search)
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -495,6 +495,20 @@
|
|||
.with_variables
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#call" class="md-nav__link">
|
||||
.call
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#export" class="md-nav__link">
|
||||
.export
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
@ -514,6 +528,30 @@
|
|||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../run_testcase/" title="Run Testcase" class="md-nav__link">
|
||||
Run Testcase
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../testing_report/" title="Testing Report" class="md-nav__link">
|
||||
Testing Report
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
</li>
|
||||
|
@ -760,6 +798,20 @@
|
|||
.with_variables
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#call" class="md-nav__link">
|
||||
.call
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#export" class="md-nav__link">
|
||||
.export
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
@ -932,6 +984,67 @@
|
|||
<p>The argument <code>name</code> of RunTestCase is used to specify teststep name, which will be displayed in execution log and test report.</p>
|
||||
<h4 id="with_variables_1">.with_variables<a class="headerlink" href="#with_variables_1" title="Permanent link">¶</a></h4>
|
||||
<p>Same with RunRequest's <code>.with_variables</code>.</p>
|
||||
<h4 id="call">.call<a class="headerlink" href="#call" title="Permanent link">¶</a></h4>
|
||||
<p>Specify referenced testcase class.</p>
|
||||
<h4 id="export">.export<a class="headerlink" href="#export" title="Permanent link">¶</a></h4>
|
||||
<p>Specify session variable names to export from referenced testcase. The exported variables can be referenced by subsequent test steps.</p>
|
||||
<div class="codehilite"><pre><span></span><code><span class="kn">import</span> <span class="nn">os</span>
|
||||
<span class="kn">import</span> <span class="nn">sys</span>
|
||||
|
||||
<span class="n">sys</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">insert</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">os</span><span class="o">.</span><span class="n">getcwd</span><span class="p">())</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">httprunner</span> <span class="kn">import</span> <span class="n">HttpRunner</span><span class="p">,</span> <span class="n">Config</span><span class="p">,</span> <span class="n">Step</span><span class="p">,</span> <span class="n">RunRequest</span><span class="p">,</span> <span class="n">RunTestCase</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">examples.postman_echo.request_methods.request_with_functions_test</span> <span class="kn">import</span> <span class="p">(</span>
|
||||
<span class="n">TestCaseRequestWithFunctions</span> <span class="k">as</span> <span class="n">RequestWithFunctions</span><span class="p">,</span>
|
||||
<span class="p">)</span>
|
||||
|
||||
|
||||
<span class="k">class</span> <span class="nc">TestCaseRequestWithTestcaseReference</span><span class="p">(</span><span class="n">HttpRunner</span><span class="p">):</span>
|
||||
<span class="n">config</span> <span class="o">=</span> <span class="p">(</span>
|
||||
<span class="n">Config</span><span class="p">(</span><span class="s2">"request methods testcase: reference testcase"</span><span class="p">)</span>
|
||||
<span class="o">.</span><span class="n">variables</span><span class="p">(</span>
|
||||
<span class="o">**</span><span class="p">{</span>
|
||||
<span class="s2">"foo1"</span><span class="p">:</span> <span class="s2">"testsuite_config_bar1"</span><span class="p">,</span>
|
||||
<span class="s2">"expect_foo1"</span><span class="p">:</span> <span class="s2">"testsuite_config_bar1"</span><span class="p">,</span>
|
||||
<span class="s2">"expect_foo2"</span><span class="p">:</span> <span class="s2">"config_bar2"</span><span class="p">,</span>
|
||||
<span class="p">}</span>
|
||||
<span class="p">)</span>
|
||||
<span class="o">.</span><span class="n">base_url</span><span class="p">(</span><span class="s2">"https://postman-echo.com"</span><span class="p">)</span>
|
||||
<span class="o">.</span><span class="n">verify</span><span class="p">(</span><span class="kc">False</span><span class="p">)</span>
|
||||
<span class="p">)</span>
|
||||
|
||||
<span class="n">teststeps</span> <span class="o">=</span> <span class="p">[</span>
|
||||
<span class="n">Step</span><span class="p">(</span>
|
||||
<span class="n">RunTestCase</span><span class="p">(</span><span class="s2">"request with functions"</span><span class="p">)</span>
|
||||
<span class="o">.</span><span class="n">with_variables</span><span class="p">(</span>
|
||||
<span class="o">**</span><span class="p">{</span><span class="s2">"foo1"</span><span class="p">:</span> <span class="s2">"testcase_ref_bar1"</span><span class="p">,</span> <span class="s2">"expect_foo1"</span><span class="p">:</span> <span class="s2">"testcase_ref_bar1"</span><span class="p">}</span>
|
||||
<span class="p">)</span>
|
||||
<span class="o">.</span><span class="n">call</span><span class="p">(</span><span class="n">RequestWithFunctions</span><span class="p">)</span>
|
||||
<span class="o">.</span><span class="n">export</span><span class="p">(</span><span class="o">*</span><span class="p">[</span><span class="s2">"foo3"</span><span class="p">])</span>
|
||||
<span class="p">),</span>
|
||||
<span class="n">Step</span><span class="p">(</span>
|
||||
<span class="n">RunRequest</span><span class="p">(</span><span class="s2">"post form data"</span><span class="p">)</span>
|
||||
<span class="o">.</span><span class="n">with_variables</span><span class="p">(</span><span class="o">**</span><span class="p">{</span><span class="s2">"foo1"</span><span class="p">:</span> <span class="s2">"bar1"</span><span class="p">})</span>
|
||||
<span class="o">.</span><span class="n">post</span><span class="p">(</span><span class="s2">"/post"</span><span class="p">)</span>
|
||||
<span class="o">.</span><span class="n">with_headers</span><span class="p">(</span>
|
||||
<span class="o">**</span><span class="p">{</span>
|
||||
<span class="s2">"User-Agent"</span><span class="p">:</span> <span class="s2">"HttpRunner/${get_httprunner_version()}"</span><span class="p">,</span>
|
||||
<span class="s2">"Content-Type"</span><span class="p">:</span> <span class="s2">"application/x-www-form-urlencoded"</span><span class="p">,</span>
|
||||
<span class="p">}</span>
|
||||
<span class="p">)</span>
|
||||
<span class="o">.</span><span class="n">with_data</span><span class="p">(</span><span class="s2">"foo1=$foo1&foo2=$foo3"</span><span class="p">)</span>
|
||||
<span class="o">.</span><span class="n">validate</span><span class="p">()</span>
|
||||
<span class="o">.</span><span class="n">assert_equal</span><span class="p">(</span><span class="s2">"status_code"</span><span class="p">,</span> <span class="mi">200</span><span class="p">)</span>
|
||||
<span class="o">.</span><span class="n">assert_equal</span><span class="p">(</span><span class="s2">"body.form.foo1"</span><span class="p">,</span> <span class="s2">"bar1"</span><span class="p">)</span>
|
||||
<span class="o">.</span><span class="n">assert_equal</span><span class="p">(</span><span class="s2">"body.form.foo2"</span><span class="p">,</span> <span class="s2">"bar21"</span><span class="p">)</span>
|
||||
<span class="p">),</span>
|
||||
<span class="p">]</span>
|
||||
|
||||
|
||||
<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s2">"__main__"</span><span class="p">:</span>
|
||||
<span class="n">TestCaseRequestWithTestcaseReference</span><span class="p">()</span><span class="o">.</span><span class="n">test_start</span><span class="p">()</span>
|
||||
</code></pre></div>
|
||||
|
||||
|
||||
|
||||
|
@ -965,13 +1078,13 @@
|
|||
</a>
|
||||
|
||||
|
||||
<a href="../../sponsors/" title="Sponsors" class="md-footer-nav__link md-footer-nav__link--next" rel="next">
|
||||
<a href="../run_testcase/" title="Run Testcase" class="md-footer-nav__link md-footer-nav__link--next" rel="next">
|
||||
<div class="md-footer-nav__title">
|
||||
<div class="md-ellipsis">
|
||||
<span class="md-footer-nav__direction">
|
||||
下一页
|
||||
</span>
|
||||
Sponsors
|
||||
Run Testcase
|
||||
</div>
|
||||
</div>
|
||||
<div class="md-footer-nav__button md-icon">
|
||||
|
|
Loading…
Reference in New Issue