Showing posts with label postman. Show all posts
Showing posts with label postman. Show all posts

Asynchronous requests with Postman's PM API

0

Category : , , ,

You can send requests asynchronously with the pm API method sendRequest, these can be used in the pre-request or the test script.

Its important to note that if you send an asynch request in the pre-request tab "The main Postman request will NOT be sent until the pre-request script is determined to be finished with all callbacks, including sendRequest."

A blog post containing more detailed info on this can be seen on the below link:
http://blog.getpostman.com/2017/10/03/send-asynchronous-requests-with-postmans-pm-api/

I have only done basic testing with this but I could get the method to fire using the 2nd example of the 3 available on the previous url:
var headers = ['reseller_id:' + environment.booking_api_reseller_id];
    headers.push('request_id:'+ environment.booking_api_request_id);
    headers.push('request_authentication:'+ environment.booking_api_request_authentication);
console.log(headers);

// Example with a full fledged SDK Request
const echoPostRequest = {
  url: environment.booking_api_host + '/v1/Availability/product/' + environment.booking_api_availability_productKey + '?fromDateTime=' + environment.booking_api_availability_start_date + 
        '&toDateTime=' + environment.booking_api_availability_end_date,
  method: 'GET',
  header: headers,
  body: {
    mode: 'raw',
    raw: JSON.stringify({ key: 'this is json' })
  }
};

pm.sendRequest(echoPostRequest, function (err, res) {
    console.log('..............here........');
    console.log(err ? err : res.json());
});

I was having issues passing the headers to the request but i found the below url which states the header param should be an array.
http://www.postmanlabs.com/postman-collection/Request.html#~definition

Reuseable scripts in Postman

0

Category : , , ,

You can reuse methods across requests in postman.

Tip #5 in the below list:
http://blog.getpostman.com/2017/07/28/api-testing-tips-from-a-postman-professional/

  1. Init in Pre-Request or Tests tab or in a previous request.
  2. Store in an Environment or Global variable.
  3. Then call multiple times from other requests.
1) Setup method in Pre-Request or Tests tab in Postman, you can also list params to pass to method.
postman.setEnvironmentVariable("commonTests", (responseBody, environmentSchema) => {
    
    // parse response and log
    var responseObject = JSON.parse(responseBody);
    //console.log("response: " + JSON.stringify(responseObject));

    // test to check status code
    tests["Status code is 200"] = responseCode.code === 200;
    
    // test response time
    console.log("responseTime: " + responseTime);
    tests["Response time is less than " + environment.max_server_response_time + "ms"] = responseTime < environment.max_server_response_time;
    
    // validate schema
    eval(environment.validateSchema)(responseObject, environmentSchema);
});

2) Call method from the Pre-Request or Tests tab in Postman.
You can also call methods from within another method as you can see at the end of the previous code sample.

    // validate schema
    eval(environment.commonTests)(responseObject, environment.specificSchema);

Automate Postman Tests with Newman

0

Category : , , ,

Newman is a command-line collection runner for postman.

1) So the first step is to export your collection and environment variables.

2) Save the JSON file in a location you can access with your terminal.

3) Install Newman CLI globally, then navigate to the where you saved the collection.

4) Once you are in the directory, run the below command, replacing the collection_name with the name you used to save the collection.
newman run "collection_name.json" -e GITHUB_ENV.postman_environment.json
5) Ensure you add the -e flag which is for the environment param.

6) You may also want to specify the -d flag for a data file and the --insecure switch to allow calls to self signed certs.


You should see something like the below:





my thanks to the great article below.
https://scotch.io/tutorials/write-api-tests-with-postman-and-newman#newman-cli

Postman BDD allows you to use BDD syntax to structure your tests and fluent Chai-JS syntax to write assertions. So the above test suite could look like this instead:
https://github.com/BigstickCarpet/postman-bdd

API Test Automation CI using GitHub, Jenkins, and Slack

First few steps are the same as above i.e. export the postman tests and environment.

Probably start at Step 2: Setup Your Jenkins Build

npm commands

Get npm installed version
npm -version
Get npm installion directory
npm root -g
Get list of installed packages
npm list -g --depth=0


my thanks to the great post below:
https://www.linkedin.com/pulse/api-test-automation-ci-using-github-jenkins-slack-talal-ibdah?trk=mp-reader-card

API with SSL Cert on IIS

0

Category : ,

Steps involved in getting an API up-and-running on IIS7

IIS non-secure

  1. Host WCF Service on IIS
  2. Add web site on IIS
  3. Change AppPool on IIS to correct .Net framework
  4. Add DNS record to point test.URL to IP
  5. Update IIs bindings to link Host Name and port number to new url test.URL

Generate self-signed SSL Cert

There can only be 1 ssl cert per IP address so we need to use a wildcard cert that can be applied to multiple urls.

Link cert to site

Add additional binding to site on IIS, this will be for https and the self-signed cert name will need to start with a * to ensure we can enter a Hostname and that multiple sites can use the same self-signed cert on the server.

Updating the WCF web.config to handle https requests

Change the behaviorConfiguration to https and also the bindingConfiguration needs to be updated to the below

  
    
  
  
    
  



  
    
  

Testing Https with Postman

Exception for self-signed needs to be made in postman, instructions for mac and windows can be found for Postman here:
Sending requests to URLs with self signed SSLs
Using self-signed SSL certificates with Postman
Using self-signed SSL certificates with the Postman App, you just need to go to the settings and turn off the SSL cert verification. here

Postman Intro

1

Category : , ,

Postman is an app that we use for testing during our API development. Basically sending requests to our API dev project to test responses and functionality.

Postman docs are available here: Postman Docs

The docs also contain a couple of videos to get you up-and-running and there is a youtube channel: Postman How-to Series

Basic Usage

You can send most request method types using Postman, including Query string params, request body info, headers containing authentication info and retrieve/view responses in any format, we predominantly worked with JSON on our API. You can also work with cookies but we have not used this yet.

Extracting data from responses and chaining requests

You can extract data from response and chain requests using test scripts.

1) Sett up a new environment with variables.
2) Create environment variable to store data and allow multiple requests to access data.
3) set value for new variable and then access with next request.
// set Environment Variable
var jsonData = JSON.parse(responseBody);
postman.setEnvironmentVariable("token", jsonData.token);

// access in request body
{
   "data" : {
           "status": "my_status",
           "token": "{{token}}"
   }
}
There is another helpful blog post on this here

Explanation Of API Chaining

Creating cURL commands in Postman

To create a cURL command in Postman.

Testing in Postman

We can write tests to validate the schema returned in response and various errors that are expected.
// parse response
var jsonData = JSON.parse(responseBody);

// create schema
var schema = 
{
    "type": "object",
    "properties":  {
                    "data": {
                        "type": "object",
                        "properties": {
                                        "reservationReference": {"type": "string"}
                                        }
                            }
                    }
};

// validate schema
tests["Valid Response Schema"] = tv4.validate(jsonObject, schema);

Postman Sandbox

The Postman Sandbox is a JavaScript execution environment that is available to you while writing pre-request scripts and test scripts for requests (both in Postman and Newman). Whatever code you write in the pre-request/test script section is executed in this sandbox.

JSON Schema Validation

Tiny Validator for JSON Schema v4
JSON Schema Examples
Understanding json schemal


my thanks to this great blog post:
http://www.tjmaher.com/2016/07/introduction-to-api-testing-with.html