Thursday, December 18, 2014

Using Q promises with node.js http requests

This post is intended at providing a code snippet on how to use Q promises with node.js http requests.

I was introduced to the concept of promises and deferred when I found myself uncomfortable writing asynchronous functions within callbacks.

The code is not:
1. Maintanable
2. Readable
3. Intuitive

That is when I stumbled on JQuery Deffered and Promises. Once I got a hang of it I came across the Q Library that does pretty much the same thing with node.js.

I found it difficult to apply it to node.js http requests and after I gave it more time I got a hang of it.

The following gist demonstrates on how to wrap the the node.js http request with the q library.

In the gist we are attempting to invoke the Google News API using the node.js http requests.


Wednesday, October 1, 2014

Soap UI Groovy Set POST Parameter

The following code snippet show how we can set a POST parameter value in a testStep in soapui using groovy


Tuesday, September 30, 2014

SoapUI Groovy Set Headers to Test Steps

During the development of my project we had to develop multiple REST endpoints.

A call to each of these REST endpoints needed to be authenticated by passing an oauth-token in their header.

Post development we had to change the core REST endpoints code to incorporate design changes.

In such situations it is necessary to do a quick regression test before pushing the code to QA.

In the following groovy snippet in soap ui we do the following:

1. Get the oauth token from the first test step
2. Parse the JSON reponse (refer to my previous post)
3. Iterate through each of the test steps and set the headers for each of them


SoapUI Groovy parse json

I came across a situation where I had to use groovy scripts in to test some REST endpoints that return JSON responses.

So following is a groovy code snippet which does the following:
1. Import the json parsing library
2. Fetch the JSON response from a test step
3. Parse the JSON response
4. Access properties in the JSON response

Wednesday, September 24, 2014

Selenium Web Driver node.js set chrome options

The following code snippet demonstrates on how to set command line options to the chrome webdriver in selenium.

Here we are using the selenium-webdriver npm available for node.js




Thursday, July 17, 2014

CURLOPT_SSL_VERIFYPEER option for PHP

When trying to use curl with PHP to invoke REST API, we encounter an error and on googling it the simple fix suggested is to set the CURLOPT_SSL_VERIFYPEER option to false.

It turns out that if CURLOPT_SSL_VERIFYPEER is set to false on production systems then API calls could become victims to Man In the middle attachs

The ideal way to resolve this error is to follow the following instructions

1. Download the CA root certificate bundle from http://curl.haxx.se/docs/caextract.html
2. Then set a path to it in your php.ini file, e.g. on Windows:
    eg. curl.cainfo=c:\php\cacert.pem
3. Restart your php instance