Skip to content

Instantly share code, notes, and snippets.

@Gbahdeyboh
Last active November 23, 2021 04:32
Show Gist options
  • Save Gbahdeyboh/df93263ab1a23a60e4431e8005b749b2 to your computer and use it in GitHub Desktop.
Save Gbahdeyboh/df93263ab1a23a60e4431e8005b749b2 to your computer and use it in GitHub Desktop.
This gist contains the answers to the challenge for the technical community management role at postman.

Postman Technical Community Manager Challenge

The below are responses to the challenge questions of the Technical Community Management role at Postman.

Community Forum Engagement

Hypothetical Questions

So that my responses to the hypothetical questions feel as it would if I were responding to an actual person on the community forum, I created an hypothetical person named James. James will be the one asking the questions I will be providing answers to. So just incase you see me use the name James in any of my responses, know that I am referring to the hypothetical person who asked the question.

Question 1

Guys, it's been almost a year since this issue was posted. Should this have been properly handled, you could have had an implementation half a year ago. Please, raise the priority of this feature request!

Answer 1

Hi @James.

Thank you for pointing this out! I apologize if the implementation of this issue is taking longer than you expected. We have a huge backlog of issues, features, bug fixes, feature requests, etc.

We select from this pool of issues and add them to our Public Roadmap. Asides from the roadmap, we have created several Projects on Github that is intended to track the progress of issues and feature requests made across all of our projects. This makes it very difficult for us to miss out on any of them.

Your feedback is very much appreciated and is needed for us to keep building a Postman loved by all. I will like you to know that this issue was not abandoned. We will get to it soon and I will do my best to keep you posted on any updates regarding it.

Let me know if you have any more questions. Thanks!


Question 2

How can I use Postman in my CI process? Our team uses TravisCI.

Answer 2

Hi @James, this is an interesting question and requires that you do a few things.

TL;DR

You can write tests scripts in your Postman collection, use Postman APIs to get your collection in JSON format, then use Newman to run the tests on this collection in your Travis CI pipeline. It gives you a new and very convenient way to test your APIs.

Long Answer

Postman provides a way that lets you write test scripts for your requests and collections. There is a command-line tool called Newman that lets you run your collections and it's respective tests on the command line. You can use this tool in your CI process and it works with any CI(including Travis CI).

To save you some Googling and extra reading up, I have highlighted some simple steps that show you how you can get started with using Postman on your CI, explained each of them in more detail, and provided useful links that you can check out to learn more. I've written this so you can just follow the exact same steps without having to read a lot of documentation. However, if you want to learn beyond the scope of what I've highlighted below, you should definitely look up the linked URLs.

  • Write Postman tests scripts for your collection requests.
  • Fetch your collections over a GET request using POSTMAN API.
  • Run your collections tests using Newman.
  • Add Newman to your CI(Travis CI) pipeline.

WRITE POSTMAN TESTS SCRIPTS FOR YOUR COLLECTION REQUESTS

Postman lets you write tests for each of the requests in your collection. There is a Tests section on your request navigation bar. Screenshot 2021-11-22 at 1 02 42 PM

I have added an example test that makes a GET request to https://jsonplaceholder.typicode.com/posts and checks if it has a status code of 200.

pm.test("Post Status test", function () {
    pm.response.to.have.status(200);
});

Sending this request will run the tests. You can find the result in the test section of the response navigation bar.

Screenshot 2021-11-22 at 1 09 02 PM

You can read about how to write your own custom tests scripts in Postman here.

FETCH YOUR COLLECTIONS OVER A GET REQUEST USING POSTMAN API

The next step will be to fetch the collection you wrote tests for above.

The easiest way of getting your collection that you will often find is by exporting it as a JSON file. But this won't work quite well with CIs because you have to export a new file each time you update your collection. Another way would be to publish your collection to a public URL. This has two caveats:

  1. The public URL makes your collection accessible by anyone who has that URL.
  2. Each time you update your collection, you have to regenerate that URL for the update to occur.

