Now Playing Tracks

Sleipnir: BDD for the Apple’s new Swift


Apple has announced new programming language at WWDC 2014 called as ‘Swift’. Apple will keep both objective C and Swift to support application development. Swift seems awesome, you can watch the introductory video of the swift to know more about Swift.


Sleipnir: BDD for the Swift

As soon as Swift comes in, there is BDD framework developed by the guys at railsware.[@railsware]. Thank you so much. There is a blog post about ‘BDD-style testing in Swift with Sleipnir

There is code available on the GitHub for the ‘Sleipnir

BDD-style framework in Swift
6 forks.
0 open issues.
Recent commits:

Can’t wait for the release of OSX Yosemite and xCode 6 to get started Swift and Sleipnir.


The post Sleipnir: BDD for the Apple’s new Swift appeared first on BDD Test Automation & Open-Source Tools.

via BDD Test Automation & Open-Source Tools

RESTful API Testing with Behat and Guzzle

Behat and Guzzle

Behat is a behaviour driven development framework for the PHP application. Behat can be used for acceptance testing and api testing.

Guzzle is PHP HTTP client to work with HTTP and web services. You can read more about Guzzle on the official website . We can use combination of the Behat and Guzzle for the testing of the REST API. In this post, we will see how to use Guzzle http  for testing GitHub web services.

Behat in Action

Let’s do some action now. We will install behat, create feature simple file and implement step definitions.

Installation & Config

Let’s create our composer.json to install all the dependencies with composer.

