SimpleAPI.html 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. <!DOCTYPE html>
  2. <!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
  3. <!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
  4. <head>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>How to create a simple API Test &mdash; baangt 1.1.1 documentation</title>
  8. <script type="text/javascript" src="_static/js/modernizr.min.js"></script>
  9. <script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
  10. <script type="text/javascript" src="_static/jquery.js"></script>
  11. <script type="text/javascript" src="_static/underscore.js"></script>
  12. <script type="text/javascript" src="_static/doctools.js"></script>
  13. <script type="text/javascript" src="_static/language_data.js"></script>
  14. <script type="text/javascript" src="_static/js/theme.js"></script>
  15. <link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
  16. <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
  17. <link rel="stylesheet" href="_static/theme_overrides.css" type="text/css" />
  18. <link rel="index" title="Index" href="genindex.html" />
  19. <link rel="search" title="Search" href="search.html" />
  20. <link rel="next" title="Types of tests" href="TestTypes.html" />
  21. <link rel="prev" title="Parameters in Configuration files (globals)" href="ParametersConfigFile.html" />
  22. </head>
  23. <body class="wy-body-for-nav">
  24. <div class="wy-grid-for-nav">
  25. <nav data-toggle="wy-nav-shift" class="wy-nav-side">
  26. <div class="wy-side-scroll">
  27. <div class="wy-side-nav-search" >
  28. <a href="index.html" class="icon icon-home"> baangt
  29. </a>
  30. <div role="search">
  31. <form id="rtd-search-form" class="wy-form" action="search.html" method="get">
  32. <input type="text" name="q" placeholder="Search docs" />
  33. <input type="hidden" name="check_keywords" value="yes" />
  34. <input type="hidden" name="area" value="default" />
  35. </form>
  36. </div>
  37. </div>
  38. <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
  39. <p class="caption"><span class="caption-text">Contents:</span></p>
  40. <ul class="current">
  41. <li class="toctree-l1"><a class="reference internal" href="Installation.html"> Installation</a></li>
  42. <li class="toctree-l1"><a class="reference internal" href="OverviewUsage.html"> Overview</a></li>
  43. <li class="toctree-l1"><a class="reference internal" href="simpleExample.html"> First Steps</a></li>
  44. <li class="toctree-l1"><a class="reference internal" href="Structure.html"> Structure</a></li>
  45. <li class="toctree-l1"><a class="reference internal" href="ParametersConfigFile.html"> Parameters</a></li>
  46. <li class="toctree-l1 current"><a class="current reference internal" href="#"> First API Test</a><ul>
  47. <li class="toctree-l2"><a class="reference internal" href="#steps-to-test-the-simple-api-format">Steps to test the simple API Format:</a><ul>
  48. <li class="toctree-l3"><a class="reference internal" href="#play-around">Play around</a></li>
  49. </ul>
  50. </li>
  51. <li class="toctree-l2"><a class="reference internal" href="#activities-for-api-tests">Activities for API-Tests:</a></li>
  52. <li class="toctree-l2"><a class="reference internal" href="#special-data-fields-in-api-tests">Special data fields in API-Tests:</a></li>
  53. </ul>
  54. </li>
  55. <li class="toctree-l1"><a class="reference internal" href="TestTypes.html"> Types of Tests</a></li>
  56. <li class="toctree-l1"><a class="reference internal" href="DataFile.html"> Data file</a></li>
  57. <li class="toctree-l1"><a class="reference internal" href="SaveResults2Database.html"> Results in Database</a></li>
  58. <li class="toctree-l1"><a class="reference internal" href="HistoryAndReasons.html"> History</a></li>
  59. <li class="toctree-l1"><a class="reference internal" href="contributors.html"> Contributions</a></li>
  60. <li class="toctree-l1"><a class="reference internal" href="changelog.html"> Changelog</a></li>
  61. <li class="toctree-l1"><a class="reference internal" href="PlannedFeatures.html"> Planned Features</a></li>
  62. <li class="toctree-l1"><a class="reference internal" href="BrowserDrivers.html"> Browser Drivers</a></li>
  63. <li class="toctree-l1"><a class="reference internal" href="Variables.html"> Variables</a></li>
  64. <li class="toctree-l1"><a class="reference internal" href="SendStatistics.html"> Results</a></li>
  65. <li class="toctree-l1"><a class="reference internal" href="Datagenerator.html">DataGenerator</a></li>
  66. <li class="toctree-l1"><a class="reference internal" href="Datagenerator.html#input-file">Input File</a></li>
  67. <li class="toctree-l1"><a class="reference internal" href="Datagenerator.html#data-type">Data Type</a></li>
  68. <li class="toctree-l1"><a class="reference internal" href="Datagenerator.html#all-data-types-format">All Data Types Format</a></li>
  69. <li class="toctree-l1"><a class="reference internal" href="Developer.html"> For Developers</a></li>
  70. <li class="toctree-l1"><a class="reference internal" href="baangt-Plugin.html">What is a baangt-plugin</a></li>
  71. <li class="toctree-l1"><a class="reference internal" href="baangt-Plugin.html#how-to-make-a-baangt-plugin">how to make a baangt-plugin</a></li>
  72. <li class="toctree-l1"><a class="reference internal" href="baangt-Plugin.html#how-the-baangt-plugin-work">how the baangt-plugin work</a></li>
  73. <li class="toctree-l1"><a class="reference internal" href="baangt-Plugin.html#how-to-replace-the-existing-plugin-by-your-own-one">how to replace the existing plugin by your own one</a></li>
  74. <li class="toctree-l1"><a class="reference internal" href="articles/Articles.html"> :subheader: Articles</a></li>
  75. <li class="toctree-l1"><a class="reference external" href="http://www.baangt.org"> Web</a></li>
  76. </ul>
  77. <p class="caption"><span class="caption-text">Autodocs:</span></p>
  78. <ul>
  79. <li class="toctree-l1"><a class="reference internal" href="docs/baangt.base.html">Autodocs</a></li>
  80. <li class="toctree-l1"><a class="reference internal" href="docs/modules.html">Modules</a></li>
  81. </ul>
  82. </div>
  83. </div>
  84. </nav>
  85. <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
  86. <nav class="wy-nav-top" aria-label="top navigation">
  87. <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
  88. <a href="index.html">baangt</a>
  89. </nav>
  90. <div class="wy-nav-content">
  91. <div class="rst-content">
  92. <div role="navigation" aria-label="breadcrumbs navigation">
  93. <ul class="wy-breadcrumbs">
  94. <li><a href="index.html">Docs</a> &raquo;</li>
  95. <li>How to create a simple API Test</li>
  96. <li class="wy-breadcrumbs-aside">
  97. <a href="_sources/SimpleAPI.rst.txt" rel="nofollow"> View page source</a>
  98. </li>
  99. </ul>
  100. <hr/>
  101. </div>
  102. <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
  103. <div itemprop="articleBody">
  104. <div class="section" id="how-to-create-a-simple-api-test">
  105. <h1>How to create a simple API Test<a class="headerlink" href="#how-to-create-a-simple-api-test" title="Permalink to this headline">¶</a></h1>
  106. <p>API-Tests are usually something, that the classic business people wouldn’t know about. With <code class="docutils literal notranslate"><span class="pre">baangt</span></code> and a bit
  107. of effort it should be possible even for business people to do some simple API-Tests.</p>
  108. <p>As with all tests in <code class="docutils literal notranslate"><span class="pre">baangt</span></code> also API-Tests are defined in a simple format in MS Excel. See <code class="docutils literal notranslate"><span class="pre">MovieSimpleAPI.xlsx</span></code>
  109. as working example.</p>
  110. <blockquote>
  111. <div><p>Prerequisit for simple API definition format:</p>
  112. <ul class="simple">
  113. <li><p>Filename must contain the word “api”, otherwise simple format will try to create a browser test run.</p></li>
  114. </ul>
  115. </div></blockquote>
  116. <div class="section" id="steps-to-test-the-simple-api-format">
  117. <h2>Steps to test the simple API Format:<a class="headerlink" href="#steps-to-test-the-simple-api-format" title="Permalink to this headline">¶</a></h2>
  118. <p>Fire up <code class="docutils literal notranslate"><span class="pre">baangt</span></code>, chose file <code class="docutils literal notranslate"><span class="pre">MovieSimpleApi.XLSX</span></code> as your run definition. Start the testrun by clicking on the
  119. button <code class="docutils literal notranslate"><span class="pre">Execute</span></code>. After a few seconds you should see the popup “Testrun finished”. Now open the result file
  120. <code class="docutils literal notranslate"><span class="pre">baangt_MovieSimpleAPI_&lt;date&gt;.xlsx</span></code> and see overview and details of the API Test run.</p>
  121. <div class="section" id="play-around">
  122. <h3>Play around<a class="headerlink" href="#play-around" title="Permalink to this headline">¶</a></h3>
  123. <p>To extend this very simple example you could want to add the field “Actors” to your result sheet. To do so, add one line
  124. in the Tab <code class="docutils literal notranslate"><span class="pre">TestStepExecution</span></code>.</p>
  125. <ul class="simple">
  126. <li><p><code class="docutils literal notranslate"><span class="pre">Activity</span></code> is <code class="docutils literal notranslate"><span class="pre">SAVE</span></code></p></li>
  127. <li><p><code class="docutils literal notranslate"><span class="pre">Value</span></code> is <code class="docutils literal notranslate"><span class="pre">RESULT_Actors</span></code></p></li>
  128. <li><p><code class="docutils literal notranslate"><span class="pre">Value2</span></code> is <code class="docutils literal notranslate"><span class="pre">$(ANSWER_CONTENT.Actors)</span></code></p></li>
  129. </ul>
  130. <p>Save the Excel-Sheet. Re-run the test case and you should see the new column “Result_Actors” with the values retrieved
  131. from the API.</p>
  132. </div>
  133. </div>
  134. <div class="section" id="activities-for-api-tests">
  135. <h2>Activities for API-Tests:<a class="headerlink" href="#activities-for-api-tests" title="Permalink to this headline">¶</a></h2>
  136. <p>(Even though we write all activtities in UPPER CASE, you can write them in any way you like)</p>
  137. <table class="colwidths-given docutils align-default" id="id1">
  138. <caption><span class="caption-text">Values for Activities for simple API format</span><a class="headerlink" href="#id1" title="Permalink to this table">¶</a></caption>
  139. <colgroup>
  140. <col style="width: 25%" />
  141. <col style="width: 75%" />
  142. </colgroup>
  143. <thead>
  144. <tr class="row-odd"><th class="head"><p>Activity</p></th>
  145. <th class="head"><p>Description</p></th>
  146. </tr>
  147. </thead>
  148. <tbody>
  149. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">APIURL</span></code></p></td>
  150. <td><p>Set’s the main URI/URL for your API-Tests. Could be omitted, if you want to always specify full path in ENDPOINT.</p></td>
  151. </tr>
  152. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">ENDPOINT</span></code></p></td>
  153. <td><p>Set’s the Endpoint-Name for the following API-Call. E.g. if your Endpoint is located at
  154. <a class="reference external" href="https://app-eu.earthsquad.global/api/rest-auth/login">https://app-eu.earthsquad.global/api/rest-auth/login</a> and during this test case execution you’d call a lot of APIs
  155. on this server, then you’d set <code class="docutils literal notranslate"><span class="pre">APIURL</span></code> to <a class="reference external" href="https://app-eu.earthsquad.global">https://app-eu.earthsquad.global</a> and set <code class="docutils literal notranslate"><span class="pre">ENDPOINT</span></code> to “/api/rest-auth/login”</p></td>
  156. </tr>
  157. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">POST</span></code></p></td>
  158. <td><p>Send a “POST”-Request to the API. Place the content, that you want to send to this endpoint in the column <code class="docutils literal notranslate"><span class="pre">value</span></code></p></td>
  159. </tr>
  160. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">GET</span></code></p></td>
  161. <td><p>Send a “GET”-Request to the API. URL-Parameters are taken from <code class="docutils literal notranslate"><span class="pre">APIURL</span></code> and <code class="docutils literal notranslate"><span class="pre">ENDPOINT</span></code>. Result is stored for
  162. immediate retrieval (see below).</p></td>
  163. </tr>
  164. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">HEADER</span></code></p></td>
  165. <td><p>Set additional parameters for the next API-Calls into the Header. In combination with the special fields (see below)
  166. it’s easy to take a result from one API-Request and use it (or parts of it) as input for the next call.</p></td>
  167. </tr>
  168. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">SAVE</span></code></p></td>
  169. <td><p>Save a value from the header or from result to output file (XLSX). <code class="docutils literal notranslate"><span class="pre">value</span></code> is the field-name. If you name it
  170. “RESULT_&lt;something&gt;” it is automatically added to the export field list. If you work in API-Simple mode, this is
  171. your only chance to get fields added into the result sheet.
  172. <code class="docutils literal notranslate"><span class="pre">value2</span></code> is the source (e.g. <code class="docutils literal notranslate"><span class="pre">$(ANSWER_CONTENT.imdbRating)</span></code> would retrieve the value “imdbRating” of the
  173. answer of your API-Call.</p></td>
  174. </tr>
  175. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">ASSERT</span></code></p></td>
  176. <td><p>This will retrieve value of element specified by <cite>locator</cite>
  177. And compare with expected_value specified in <cite>value</cite></p>
  178. <p>if expected_value not matches with output_value it will raise TestStepExecution and result in FAILED.</p>
  179. </td>
  180. </tr>
  181. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">ADDRESS_CREATE</span></code></p></td>
  182. <td><p>Create Address Data for various test cases and save in testDataDict
  183. The following field variable can be used via $(field_name).</p>
  184. <p>[‘HouseNumber’, ‘AdditionalData1’, ‘AdditionalData2’, ‘StreetName’, ‘CityName’, ‘PostalCode’, ‘CountryCode’]</p>
  185. <dl class="simple">
  186. <dt>Example:</dt><dd><p>Default Data: (value=&lt;blank&gt; and value2=&lt;blank&gt;)
  187. ‘HouseNumber’: ‘6’, ‘AdditionalData1’: ‘Near MahavirChowk’, ‘AdditionalData2’: ‘Opposite St. Marish Church’, ‘StreetName’: ‘GoreGaon’, ‘CityName’: ‘Ambala’, ‘PostalCode’: ‘160055’, ‘CountryCode’: ‘India’</p>
  188. </dd>
  189. <dt><cite>value</cite> optional</dt><dd><dl class="simple">
  190. <dt>if provided<span class="classifier">(value= {“CountryCode”:”US”,”CityName”:”Athens”} value2=&lt;blank&gt;)</span></dt><dd><p>FieldValue updated to:
  191. {‘HouseNumber’: ‘6’, ‘AdditionalData1’: ‘Near MahavirChowk’,
  192. ‘AdditionalData2’: ‘Opposite St. Marish Church’,
  193. ‘StreetName’: ‘GoreGaon’, ‘CityName’: ‘Athens’,
  194. ‘PostalCode’: ‘160055’, ‘CountryCode’: ‘US’}</p>
  195. </dd>
  196. </dl>
  197. </dd>
  198. </dl>
  199. <p><cite>value2</cite> optional</p>
  200. <blockquote>
  201. <div><p>Field will be prefixed with “office_&lt;field_name&gt;”. Ex. “office_CountryCode”</p>
  202. </div></blockquote>
  203. </td>
  204. </tr>
  205. </tbody>
  206. </table>
  207. </div>
  208. <div class="section" id="special-data-fields-in-api-tests">
  209. <h2>Special data fields in API-Tests:<a class="headerlink" href="#special-data-fields-in-api-tests" title="Permalink to this headline">¶</a></h2>
  210. <p>In WEB-Testing you check results either via <code class="docutils literal notranslate"><span class="pre">Assert</span></code>-Statement or via mapping the text or attribute of an element to a
  211. field in the TestDataDictionary. In API-Tests you have some automatic internal variables, that you can use without
  212. manually declaring them:</p>
  213. <table class="colwidths-given docutils align-default" id="id2">
  214. <caption><span class="caption-text">Special Internal Variables in API-Testing</span><a class="headerlink" href="#id2" title="Permalink to this table">¶</a></caption>
  215. <colgroup>
  216. <col style="width: 25%" />
  217. <col style="width: 75%" />
  218. </colgroup>
  219. <thead>
  220. <tr class="row-odd"><th class="head"><p>Variable</p></th>
  221. <th class="head"><p>Contents</p></th>
  222. </tr>
  223. </thead>
  224. <tbody>
  225. <tr class="row-even"><td><p>RESULT_CODE</p></td>
  226. <td><p>Result code of the last call to an API. Ideally you’d be able to match result codes as described in here
  227. <a class="reference external" href="https://restfulapi.net/http-status-codes/">https://restfulapi.net/http-status-codes/</a>, but in the end setting the status code is the job of the developer of
  228. the API you’re using - they might follow a different path or simply have bugs.</p></td>
  229. </tr>
  230. <tr class="row-odd"><td><p>ANSWER_HEADER</p></td>
  231. <td><p>Last Header. You can access a certain part of the header by using $(ANSWER_HEADER.&lt;partName&gt;), so if you want to
  232. use the part <code class="docutils literal notranslate"><span class="pre">login_key</span></code> of a header you’d write <code class="docutils literal notranslate"><span class="pre">$(ANSWER_HEADER.LOGIN_KEY)</span></code></p></td>
  233. </tr>
  234. <tr class="row-even"><td><p>ANSWER_CONTENT</p></td>
  235. <td><p>Last content of an API-Call (Post, Get, etc.). Again you can access/extract/replace parts of this content using
  236. the “.” like described in the line above (e.g. <code class="docutils literal notranslate"><span class="pre">$(ANSWER_CONTENT.FRANZI)</span></code> to refer to a content part <code class="docutils literal notranslate"><span class="pre">FRANZI</span></code>.</p></td>
  237. </tr>
  238. </tbody>
  239. </table>
  240. </div>
  241. </div>
  242. </div>
  243. </div>
  244. <footer>
  245. <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
  246. <a href="TestTypes.html" class="btn btn-neutral float-right" title="Types of tests" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
  247. <a href="ParametersConfigFile.html" class="btn btn-neutral float-left" title="Parameters in Configuration files (globals)" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
  248. </div>
  249. <hr/>
  250. <div role="contentinfo">
  251. <p>
  252. &copy; Copyright 2020, Bernhard Buhl
  253. </p>
  254. </div>
  255. Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
  256. </footer>
  257. </div>
  258. </div>
  259. </section>
  260. </div>
  261. <script type="text/javascript">
  262. jQuery(function () {
  263. SphinxRtdTheme.Navigation.enable(true);
  264. });
  265. </script>
  266. </body>
  267. </html>