<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>API learning &#8211; TestMace / blog</title>
	<atom:link href="https://testmace.com/blog/category/api-learning/feed/" rel="self" type="application/rss+xml" />
	<link>https://testmace.com/blog</link>
	<description></description>
	<lastBuildDate>Fri, 13 Mar 2020 06:54:09 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.9.13</generator>

<image>
	<url>https://testmace.com/blog/wp-content/uploads/2018/11/cropped-favicon-1-32x32.png</url>
	<title>API learning &#8211; TestMace / blog</title>
	<link>https://testmace.com/blog</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Your first test in SoapUI</title>
		<link>https://testmace.com/blog/2019/01/10/your-first-test-in-soapui/</link>
		<comments>https://testmace.com/blog/2019/01/10/your-first-test-in-soapui/#respond</comments>
		<pubDate>Thu, 10 Jan 2019 06:11:48 +0000</pubDate>
		<dc:creator><![CDATA[Dmitriy Snytkin]]></dc:creator>
				<category><![CDATA[API learning]]></category>

		<guid isPermaLink="false">https://testmace.com/blog/?p=8175</guid>
		<description><![CDATA[Prerequisites You should have a nodding acquaintance with the HTTP comprehending what the request and response consist of. You should understand the principles of a query construction for a service resources access and what REST API means. Introduction SoapUI is a tool for Web Services testing that based on work with HTTP.  There can be...]]></description>
				<content:encoded><![CDATA[<h3><strong>Prerequisites</strong></h3>
<ul>
<li style="font-weight: 400;"><span style="font-weight: 400;">You should have </span><span style="font-weight: 400;">a nodding acquaintance with</span><span style="font-weight: 400;"> the HTTP comprehending what the request and response consist of. </span></li>
<li style="font-weight: 400;"><span style="font-weight: 400;">You should understand the principles of a query construction for a service resources access and what REST API means.</span></li>
</ul>
<h3><strong>Introduction</strong></h3>
<p><span style="font-weight: 400;">SoapUI is a tool for Web Services testing that based on work with HTTP.  There can be services which API is built upon the REST methodology or the SOAP protocol. Developers and QA engineers use this tool for automated functional, load, regression tests and many other things. SoapUI is considered the richest software tool of a kind in terms of functionality. Launching this program for the first time you don’t know where to look first as you don’t understand where to start. However, the range of its opportunities and its utility are being realized when you dive back into it and work for a while. </span></p>
<p><span style="font-weight: 400;">In this article I would like to assist newcomers to take the first step towards getting acquainted with this powerful tool from scratch, from its installation to creating your first HTTP request to a REST service and to its coverage by tests. Here we go! </span></p>
<h3><strong>Installation</strong></h3>
<p><span style="font-weight: 400;">SoapUI is a cross-platform program that is available in two formats: Open Source и Pro. To complete everything that will be covered in this article the Open Source version functionality is enough.You can download an installation file for Windows, Linux, MacOS on the developer official website </span><a href="https://www.soapui.org/downloads/latest-release.html"><span style="font-weight: 400;">https://www.soapui.org/downloads/latest-release.html</span></a><span style="font-weight: 400;">. </span></p>
<p><span style="font-weight: 400;">There are some key steps for the installation on the 64-bit version of Linux:</span></p>
<ul>
<li style="font-weight: 400;"><span style="font-weight: 400;">firstly it’s necessary to install </span><a href="https://java.com/en/download/help/linux_x64_install.xml"><span style="font-weight: 400;">JRE</span></a></li>
<li style="font-weight: 400;"><span style="font-weight: 400;">download an archive with the program </span></li>
<li style="font-weight: 400;"><span style="font-weight: 400;">extract the installation file into a catalogue </span></li>
<li style="font-weight: 400;"><span style="font-weight: 400;">make sure that a user </span><span style="font-weight: 400;">on behalf of which a launch is performed has the rights to read and write to the directory</span></li>
<li style="font-weight: 400;"><span style="font-weight: 400;">enter the catalogue, grant rights to run a file </span><span style="font-weight: 400;color:red;">bin/soapui.sh</span></li>
<li style="font-weight: 400;"><span style="font-weight: 400;">The next step is an optional one. Create a  run app shortcut following the steps listed in a guide from another article </span><a href="https://testmace.com/blog/2018/11/22/8082/"><span style="font-weight: 400;">“Your First Postman Test”</span></a><span style="font-weight: 400;">.</span></li>
</ul>
<p><span style="font-weight: 400;">As for other software systems it’s quite easy. Suffice to download the installation program, run it and follow its simple instructions. If any issues have been noticed during the installation process you can refer to the detailed manual and a relevant </span><a href="https://www.soapui.org/getting-started/installing-soapui.html"><span style="font-weight: 400;">section of documentation</span></a><span style="font-weight: 400;"> to find a solution.</span></p>
<h3><strong>Interface overview </strong></h3>
<p><span style="font-weight: 400;">Launch the program. There you can see the following interface components: </span></p>
<ul>
<li style="font-weight: 400;"><span style="font-weight: 400;">a project console (on top). There are buttons for a project creation, import of a previously created project, save, a link to a community forum, SoapUI app settings, and quick switching off/on of a run queries through a proxy server.</span></li>
<li style="font-weight: 400;"><span style="font-weight: 400;">a project navigator (on the left). A project tree is displayed here you can add, delete, disable nodes of different purposes (Project, API server scheme, test cases, and etc.).</span></li>
<li style="font-weight: 400;"><span style="font-weight: 400;">a properties window of the chosen node (bottom left). Depending on the node selected in the navigator, tables with various sets of properties for their quick editing are displayed in the window. </span></li>
<li style="font-weight: 400;"><i><span style="font-weight: 400;">a primary workspace </span></i><span style="font-weight: 400;">is located to the right of the navigator, there editing and running all the project tree elements happen.</span></li>
</ul>
<h3><strong>Creating a project and an API scheme </strong></h3>
<p><span style="font-weight: 400;">By default the navigator has a Workspace node, in which nodes of a Project type are grouped. You can create a project draft through the app menu File &gt; Create empty project by clicking a relevant button in the project console or through a context menu of the Workspace node in the navigator. </span></p>
<p><span style="font-weight: 400;">To create any RESTful service query in SoapUI you first have to create a WADL(Web Application Description Language) element in the project, in which resources and accessor methods to them through the web service interface are described. There is an opportunity in SoapUI to import an API scheme from Swagger, open an already prepared scheme or create a new one from scratch. So let’s create a scheme from scratch.</span></p>
<p><span style="font-weight: 400;">I use </span><a href="https://github.com/toddmotto/public-apis"><span style="font-weight: 400;">one of the many free API&#8217;s</span></a><span style="font-weight: 400;"> as a guinea pig. Let’s create a GET request at URI as an example https://hacker-news.firebaseio.com/v0/item/8863.json?print=pretty. You need to choose </span><i><span style="font-weight: 400;">New REST Service from URI</span></i><span style="font-weight: 400;"> through the context menu of the created project in the navigator</span><i><span style="font-weight: 400;">. </span></i><span style="font-weight: 400;">Enter our URI in the dialog box</span><i><span style="font-weight: 400;">. </span></i><span style="font-weight: 400;">Four nested nodes are created in the tree. We’ll sort it out what is what.</span></p>
<p><a ref="magnificPopup" href="https://testmace.com/blog/wp-content/uploads/2019/01/image3.png"><img class="alignnone size-full wp-image-8180" src="https://testmace.com/blog/wp-content/uploads/2019/01/image3.png" alt="" width="377" height="114" srcset="https://testmace.com/blog/wp-content/uploads/2019/01/image3.png 377w, https://testmace.com/blog/wp-content/uploads/2019/01/image3-300x91.png 300w" sizes="(max-width: 377px) 100vw, 377px" /></a></p>
<p><span style="font-weight: 400;">The top level element is the entire WADL scheme. If you open this node by a double click you can see the navigator window and description of the scheme in the WADL language (derived from XML) in the appeared window on the WADL Content tab. In the settings of this nodes on the Service Endpoints tab you can list various hosts names on which running this service. There is already one host name that the program has derived from the input URI. Let’s imagine that we are developers of the service and want to test a new functionality on the test server (for example, a fictitious server is </span><a href="https://stage.hacker-news.firebaseio.com"><span style="font-weight: 400;">https://stage.hacker-news.firebaseio.com</span></a><span style="font-weight: 400;">) and keep an eye on our realised server. In this case you need to add one more record into the endpoints </span><a href="https://stage.hacker-news.firebaseio.com"><span style="font-weight: 400;">https://stage.hacker-news.firebaseio.com</span></a><span style="font-weight: 400;">. Now we have the opportunity to choose on which server we will run the prepared test cases.</span></p>
<p><span style="font-weight: 400;">The next element named </span><span style="font-weight: 400;color:red;">8863.json [/v0/item/8863.json]</span><span style="font-weight: 400;"> has the form of one of many service resources description. In this case a type of resource is an item, and 8863 is an identification number of a concrete instance of this type. You can specify a path to the resource on the server in the edit window for this element and add a number of parameters and headings with which any requests to this resource should be made.</span></p>
<p><a ref="magnificPopup" href="https://testmace.com/blog/wp-content/uploads/2019/01/image7.png"><img class="alignnone size-full wp-image-8182" src="https://testmace.com/blog/wp-content/uploads/2019/01/image7.png" alt="" width="468" height="272" srcset="https://testmace.com/blog/wp-content/uploads/2019/01/image7.png 468w, https://testmace.com/blog/wp-content/uploads/2019/01/image7-300x174.png 300w" sizes="(max-width: 468px) 100vw, 468px" /></a></p>
<p><span style="font-weight: 400;">On this step, I would like to add a bit of Feng Shui in the scheme description and  make this resource more universal. In the program generated path to the resource, requests can only be made to the instance with the ID 8863 in json format. Let’s assume that there are more instances on the server than this one and they can be implemented in XML format. To make description of the resource more useful you should rewrite the path to it having applied template parameters:</span></p>
<p><a ref="magnificPopup" href="https://testmace.com/blog/wp-content/uploads/2019/01/image4.png"><img class="alignnone size-full wp-image-8181" src="https://testmace.com/blog/wp-content/uploads/2019/01/image4.png" alt="" width="470" height="251" srcset="https://testmace.com/blog/wp-content/uploads/2019/01/image4.png 470w, https://testmace.com/blog/wp-content/uploads/2019/01/image4-300x160.png 300w" sizes="(max-width: 470px) 100vw, 470px" /></a></p>
<p><span style="font-weight: 400;">You can create queries to this resource in a such way transferring instance ID </span><span style="font-weight: 400;color:red;">item_id </span><span style="font-weight: 400;">and its format</span> <span style="font-weight: 400;color:red;">format</span> <span style="font-weight: 400;">( json by default)</span><span style="font-weight: 400;"> as a parameters. </span></p>
<p><span style="font-weight: 400;">The following element defines available query methods to the resource. In the edit window for the element you can choose method type and add various query parameters specific to requests when accessing a resource through this method. You can add many queries to a such node on the navigator tree. Each of them is able to extend a number of parameters and assign a specific value. The program has generated GET method from the previously input URI. This is exactly what we need.</span></p>
<p><span style="font-weight: 400;">Well, finally, we give consideration to an element of the request itself. In this component you can directly run a query to a service on one of the endpoints, defined in WADL, for an access to the resource through the chosen method. In the left part of the element settings window you can notice a table with all sorts of query parameters that are inherited from a resource and method. On the Raw tab there is a submission of a request in accordance with the HTTP protocol. You can behold server response in the different formats in the right part of this element window. SoapU parses server responses and provides them in more convenient to perceive format than if it is in a raw HTTP. </span></p>
<p><span style="font-weight: 400;">Separately I would like to emphasize that resource and methods are part of the API Web service scheme description while queries are abstraction of the SoapUI itself, and it is not mentioned in WADL scheme. You can verify it returning to the WADL Content tab.</span></p>
<h3><strong>Sending HTTP requests</strong></h3>
<p><span style="font-weight: 400;">To make a request you should push the button as an Play icon in the upper left corner of the request box or you can avail of Alt+Enter shortcut. </span></p>
<p><a ref="magnificPopup" href="https://testmace.com/blog/wp-content/uploads/2019/01/image2.png"><img class="alignnone size-full wp-image-8183" src="https://testmace.com/blog/wp-content/uploads/2019/01/image2.png" alt="" width="1271" height="375" srcset="https://testmace.com/blog/wp-content/uploads/2019/01/image2.png 1271w, https://testmace.com/blog/wp-content/uploads/2019/01/image2-300x89.png 300w, https://testmace.com/blog/wp-content/uploads/2019/01/image2-1024x302.png 1024w" sizes="(max-width: 1271px) 100vw, 1271px" /></a></p>
<p><span style="font-weight: 400;">Server has returned a response status with error. What is it, then? Let’s consider the Raw HTTP request: </span></p>
<pre><code >GET https://hacker-news.firebaseio.com/v0/item/.json?print=pretty HTTP/1.1<br />
Accept-Encoding: gzip,deflate<br />
Host: hacker-news.firebaseio.com<br />
Connection: Keep-Alive<br />
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)<br />
</code></pre>
<span style="font-weight: 400;">I have forgotten to define a value for resource ID </span><span style="font-weight: 400;color:red;">item_id</span><span style="font-weight: 400;">. My suggestion is to remain this query unchanged. Further, we will be able to set parameters. In order to verify a request to the concrete instance we will create a duplicate and define the value for the missing parameter. We need to choose Clone Request through the context menu of the element request in the navigator and name it “get item № 8863”. Having set item_id parameter in the 8863 value, you need to make the request again. </span></p>
<p><a ref="magnificPopup" href="https://testmace.com/blog/wp-content/uploads/2019/01/image5.png"><img class="alignnone size-full wp-image-8184" src="https://testmace.com/blog/wp-content/uploads/2019/01/image5.png" alt="" width="722" height="354" srcset="https://testmace.com/blog/wp-content/uploads/2019/01/image5.png 722w, https://testmace.com/blog/wp-content/uploads/2019/01/image5-300x147.png 300w" sizes="(max-width: 722px) 100vw, 722px" /></a></p>
<p><span style="font-weight: 400;">Great! Your first successful request in SoapUI has just been made. Please pay attention that depending on Content-Type in the response the program provides relevant submissions for a human readable perception of information. In this case you can find response body with its marked format on the JSON tab.</span></p>
<h3><strong>Writing test cases</strong></h3>
<p><span style="font-weight: 400;">We have learned to make query to a Web service so now it is time to cover it by tests. We can generate test cases for each of our resources by selecting Generate Test Suite through the context menu of the WADL element in the navigator. However, I’d rather make it step by step on my own. </span></p>
<p><span style="font-weight: 400;">So we add a Test Suite object in our project through the context menu or using Ctrl + T shortcut. Then we should name it </span><span style="font-weight: 400;color:red;">Item Resource TestSuite</span><span style="font-weight: 400;">. In the TestSuite settings menu we are able to detect a list of TestCases, controls for launching and pause of tests of this group, choose serial or parallel way of launching, set description on the Description tab, set variables that are common for all tests of the group on the Properties tab, write a script in Groovy that will be completed before running and at the end of all tests for test environment setting. </span></p>
<p><span style="font-weight: 400;">Criteria for cases integration in TestSuite can be various. This can be tests aimed at a particular part of service functionality coverage, tests aimed at Quick regression testing, tests for different parts of service functionality monitoring, and other. In our case that is not an issue that’s why I will add in prepared Suite only tests connected with an access to item resource.</span></p>
<p><span style="font-weight: 400;">Let’s create a first test case through the TestSuite context menu or using Ctrl + N shortcut. Then we should give a meaningful name expressing the coverage of the test for short, </span><span style="font-weight: 400;color:red;">Should return requested item</span><span style="font-weight: 400;">. Because of the test case name it is clear that we would like to make sure the object request service with the given ID should return relevant resource data. There are elements for starting and force trip of a case, case circularity option, service authorization method setting, choosing endpoint on which this case will be running, button for adding load and vulnerability tests in the TestCase edit window. Next is progress bar of a test case implementation and a list of its steps.  </span></p>
<p><span style="font-weight: 400;">Test case can consist of many different steps, and one article is not enough to consider their diversity. That’s why I will concentrate only on one that is handy for us. Press the second button on the left with adding a step “Create a new REST Request TestStep”.</span></p>
<p><a ref="magnificPopup" href="https://testmace.com/blog/wp-content/uploads/2019/01/image6.png"><img class="alignnone size-full wp-image-8185" src="https://testmace.com/blog/wp-content/uploads/2019/01/image6.png" alt="" width="398" height="398" srcset="https://testmace.com/blog/wp-content/uploads/2019/01/image6.png 398w, https://testmace.com/blog/wp-content/uploads/2019/01/image6-150x150.png 150w, https://testmace.com/blog/wp-content/uploads/2019/01/image6-300x300.png 300w, https://testmace.com/blog/wp-content/uploads/2019/01/image6-350x350.png 350w" sizes="(max-width: 398px) 100vw, 398px" /></a></p>
<p><span style="font-weight: 400;">Then we should name it as a “send request” and in the appeared dialog box with the list we choose one of the previously created requests.</span></p>
<p><a ref="magnificPopup" href="https://testmace.com/blog/wp-content/uploads/2019/01/image8.png"><img class="alignnone size-full wp-image-8186" src="https://testmace.com/blog/wp-content/uploads/2019/01/image8.png" alt="" width="637" height="128" srcset="https://testmace.com/blog/wp-content/uploads/2019/01/image8.png 637w, https://testmace.com/blog/wp-content/uploads/2019/01/image8-300x60.png 300w" sizes="(max-width: 637px) 100vw, 637px" /></a></p>
<p><span style="font-weight: 400;">Now our test case has the first and only step. Further, we need to add “face-to-face” checks of the request results. At the bottom of the TestStep settings window (by the way, this window is very similar to the request settings window) you can find Assertions tab. This is where all conditions for this step check are added. Let’s bring in an assertion to verify that a returned response complies with a requested item:</span></p>
<ul>
<li style="font-weight: 400;"><span style="font-weight: 400;">Click on a button with the “+” icon;</span></li>
<li style="font-weight: 400;"><span style="font-weight: 400;">Choose JSONPath Match snippet in the appeared window in the Property Content section;</span></li>
<li style="font-weight: 400;"><span style="font-weight: 400;">Write a path to the ID field in a response: $.id in JSONPath Expression;</span></li>
<li style="font-weight: 400;"><span style="font-weight: 400;">Write the value 8863 in the Expected result field. </span></li>
</ul>
<p><span style="font-weight: 400;">Then we should run the step as we run request. This step icon in the navigator tree has become Green as well as Assertions tab. Great, this is success!</span></p>
<p><span style="font-weight: 400;">Frankly speaking, our test is of very low value and it is quite easy to break it. Let’s make a duplicate of the TestCase using F9 hotkey or through the context menu and change the item_id value to 9224 in this step. </span></p>
<p><span style="font-weight: 400;">Having run this step, it will become red in your test. Logically, the server has already returned the object with other ID. Now we have to amend the assertion description. We will specify a current step variables &#8211; ${item_id} as an expected result. Then, whatever item_id for the request we input our tests are always green. In SoapUI it is possible to indicate a link to any property value of any project element as value.</span></p>
<h3><strong>Running some tests</strong></h3>
<p><span style="font-weight: 400;">Let’s come back to our TestCase object. We have two steps in a list. TestCase instance implies step by step implementation. If any step has not completed its tests other steps will not be launched. Another situation happens with TestSuite. Here TestCases can be launched both in series or on parallel. If one of them has been failed other cases will be started or will not be interrupted. anyway. Let’s run our TestCase.</span></p>
<p><a ref="magnificPopup" href="https://testmace.com/blog/wp-content/uploads/2019/01/image1.png"><img class="alignnone size-full wp-image-8187" src="https://testmace.com/blog/wp-content/uploads/2019/01/image1.png" alt="" width="1592" height="927" srcset="https://testmace.com/blog/wp-content/uploads/2019/01/image1.png 1592w, https://testmace.com/blog/wp-content/uploads/2019/01/image1-300x175.png 300w, https://testmace.com/blog/wp-content/uploads/2019/01/image1-1024x596.png 1024w" sizes="(max-width: 1592px) 100vw, 1592px" /></a></p>
<p><span style="font-weight: 400;">Everything is green. On the TestCase Log tab you can see the launched steps sequence and how much time their execution with verifications has taken. </span></p>
<h3><strong>Conclusion</strong></h3>
<p><span style="font-weight: 400;">In this article we have got familiar with SoapUI, the tool for writing automated tests of Web services, and with its basic functionality, learned to create an API Web service scheme, figured out what is WADL comprised of. Moreover, we have created our first request to an open API and covered it with the simplest tests without writing a single line of code.  In SoapUI there is an opportunity to make a query even easier just create TestCase with HTTP Request step. However, in this article I have decided to show how SoapUI differs from tools with similar functionality. I would like to say in the end that there are many more ways of making queries, cases and tests than I have been able to cover. SoapUI undoubtedly helps to improve the quality of a developing product, helps QA engineers as well as developers reducing the number of routine work. The project structure encourages good systematization of test cases and allows to run verifications of a large and complex system functionality parts. </span></p>
<h3><strong>Materials</strong></h3>
<p><span style="font-weight: 400;">File of the SoapUI project committed within this article: <a href="https://drive.google.com/file/d/1DwQpxAy9RTJ1qxxs5VjDzUu_j54xSBfQ/view?usp=sharing">https://drive.google.com/file/d/1DwQpxAy9RTJ1qxxs5VjDzUu_j54xSBfQ/view?usp=sharing</a></span></p>
]]></content:encoded>
			<wfw:commentRss>https://testmace.com/blog/2019/01/10/your-first-test-in-soapui/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Postman authorization methods</title>
		<link>https://testmace.com/blog/2018/12/03/8127/</link>
		<comments>https://testmace.com/blog/2018/12/03/8127/#respond</comments>
		<pubDate>Mon, 03 Dec 2018 11:04:53 +0000</pubDate>
		<dc:creator><![CDATA[Dmitriy Snytkin]]></dc:creator>
				<category><![CDATA[API learning]]></category>

		<guid isPermaLink="false">https://testmace.com/blog/?p=8127</guid>
		<description><![CDATA[Authorization is one of the most important features every decent REST client should have. Postman is not an exception. It is equipped with various authorization methods from simple Basic Auth to special AWS signature and NTLM Authentication. In this article we&#8217;ll review some of the most popular authorization methods. This wonderful service https://postman-echo.com and its...]]></description>
				<content:encoded><![CDATA[<p>Authorization is one of the most important features every decent REST client should have. Postman is not an exception. It is equipped with various authorization methods from simple Basic Auth to special AWS signature and NTLM Authentication. In this article we&#8217;ll review some of the most popular authorization methods. This wonderful service <a href="https://postman-echo.com">https://postman-echo.com</a> and its Authentication Methods section in particular will help us with testing.</p>
<h3><strong>Basic Auth</strong></h3>
<p>Let&#8217;s start with the simplest (and less common) method. It is quite rarely used (I used it a couple of times to restrict access to staging environment), definitely has some security issues, and shouldn&#8217;t ever be used without https. The thing is that for authorization (here we consider the option when we send the authorization data in a request header) we send username:password strings to the Authorization header base64. That means for a Postman user with a password &#8216;Password&#8217; the string is postman:password and its base64 version is cG9zdG1hbjpwYXNzd29yZA==. Our data header will look like this:</p>
<pre><code >Authorization: Basic cG9zdG1hbjpwYXNzd29yZA==</code></pre>
<p>Note that base64 is not an encryption or hash algorithm. It is a data encoding algorithm, and that explains its low security level. Now let&#8217;s see how Postman works with basic auth using an example from <a href="https://docs.postman-echo.com/#42c867ca-e72b-3307-169b-26a478b00641">postman-echo</a>.</p>
<p>While choosing Basic Auth from authorization list you are prompted to enter your username and password. Just enter &#8216;postman&#8217; and &#8216;password&#8217;, and the request willl be successfully sent 🙂 Postman encodes data to base64 and inserts it in the appropriate header:</p>
<p><a ref="magnificPopup" href="https://testmace.com/blog/wp-content/uploads/2018/12/PostMan-Authorization-6.png"><img class="alignnone wp-image-8135 size-full" src="https://testmace.com/blog/wp-content/uploads/2018/12/PostMan-Authorization-6.png" alt="" width="1602" height="631" srcset="https://testmace.com/blog/wp-content/uploads/2018/12/PostMan-Authorization-6.png 1602w, https://testmace.com/blog/wp-content/uploads/2018/12/PostMan-Authorization-6-300x118.png 300w, https://testmace.com/blog/wp-content/uploads/2018/12/PostMan-Authorization-6-1024x403.png 1024w" sizes="(max-width: 1602px) 100vw, 1602px" /></a></p>
<h3><strong>Bearer token</strong></h3>
<p>Let&#8217;s now talk about bearer token. This is one of the simplest authorization methods. To send an authorized request, we need to pass the value Bearer &lt;token&gt;, where &lt;token&gt; is some character sequence (usually a hash) that is generated in response to a successful authorization. It looks like that:</p>
<pre><code >Authorization: Bearer 129dabaf157205b46e393ce3e7f34ac6</code></pre>
<p>Bearer token was developed as a part of OAuth 2.0 in <a href="https://tools.ietf.org/html/rfc6750">RFC 6750</a>, but it generally functions as an independent authorization method.</p>
<p>Now I&#8217;ll show you how to use bearer token in Postman. First, you find it in the authorization methods list:</p>
<p><a ref="magnificPopup" href="https://testmace.com/blog/wp-content/uploads/2018/12/PostMan-Authorization-2.png"><img class="alignnone wp-image-8131 size-full" src="https://testmace.com/blog/wp-content/uploads/2018/12/PostMan-Authorization-2.png" alt="" width="450" height="434" srcset="https://testmace.com/blog/wp-content/uploads/2018/12/PostMan-Authorization-2.png 450w, https://testmace.com/blog/wp-content/uploads/2018/12/PostMan-Authorization-2-300x289.png 300w" sizes="(max-width: 450px) 100vw, 450px" /></a></p>
<p>Then you&#8217;ll be asked to type the token that I&#8217;ve mentioned earlier.</p>
<p><a ref="magnificPopup" href="https://testmace.com/blog/wp-content/uploads/2018/12/PostMan-Authorization-1.png"><img class="alignnone wp-image-8130 size-full" src="https://testmace.com/blog/wp-content/uploads/2018/12/PostMan-Authorization-1.png" alt="" width="1605" height="178" srcset="https://testmace.com/blog/wp-content/uploads/2018/12/PostMan-Authorization-1.png 1605w, https://testmace.com/blog/wp-content/uploads/2018/12/PostMan-Authorization-1-300x33.png 300w, https://testmace.com/blog/wp-content/uploads/2018/12/PostMan-Authorization-1-1024x114.png 1024w" sizes="(max-width: 1605px) 100vw, 1605px" /></a></p>
<p>As you can see, Postman recommends you use variables to keep tokens secure. In some cases this also might come in handy &#8211; with the help of variables you can easily use the same token in different requests.</p>
<h3><strong>Digest Access Authentication</strong></h3>
<p>The first version of digest access authentication was described in <a href="https://tools.ietf.org/html/rfc2069">RFC 2069</a>. That is a standard version of this authorization method, which often doesn&#8217;t provide the required security level. Later on RFC 2069 was replaced with <a href="https://tools.ietf.org/html/rfc2617">RFC 2617</a>, where a range of measures for security enhancement were introduced. Postman supports this standard. Let&#8217;s explore it with an example from <a href="https://docs.postman-echo.com/#a4c04e32-72cf-0475-07dc-89c23f85cf0c">postman-echo.com</a>.</p>
<p>Client-server interaction with digest access authentication includes:</p>
<p>1) Sending a request to the node that requires authorization. We get 401 (Unauthorized) code in response with digest access authentication parameters (or directives, according to the standard) in the WWW-Authenticate header. Here is an example:</p>
<pre><code >WWW-Authenticate: Digest realm="Users",<br />
                         nonce="Cmv5um4yl1wUrakLZhEH5FQpGA78EkkQ",<br />
                         qop="auth"<br />
</code></pre>
<p>2) Entering a login (username) and password (password) by the client (postman and password in our case). Here we just let the digest magic happen 🙂 No need to go into details since it&#8217;s all been thoroughly described in the standard. In short, the main thing here is calculation of the response directive using the chosen algorithm (MD5 or MD5-sess), the data that the client has, and the data that the server returned after step 1.</p>
<p>In the request all authorization parameters are passed in the Authorization header. The header will look like this:</p>
<pre><code >Authorization: Digest username="postman",<br />
                      realm="Users",<br />
                      nonce="ni1LiL0O37PRRhofWdCLmwFsnEtH1lew",<br />
                      uri="/digest-auth",<br />
                      response="254679099562cf07df9b6f5d8d15db44",<br />
                      opaque=""<br />
</code></pre>
<p>It&#8217;s time to put theory into practice. Set the following request parameters in Postman:</p>
<ul>
<li><strong>Request Type:</strong> GET</li>
<li><strong>Authorization Method:</strong> Digest Auth</li>
<li><strong>Username:</strong> postman</li>
<li><strong>Password:</strong> password</li>
</ul>
<p>Realm and Nonce values come from the server, so we use variables mechanism and pass echo_digest_realm and echo_digest_nonce values to these directives respectively. That&#8217;s how our configured request looks like:</p>
<p><a ref="magnificPopup" href="https://testmace.com/blog/wp-content/uploads/2018/12/PostMan-Authorization-3.png"><img class="alignnone wp-image-8132 size-full" src="https://testmace.com/blog/wp-content/uploads/2018/12/PostMan-Authorization-3.png" alt="" width="1609" height="688" srcset="https://testmace.com/blog/wp-content/uploads/2018/12/PostMan-Authorization-3.png 1609w, https://testmace.com/blog/wp-content/uploads/2018/12/PostMan-Authorization-3-300x128.png 300w, https://testmace.com/blog/wp-content/uploads/2018/12/PostMan-Authorization-3-1024x438.png 1024w" sizes="(max-width: 1609px) 100vw, 1609px" /></a></p>
<p>Now try to send the request and enjoy code 200 🙂</p>
<h3><strong>OAuth 1.0</strong></h3>
<p>OAuth 1.0 is an authorization protocol to access a third-party API. You probably use this authorization method from time to time while logging into some websites with Facebook or Github.</p>
<p><strong>There are 3 parties in this authorization method:</strong></p>
<ol>
<li>Server. In fact, that is your application itself</li>
<li>User. A user of your app</li>
<li>Service Provider. A third-party service, which user data we&#8217;re trying to get access to (with user&#8217;s consent for sure)</li>
</ol>
<p>Let&#8217;s imagine we want to retrieve the user&#8217;s social network contacts. Simply put, to do it we should follow the steps:</p>
<ol>
<li>Send a request to the Service Provider to get a Request token. In the request we pass oauth_consumer_key (a key that identifies our server), oauth_timestamp (a timestamp), oauth_callback (an address where a successfully authorized User should be redirected to), oauth_signature_method (a digital signature type, that can take values HMAC-SHA1, HMAC-SHA256, and PLAINTEXT), and oauth_signature (a digital signature). Check out <a href="https://oauth.net/core/1.0/#signing_process">the standard</a> to learn more about signature process. Please note that apart from request data, the Consumer Secret is also used &#8211; a key that only the Server and the Service Provider have access to. The Service Provider returns oauth_token (the very Request Token) and oauth_token_secret in response.</li>
</ol>
<ol start="2">
<li>Redirect a User to the Service Provider authorization page. Here the User signs in and authorizes the Server to access protected resources. Then the Service Provider redirects the User to the address written in oauth_callback (step 1) with oauth_token and oauth_verifier parameters.</li>
<li>Using previously received oauth_token, the Server requests an access token. This is quite similar to the process of obtaining the request token, but for signature generating we use oauth_token and oauth_verifier from the previous step and ignore the oauth_callback parameter. The Service Provider returns oauth_token (our Access Token) and oauth_token_secret in response.</li>
<li>Send a request to get our User&#8217;s contact list, using the Access Token.</li>
</ol>
<p>Let&#8217;s see how this authorization method works in Postman. Postman has the necessary field set, it can pass the authorization data both in query parameters and in the authorization header, and also calculates a digital signature automatically depending on the chosen signature generation method.</p>
<p>Let&#8217;s use our favorite <a href="https://docs.postman-echo.com/#2f79ab5b-9029-56c2-7b05-52047790d670">postman-echo</a> for testing. This resource provides the endpoint for signature verification (as you see, this is an essential part of this authorization method).</p>
<p>Create a new GET request on <a href="https://postman-echo.com/oauth1">https://postman-echo.com/oauth1</a> and select OAuth 1.0 as an authorization method. Put <strong>RKCGzna7bv9YD57c</strong> and <strong>D+EdQ-gs$-%@2Nu7</strong> values in the Consumer key and Consumer Secret fields respectively. As one can notice, the &#8220;<strong>Add authorization to</strong>&#8221; field allows you to choose where to add the authorization data. This is how the request looks like if we send the data using query parameters:</p>
<p><a ref="magnificPopup" href="https://testmace.com/blog/wp-content/uploads/2018/12/PostMan-Authorization-4.png"><img class="alignnone wp-image-8133 size-full" src="https://testmace.com/blog/wp-content/uploads/2018/12/PostMan-Authorization-4.png" alt="" width="1611" height="936" srcset="https://testmace.com/blog/wp-content/uploads/2018/12/PostMan-Authorization-4.png 1611w, https://testmace.com/blog/wp-content/uploads/2018/12/PostMan-Authorization-4-300x174.png 300w, https://testmace.com/blog/wp-content/uploads/2018/12/PostMan-Authorization-4-1024x595.png 1024w" sizes="(max-width: 1611px) 100vw, 1611px" /></a></p>
<p>If you do it right, the Service Provider will report that the signature verification was successful.</p>
<p><a ref="magnificPopup" href="https://testmace.com/blog/wp-content/uploads/2018/12/PostMan-Authorization-5.png"><img class="alignnone wp-image-8134 size-full" src="https://testmace.com/blog/wp-content/uploads/2018/12/PostMan-Authorization-5.png" alt="" width="520" height="179" srcset="https://testmace.com/blog/wp-content/uploads/2018/12/PostMan-Authorization-5.png 520w, https://testmace.com/blog/wp-content/uploads/2018/12/PostMan-Authorization-5-300x103.png 300w" sizes="(max-width: 520px) 100vw, 520px" /></a></p>
<p>If you already have an access token, you can type it in the corresponding authorization parameters field and send your requests to the authorized part of your application.</p>
<h3>Conclusion</h3>
<p>In this article we&#8217;ve discussed several authorization methods. In terms of authorization, Postman is much more powerful though. OAuth 2.0, Hawk and some more specific authorization methods are left aside today. Well, that&#8217;s a nice reason to get back to this topic one day, isn&#8217;t it? 🙂</p>
]]></content:encoded>
			<wfw:commentRss>https://testmace.com/blog/2018/12/03/8127/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Your First Postman Test</title>
		<link>https://testmace.com/blog/2018/11/22/8082/</link>
		<comments>https://testmace.com/blog/2018/11/22/8082/#respond</comments>
		<pubDate>Thu, 22 Nov 2018 05:56:57 +0000</pubDate>
		<dc:creator><![CDATA[Dmitriy Snytkin]]></dc:creator>
				<category><![CDATA[API learning]]></category>

		<guid isPermaLink="false">https://testmace.com/blog/?p=8082</guid>
		<description><![CDATA[Introduction Postman is a tool used by both client/server applications testers and developers to interact with API. Having appeared as a tool for sending simple requests, Postman has now drastically increased functionality, being able to deal with much wider range of tasks. However many of its features are &#8220;hidden&#8221; due to historical reasons and product...]]></description>
				<content:encoded><![CDATA[<h3><strong>Introduction</strong></h3>
<p>Postman is a tool used by both client/server applications testers and developers to interact with API. Having appeared as a tool for sending simple requests, Postman has now drastically increased functionality, being able to deal with much wider range of tasks. However many of its features are &#8220;hidden&#8221; due to historical reasons and product positioning. This article is here to shed light on one of those features, namely requests testing.</p>
<h3><strong>Postman Installation</strong></h3>
<p>Postman is available as a native application for Windows, Linux and MacOS operating systems. Check out the link to download your version (<a href="https://www.getpostman.com/apps">https://www.getpostman.com/apps</a>).<br />
<img class="alignnone size-full wp-image-8090" src="https://testmace.com/blog/wp-content/uploads/2018/11/Your_First_Postman_Test_1.jpg" alt="" width="628" height="279" srcset="https://testmace.com/blog/wp-content/uploads/2018/11/Your_First_Postman_Test_1.jpg 628w, https://testmace.com/blog/wp-content/uploads/2018/11/Your_First_Postman_Test_1-300x133.jpg 300w" sizes="(max-width: 628px) 100vw, 628px" /></p>
<p>If you are a Windows or MacOS user, just run the installer and follow the instructions. The Linux version comes as a tar.gz file, so you need to:</p>
<ol>
<li>Unzip the file.</li>
<li>Create a desktop file (optional). This will let you run Postman by double-clicking the icon and identify the app in different application launchers including system ones. Create a file by name Postman.desktop in ~/.local/share/applications with the following content:</li>
</ol>
<pre><code >&#091;Desktop Entry&#093;<br />
Encoding=UTF-8<br />
Name=Postman<br />
Exec=YOUR_INSTALL_DIR/Postman/app/Postman %U<br />
Icon=YOUR_INSTALL_DIR/Postman/app/resources/app/assets/icon.png<br />
Terminal=false<br />
Type=Application<br />
Categories=Development;<br />
YOUR_INSTALL_DIR is the path to the folder where Postman executable is stored.<br />
</code></pre>
<h3><strong>Running Postman</strong></h3>
<p>Now you can find Postman in application launchers. Once you have Postman running, you can sign up on https://www.getpostman.com/ and sign in the app or ignore this step. Note that authorization allows to synchronize your data that might be helpful while working in a team.</p>
<p>In Linux-based systems there are a few issues you should pay attention to:</p>
<ol>
<li>Don&#8217;t run the app as root This might cause some problems in further using of application (especially for unprivileged users).</li>
<li>Make sure the running user has read/write permission for ~/.config folder. This is where Postman stores the data.</li>
<li>Ubuntu 18 users will need a libgconf-2-4 package. It was removed from default Ubuntu packages, but may easily be installed by the command</li>
</ol>
<pre><code >sudo apt-get install libgconf-2-4</code></pre>
<h3><strong>Interface Overview</strong></h3>
<p>Let&#8217;s take a look at the request interface. We&#8217;ll need it for writing the test in the future. The main purpose of Postman, as mentioned above, is to perform HTTP-requests. That is why the request interface is the first thing we see after running the app.</p>
<p><img class="alignnone size-full wp-image-8090" src="https://testmace.com/blog/wp-content/uploads/2018/11/Your_First_Postman_Test_2.jpg" alt="" width="628" height="279" /></p>
<p>The top bar contains URL and request method (GET, POST, PUT, PATCH, etc.). Click the Params button to set the request parameters.</p>
<p>You can see several tabs just below. Let&#8217;s take a closer look at them.</p>
<p>Authorization. This allows to configure authorization methods for the request. Postman has an impressive list of the most common authorization methods. We are not going to change this parameter, thus we won&#8217;t focus on it and just move on.</p>
<p>Headers. As the name implies, this tab allows to change the request headers list. A very useful feature is the autocomplete menu both with header names and values list. However the list of autocompleted header values is limited to the content types list only. In fact the value set doesn&#8217;t depend on the header name, that may eventually lead to errors.</p>
<p>For headers editing you can use either spreadsheet-style edit mode (Key-Value Edit) or text edit mode (Bulk Edit). Unfortunately, there is no autocomplete feature here, but if you have a headers list in a special format (for instance, task description from bug tracker), this mode comes in handy.</p>
<p><img class="alignnone size-full wp-image-8090" src="https://testmace.com/blog/wp-content/uploads/2018/11/Your_First_Postman_Test_3.jpg" alt="" width="628" height="279" /></p>
<p>Body: This tab is available for some methods (GET in particular) and allows you to add the request body. The request body interface is quite similar to the request header editing interface but still has its own features.</p>
<ol>
<li>You can set the required content type choosing from form-data, x-www-form-urlencode, raw, and binary types. Those types, except for interface part, influence on Content-Type header.</li>
<li>Every type has a description field. That is quite convenient, you can make something like API description.</li>
<li>The field value can be either text or file.</li>
</ol>
<p>If you choose the raw request body type, you can edit the request body in a raw form &#8211; the very body that is going to be sent to the server. This is not so useful, but having set the appropriate Content-Type header, we can edit the body with syntax highlighting (xml, javascript, json or html).<br />
<img class="alignnone size-full wp-image-8090" src="https://testmace.com/blog/wp-content/uploads/2018/11/Your_First_Postman_Test_4.jpg" alt="" width="628" height="279" /></p>
<h3><strong>Request Sending</strong></h3>
<p>Let&#8217;s send our first request. For the experiment I&#8217;m using <a href="https://github.com/toddmotto/public-apis">one of numerous free APIs</a> &#8211; <a href="https://github.com/HackerNews/API">https://github.com/HackerNews/API</a>. Here you can find an example of a GET request <a href="https://hacker-news.firebaseio.com/v0/item/8863.json?print=pretty">https://hacker-news.firebaseio.com/v0/item/8863.json?print=pretty</a>.</p>
<p><img class="alignnone size-full wp-image-8090" src="https://testmace.com/blog/wp-content/uploads/2018/11/Your_First_Postman_Test_5.jpg" alt="" width="628" height="279" /></p>
<p>That&#8217;s a typical GET request with parameters. Now let&#8217;s dig into response parameters tabs, that are at the bottom of the screen.</p>
<p>The Body tab contains the response body. As you might have noticed, highlighting can be changed here. But in most cases you won&#8217;t have to do that &#8211; it is set depending on the Content-Type response. You can also view the response body with no highlighting in Preview mode. This mode is helpful while viewing rendered content of an HTML response.</p>
<p>And the last thing we haven&#8217;t discussed on this tab is the line break button. As you can guess, it enables breaking long lines.</p>
<p>Cookies tab is unavailable here since this request doesn&#8217;t contain any cookies. We&#8217;ll get into Cookies tab features next time.</p>
<p>Headers tab is quite reserved. No mode changing, no highlighting. Just a key-value list.</p>
<p><img class="alignnone size-full wp-image-8090" src="https://testmace.com/blog/wp-content/uploads/2018/11/Your_First_Postman_Test_6.jpg" alt="" width="628" height="279" /></p>
<p>We have dived in the basic Postman features to deal with HTTP requests, which can help us in testing. At the same time we&#8217;ve left behind some exciting ones as variables, environment, collections, etc. It has already been said that Postman has become something more than a simple tool for sending requests. And that&#8217;s not only about tests, if you just have a look at that New drop-down menu.</p>
<p><img class="alignnone wp-image-8090" src="https://testmace.com/blog/wp-content/uploads/2018/11/Your_First_Postman_Test_7.jpg" alt="" width="265" height="404" /></p>
<p>This truly is an impressive list.</p>
<h3><strong>Writing tests</strong></h3>
<p>Finally, we are here to create our first test. You can find the test editor under the Test tab of the request builder. Simple as that &#8211; there is an edit box on the left and snippets list on the right. Snippets allow to create test templates and help inexperienced testers in their work, but software development skills are highly important with Postman as all tests are written in JavaScript.</p>
<p><img class="alignnone size-full wp-image-8090" src="https://testmace.com/blog/wp-content/uploads/2018/11/Your_First_Postman_Test_8.jpg" alt="" width="628" height="279" /></p>
<p>In our case, we need the snippet &#8216;Response body is equal to a string&#8217;. Choose that and Postman will generate a test template.<br />
<pre><code >pm.test("Your test name", function () {<br />
  var jsonData = pm.response.json();<br />
  pm.expect(jsonData.value).to.eql(100);<br />
});<br />
</code></pre>
Let&#8217;s have a closer look at the script. To create a test we call the test method of pm object with parameters &#8216;Your test name&#8217; (here you can place either the test name or short info about the test and its expected results) and the callback (the function, that is called within by Postman after running the test). Put this in the callback body:</p>
<pre><code >var jsonData = pm.response.json();</code></pre>
<p>Convert the response from JSON to JavaScript object:</p>
<pre><code >pm.expect(jsonData.value).to.eql(100);</code></pre>
<p>Check if the value received from the object is equal to 100. That&#8217;s pretty much it, we only need to add our data to the test. Change the last line to:</p>
<pre><code >pm.expect(jsonData.id).to.eql(8863);</code></pre>
<p>Here we check if the id of the received object is the same as requested id (8863). Now you see, there&#8217;s no problem with writing a test having all those snippets ready to help.</p>
<p>Resend the request to run the test. Now we can see the results of our test on the Response panel under the Test tab.</p>
<p><img class="alignnone size-full wp-image-8090" src="https://testmace.com/blog/wp-content/uploads/2018/11/Your_First_Postman_Test_9.jpg" alt="" width="628" height="279" /></p>
<p>Congratulations, the test &#8220;Your test name&#8221; was successfully run!</p>
<p>And what if it wasn&#8217;t? Let&#8217;s change the id to irrelevant one:</p>
<pre><code >pm.expect(jsonData.id).to.eql('wrong id');</code></pre>
<p>After sending the request Postman says that your test failed:</p>
<p><img class="alignnone size-full wp-image-8090" src="https://testmace.com/blog/wp-content/uploads/2018/11/Your_First_Postman_Test_10.jpg" alt="" width="628" height="279" /></p>
<h3><strong>Conclusion</strong></h3>
<p>In this article we&#8217;ve discussed basic features, that help in writing tests. Unfortunately, JavaScript skills are essential for working with Postman. To this end, Postman loses the game to SoapUI. However, snippets make things easier. Besides, the language is quite easy to learn (as compared to built-in Groovy in SoapUI). Anyway, automation tests is a new step in testing, and using this approach you can significantly increase the quality of your product.</p>
]]></content:encoded>
			<wfw:commentRss>https://testmace.com/blog/2018/11/22/8082/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