$ mkdir RESTful-Behat
$ cd RESTful-Behat
$ vim composer.json 

    "require": {
        "behat/behat": "2.4.0",
        "guzzle/guzzle": "2.4.*",
        "guzzlehttp/guzzle": "4.*"
    "config": {
        "bin-dir": "bin/"

Now, we need to download composer and install all these dependencies

$curl | php
$php composer.phar install

This will install all the dependencies in the ‘vendor’ directory. Now we will create config file for behat.

# behat.yml

Note, we have created basic config for the behat. Now initialise Behat so that, Behat will create ‘bootstrap’ directory and ‘FeatureContext.php’ file.

$ ./bin/behat --init

Create Feature file

In order to test the GitHub’s REST API with Behat, we need to create a feature file in the plain english. Our feature file should look like this:

$ vim github_rest_api.feature

Feature: GitHub RestFul Api Testing with Behat  

 As a behat user
 I want to test restful api of the GitHub
 So that it will bring smile for behat community

Scenario: GitHub behat Demo Api 
  Given I request "/repos/Shashikant86/BehatDemo" 
  Then the response should be JSON
  And the response status code should be 200
  And the response has a "name" property
  And the "name" property equals "BehatDemo"

As we read the feature file, we can understand that we are checking response format, response code and properties of the response a.k.a response body. At this point, we need to run ‘behat’ to get undefined steps. We need to implement these steps in the ‘FeatureContext.php’ file.

Step Definitions

Now, it’s time to implement step definitions using all the methods of the Guzzle Http library.

$ vim features/bootstrap/FeatureContext.php


use Behat\Behat\Context\ClosuredContextInterface,
use Behat\Gherkin\Node\PyStringNode,
use GuzzleHttp\Client;     

class FeatureContext extends BehatContext
    public $_response;
    public $_client;
    private $_parameters = array();
     * Initializes context.
     * Every scenario gets it's own context object.
     * @param   array   $parameters     context parameters (set them up through behat.yml)
    public function __construct(array $parameters)

        $this->_parameters = $parameters;
        $baseUrl = $this->getParameter('base_url');
        $client = new Client(['base_url' => $baseUrl]);
        $this->_client = $client;

    public function getParameter($name)
        if (count($this->_parameters) === 0) {
            throw new \Exception('Parameters not loaded!');
        } else {
            $parameters = $this->_parameters;
            return (isset($parameters[$name])) ? $parameters[$name] : null;

     * @When /^I request "([^"]*)"$/
    public function iRequest($uri)
        $request = $this->_client->get($uri);
        $this->_response = $request;

     * @Then /^the response should be JSON$/
    public function theResponseShouldBeJson()
        $data = json_decode($this->_response->getBody(true));
        if (empty($data)) { throw new Exception("Response was not JSON\n" . $this->_response);

     * @Then /^the response status code should be (\d+)$/
    public function theResponseStatusCodeShouldBe($httpStatus)
        if ((string)$this->_response->getStatusCode() !== $httpStatus) {
            throw new \Exception('HTTP code does not match '.$httpStatus.
                ' (actual: '.$this->_response->getStatusCode().')');

     * @Given /^the response has a "([^"]*)" property$/
    public function theResponseHasAProperty($propertyName)
        $data = json_decode($this->_response->getBody(true));
        if (!empty($data)) {
            if (!isset($data->$propertyName)) {
                throw new Exception("Property '".$propertyName."' is not set!\n");
        } else {
            throw new Exception("Response was not JSON\n" . $this->_response->getBody(true));
     * @Then /^the "([^"]*)" property equals "([^"]*)"$/
    public function thePropertyEquals($propertyName, $propertyValue)
        $data = json_decode($this->_response->getBody(true));

        if (!empty($data)) {
            if (!isset($data->$propertyName)) {
                throw new Exception("Property '".$propertyName."' is not set!\n");
            if ($data->$propertyName !== $propertyValue) {
                throw new \Exception('Property value mismatch! (given: '.$propertyValue.', match: '.$data->$propertyName.')');
        } else {
            throw new Exception("Response was not JSON\n" . $this->_response->getBody(true));

We have implemented all the steps to test GitHub REST API. At this point, we will see all the steps has been passing



The source code for this demo is available on the GitHub at ‘RESTful-Behat‘ repo. You can try this by yourself

 $ git clone
 $ cd RESTful-Behat
 $curl | php
 $php composer.phar install


Watch video demo of this demo on youtube


The post RESTful API Testing with Behat and Guzzle appeared first on BDD Test Automation & Open-Source Tools.

via BDD Test Automation & Open-Source Tools

FootBall Fever Mac Setup

FIFA Fever

FIFA world cup 2014 is going on in the Brazil and whole world is affected with football fever. Being big fan of the England football, I have setup my home and my Macs to fully support England. Unfortunately, England team wasn’t lucky enough to qualify but I have decorated our home with England flags.

Mac Setup

 You can watch more pics on my tumblr post.

Mac Hardware

Hardware has following

  • Two MacBook Pro 13″

One  with Mountain Loin  and other with OSX Mavericks.

  • JVC 40TW51JD Smart 40 ” LED TV [HDTV]

JVC HDTV  connected to the BT Home Hub 4 with an ethernet cable.

  • HDMI Cable

Belkin Mini DisplayPort  can found in any Apple Store.

  • iPhone 4S

To take pictures of the setup.

  • BT HomeHub 4 /Wireless Phone

Wireless and ethernet network.

  • Ethernet Cable, Tables and England flags

This is my home setup. I use this Apple gear for programming, blogging, watching live TV stream from internet and using social Media. Being a software professional, I use many latest open-source development/testing tools from terminal/iTerm so big screens would be helpful. This setup helped me in

  • Watching my favourite TV programmes on BBC especially Sports Football, Tennis, Snooker etc
  • Blogging
  • Easy Switch between TV and HDMI content.
  • Full Audio supports from HDTV to watch offline matches.

Favourite OSX Apps

There are many cool OSX apps available on the Apple Store.

  • xCode

xCode is used for the mobile app automation xCode with command line tools can easy many setup used for RubyGems. I installed xCode with command like tools read more about it here.

  • Jenkins

Jenkins is a open-source continuous integration server. I have downloaded OSX version of the Jenkins. Read my blog to know more about Jenkins setup

  • iTerm2

iTerm2  is the terminal replacement for the Mac OSX. iTerm 2 has lots of cool feature over terminal.

  • Sublime Text

Sublime  is a popular editor the web developers.  You can down load Sublime Text 2 for the OSX from the website.

  • Atom

Atom  is another open-source editor developed by Github. Atom has various packages in order to support web development process. You can download Atom for OSX from the download link. I have installed Atom editor on Mavericks

  • GitHub

GitHub app can be found on the OSX Apple Store. Web developers can then clone, commit, fork code from the GitHub App. It’s very handy.

  • Alfred

Alfred  is a productivity app for the Mac OSX. You can use it as alternative to spotlight. You can find Alfred on the Mac Apple Store.

  • Pocket

Pocket  is very useful for the bookmarking the web content so that we can read it later. You can also find Pocket app on the Mac Apple Store.

  • Vagrant

Vagrant  is a cool way to create a development environment on the fly. Developers can create virtual machines for the web development.

  • Quick Time Player

Quick Time Player is a simple way to record screencast.

  • The Next Web

The Next Web   and Mashable  are awesome app in order to know latest trends in the technology and social media. Both The Next Web and Mashable apps are available on Mac Apple Store.

Productivity Tricks

Some of you might know these tricks but I enjoy these tricks.

  • Change Application icons

I like to change the application icons of Mac OSX. I used to download OSX icons in the .icns format and replace it with the existing one. The idea is very simple, you just right click on Application—>Show Package Content —> Contents—> Resources. You should find existing .icns file here and you have to replace it with new one. That’s it ! 

  • Rename iTerm tab

Being a web developer everybody uses command line tools like terminal or iTerm 2. It would be better idea to name each tab of iTerm with the specific name. It can be easily done with ‘cmd+I’ and then type name of the tab and then press escape. Read my detailed blog  

Enjoy Football, Enjoy Mac OSX !

The post FootBall Fever Mac Setup appeared first on BDD Test Automation & Open-Source Tools.

via BDD Test Automation & Open-Source Tools

Cucumber Tip – Skip HTTP Auth with capybara and headless Drivers

HTTP Authentication

HTTP authentication is a mechanism of force use to user credential before entering into the website. While developing application, we might need to use HTTP authentication to restrict unauthorised user accessing site. You can read more HTTP auth  

While automating the pages with HTTP authentication we need to enter the login credentials to carry on test journey. Here is something we can do to skip HTTP auth

Set HTTP Headers

Headless capybara drivers provides mechanism to set HTTP headers before visiting page which skips http authorisation. There are Poltergeist and Mechanize  drivers for the capybara which allows us to set HTTP header. You can add those steps in the before hook.

Using Poltergeist

You can set HTTP header with Poltergeist to skip basic http auth like this. You need base64 for this

page.driver.headers = {'Authorization': 'Basic '+ Base64.encode64('username:password')};

Using Mechanize

You can set headers using mechanize like this:

page.driver.browser.agent.auth('username', 'password')

It become so simple to skip basic http auth using headless drives like Poltergeist and Mechanize.

Happy BDD

The post Cucumber Tip – Skip HTTP Auth with capybara and headless Drivers appeared first on BDD Test Automation & Open-Source Tools.

via BDD Test Automation & Open-Source Tools
To Tumblr, Love Pixel Union