Sublime and BDD

A simple guide about how to write formatted BDD features in Sublime. – Download what you want in Package Control. If you don’t have the package control in your sublime, follow these steps: – Open the console:

ctrl ` shortcut

– If your sublime is 2:

import urllib2,os,hashlib; h = 'eb2297e1a458f27d836c04bb0cbaf282' + 'd0e7a3098092775ccb37ca9d6b2e4b7d'; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); os.makedirs( ipp ) if not os.path.exists(ipp) else None; urllib2.install_opener( urllib2.build_opener( urllib2.ProxyHandler()) ); by = urllib2.urlopen( 'http://packagecontrol.io/' + pf.replace(' ', '%20')).read(); dh = hashlib.sha256(by).hexdigest(); open( os.path.join( ipp, pf), 'wb' ).write(by) if dh == h else None; print('Error validating download (got %s instead of %s), please try manual install' % (dh, h) if dh != h else 'Please restart Sublime Text to finish installation')

– If your sublime is 3:

import urllib.request,os,hashlib; h = 'eb2297e1a458f27d836c04bb0cbaf282' + 'd0e7a3098092775ccb37ca9d6b2e4b7d'; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); by = urllib.request.urlopen( 'http://packagecontrol.io/' + pf.replace(' ', '%20')).read(); dh = hashlib.sha256(by).hexdigest(); print('Error validating download (got %s instead of %s), please try manual install' % (dh, h)) if dh != h else open(os.path.join( ipp, pf), 'wb' ).write(by)

– Hit Enter and restart the sublime after downloaded the package.

  How to install Packages from Package Control ?

– ‘Command+Shift+P’ – Type ‘Install Package’ and enter

– Choose the package as :

Cucumber

Gherkin[Cucumber] Formatter

Behat

Behat Snippets

How to use ?

You can try any of these commands to generate respective file.

– ‘Command+Shift+P’ – Type: ‘Gherkin’

– ‘Command+Shift+P’ – Type: ‘Feature’

– ‘Command+Shift+P’ – Type: ‘Scenario’ or ‘Scenario Outline’

– ‘Command+Shift+P’ – Type: ‘Example’

  If you want some snippet of Given/When/Then/etc, you can use the command  ‘Command+Shift+P’ – Type: ‘Given’

Screen Shot 2015-04-01 at 21.46.24

Easy and very useful, for this reason I like Sublime ! lol Thank you guys 🙂

Sourceshttp://shashikantjagtap.net/speed-up-your-bdd-with-sublime-text-2/ https://packagecontrol.io/installation

Behat, Mink and Selenium

Hello guys !

I will explain a simple tutorial of “How can you use BDD with Selenium and PHP.”

– First thing you have to install Behat:

– Install Composer

– Create a composer.json file in your root directory

1
2
3
4
5
6
7
8
9
{
“require”: {
“behat/behat”: “2.4.*@stable”,
“behat/mink”: “1.5.*@stable”,
“behat/mink-goutte-driver”: “*”,
“behat/mink-extension”: “*”,
“behat/mink-selenium2-driver”: “*”
}
}

 

– Run composer install

– Create a behat.yml file

 

1
2
3
4
5
6
7
8
default:
paths:
features: features
bootstrap: %behat.paths.features%/bootstrap
extensions:
Behat\MinkExtension\Extension:
goutte: ~
selenium2: ~

 

– Initialize your Behat project with vendor/bin/behat –init. Note: bin directories are configurable in composer.json. If your composer file has a bin directory, use that path instead of vendor/bin.

– Create a feature file, e.g. test.feature
1
2
3
4
5
6
7
8
9
10
Feature: Drupal.org search
In order to find modules on Drupal.org
As a Drupal user
I need to be able to use Drupal.org search
@javascript
Scenario: Searching for “behat”
Given I go to “http://drupal.org
When I search for “behat
Then I should see “Behat Drupal Extension

 

– Edit FeatureContext.php to extend from MinkContext. Note: You will need to add the use statement, use Behat\MinkExtension\Context\MinkContext. Run vendor/bin/behat

– Second Step: Adding Selenium as an optional driver

– Download Selenium Server

– Run java -jar /path/to/selenium-server-standalone-2.37.0.jar

– Add selenium2: ~ to your behat.yml

– Add a @javascript tag above your scenario

– Run vendor/bin/behat

– Third Step: Adding new step definitions

– Add the step you want to create in your scenario, e.g.

– When I search for “behat” Run vendor/bin/behat

– Copy the step definition template to FeatureContext.php and replace the PendingException with your code.

1
2
3
4
5
6
7
8
/**
* @When /^I search for “([^”]*)”$/
*/
public function iSearchFor($arg1)
{
$this->fillField(‘Search Drupal.org’, $arg1);
$this->pressButton(‘Search’);
}

 

Resources: http://lin-clark.com/blog/2013/11/26/quickstart-testing-with-behat-mink-selenium/