The two ways above are quite popular and suit other use cases, but you shouldn't use them on a CI. CIs are meant to be automated and it defeats the whole automation thing.

The best approach is to use the Postman API.

First, you need to generate an API key that gives you access to your workspace. You can generate a new key here.

Copy and keep this key safe, it will be eventually used as a secret in your CI pipeline.

To get access to the specific collection you want to test, you need its collection ID. You can fetch a list of collections and get the ID from there. Send a GET request to this endpoint https://api.getpostman.com/collections?apikey=<Your-API-KEY>

It will respond with an array of your collections, look through this array for the specific collection you want to test and get its ID.

Next, send a GET request here https://api.getpostman.com/collections/<collection-id>?apikey=<Your-API-KEY>. This will return the specific collection you need and this URL will be used to run the tests in your collection using Newman.

ADD NEWMAN TO YOUR CI(TRAVIS CI) PIPELINE

Newman is a command-line tool that lets you run your postman collections and tests on the command line. Since Newman is a command-line tool, it can be used in your Travis CI.

First, you need to install Newman. Add a command to install Newman in your .travis.yml file.

install:
- npm install newman

Then, you need to add a script to run Newman against your collection

script:
- npx newman run <link-to-your-collection>

Now, your postman scripts run every time your CI runs.

You can read more about this here. My approach to fetching the collections was slightly different as I feel it should be completely automated and you shouldn't have to export the collection again if something changes on it.

I know this was a bit lengthy to read, but I hope it was worth it as it was intended to get you to spend less time researching.

Let me know if you have any questions. Cheers!


Question 3

I have a bunch of JUnit tests written already. Is there a way to transfer these tests over to Postman? And does Postman work with Cucumber? And do these result in HTML?

Answer 3

Hi @James.

Currently, there is no way to transfer JUnit tests to postman. The test has to be written with postman test scripts.

Also, Postman does not work with Cucumber yet, but postman provides a CLI tool called Newman that can be used to programmatically run your postman collections.

As regards the last question, you can export your postman reporter results as an HTML file. This comment might be quite helpful.

If you feel transferring Junits tests to postman, or support for cucumber is something that would be beneficial to our broader community, I will recommend that you make a feature request on our Github page from this link. GitHub is the forum where our team picks up the issue and provides early resolutions. It is how we keep track of the bugs/feature requests.


Question 4

How can I get all the Houses that have “words” using the Game of Thrones API? And how can I output the words of each house to the console? [create a collection and share it with this user that can be accessed publicly]

Answer 4

Hi @James.

There are two sides to your question.

Get houses that have words

The Game of Thrones API provides an endpoint that gives you a list of all houses. {Base URL}/api/houses.

This endpooint can take in filter parameters that lets you filter the data it returns. One of the filter parameter it provides is the hasWords parameter. This parameter is a boolean that lets you return houses that has words or not.

You can send a GET request to the https://www.anapioficeandfire.com/api/houses endpoint and set the hasWords filter paramter to true. i.e https://www.anapioficeandfire.com/api/houses?hasWords=true on Postman.

I have created a public collection that does this for you already. You should check it out here

Screenshot 2021-11-23 at 2 47 32 AM

Output words of each house.

Postman lets you log values to the console before or after a request. You can add console.log scripts to either the Pre-request Script or the Tests navigation tab(just right below the address bar) to log values before or after a request completes respectively on Postman. In your case, you need to log the response of the request, which means the request has to be completed first and hence makes the Tests section the ideal place to place your scripts.

You can get the response of the request in JSON format using the below script.

pm.response.json()

To log the words of each house, add the below script to your Tests tab.

const response = pm.response.json()

response.forEach(({name, words}) => {
    console.log(`'${ name }' has words: ${ words }`)
})

It gets the response of the request as JSON(ideally, this returns an array), loops through it and logs the words of each of the house returned. This script has also been added to the collection I previously shared above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment