Showing posts with label Postman. Show all posts
Showing posts with label Postman. Show all posts

Friday, February 10, 2017

Postman - Embed 'Run in Postman' button in Visual Studio Online

Today we managed to embed Postman button in Visual Studio Online dashboard.




Why should we embed this? The Run button in Postman opens a collection of API endpoints directly in the user’s Postman app. By embedding this in your documentation, you'll be able to link a collection of endpoints and workflows that help developers onboard onto your API faster.

What should we do to have this?
First of all, you need to include a new widget type in Visual Studio Online.
You must have permissions to add new widgets.


Then, you need to add a new dashboard tile:


The next steps are to install a widget from Extension Gallery.


Visual Studio Online administrator will need to approve your request. Once this is approved you'll be able to see the new widget in the available list.

Next, you need to obtain embedded code from Postman. Follow these steps:
1. Click on the collection you would like to embed and hit Share


2. Shift to the Embed Button tab


3. Click in Generate Code. This will upload the collection to Postman servers


4. Select an environment, if you want to export it

5. Hit Copy to Clipboard

Now, you need to include this embedded code into your Visual Studio Online widget. Add a new widget of type IFrame Dashboard Widget. Copy the text in Url field, choose a title and a dimension and, what is most important, before the copied text add this data:text/html,<html><body>, at the end add this </body></html>. You have the freedom to customize the widget as you wish. All you have to do is to write html code. There is only one limitation: Url field should not exceed 4000 characters.

When you'll press Run in Postman button, you'll need to right click on Postman for Chrome + open in a new tab, and after this, Postman app. will be opened and will import the collection and/or environment automatically. One observation: the environment will be duplicated every time you'll import it. So, make sure to delete the old one if you already performed an import.
Use Chrome to follow these steps.

That's it. 

Happy testing and... make it green, becomes a dream :).

Monday, January 9, 2017

Postman - Extracting login token and using it in requests

Introduction


Postman is a powerful GUI platform to make your API development faster & easier, from building API requests through testing, documentation and sharing. In this article we'll show you how to:

- take the token from your login post and use it later for authorization in later requests
- define environment variables and use them in requests
- test your API by testing response code, response time, response body content, etc.
As example, we are going to test this workflow: 
- login to https://www.pincello.com
- create a new timeline

* Pincello is a beta web application that allows you to make professional timelines quickly that is the Web  version of a PowerPoint addin (for more details visit https://www.officetimeline.com/).

Extract token data from login
Postman gives the possibility to extract values from the response and saving it inside an environment or a global variable. Environment and global variables let you keep track of everything that affects API state. Some examples of common variables you would use with an API are session tokens, user IDs, file IDs.
What are the steps for taking the token from login:

1. Launch Postman Chrome Extension
2. Create a new collection (from the top left part)


3. Name it, for example Pincello Testing


4. Open Manage Environments (from the top right part)


5. Add a new environment, e.g. Pincello and add a new key, e.g. token. Leave the value empty.


6. Set this environment (Pincello) to the current collection (Pincello Testing)


6. Post login data and extract via Test tab the access_token and then place it in the environment variable.
In this case we need to create a new request with
- url = {{url}}/token, where {{url}} is another environemnt variable that represents your url that you want to test
- type POST
- body, in this case of type x-www-form-urlencoded with some inputs, those values are stored also as environment variable


*every call to an environment variable is made by using environment key value with {{}}


- you then need to go to Test tab and place the result of post response in token environment variable. To do this, white this javascript code in your Test tab



7. Write tests for login request, e.g. response time, response status code = 200. To do this add tests to your Test tab from Code list


8. Every request after login, will require an authorization, thus, we should add Authorization header for the next requests like in the image below, by using the token previously extracted.


9. Continue with your API testing. Here are some examples:




10. Run the tests


11. Check your tests results



Happy testing and... make it green, becomes a dream :)

Popular Posts