Skip to content

Instantly share code, notes, and snippets.

@arnold-almeida
Last active December 17, 2015 22:29
Show Gist options
  • Save arnold-almeida/5682658 to your computer and use it in GitHub Desktop.
Save arnold-almeida/5682658 to your computer and use it in GitHub Desktop.
Boilerplate for Behat with Mink on Php 5.4+ with contexts and subcontexts
# The default profile is always named default.
default:
extensions:
Behat\MinkExtension\Extension:
base_url: 'http://domain.test'
goutte:
guzzle_parameters:
request.params:
redirect.disable: true
#
# switch disable followings if use behat/mink-selenium2-driver
#
# selenium: ~
# javascript_session: selenium
#
# switch enable followings if use behat/mink-selenium2-driver
#
# javascript_session: selenium2
# browser_name: 'firefox'
# selenium2:
# capabilities: { "browser": "firefox"}
{
"require-dev" :
{
"behat/behat": "2.4.*@stable",
"behat/mink": "1.4@stable",
"behat/mink-extension": "*",
"behat/mink-goutte-driver": "*",
"behat/common-contexts": "*"
},
"minimum-stability": "dev",
"config":
{
"bin-dir": "bin/"
}
}
<?php
/**
* Reading :
*
* - http://www.craftitonline.com/2011/08/behat-symfony-2-secret-how-to-subcontext-minkcontext/
* - http://www.craftitonline.com/2011/07/behat-mink-new-use-of-aliased-subcontexts-complex-step-chaining/
* - http://davidwinter.me/articles/2012/01/14/testing-javascript-websites-with-behat/
* - http://davidwinter.me/articles/2012/01/13/using-behat-with-mink/
*/
use Behat\Behat\Context\ClosuredContextInterface,
Behat\Behat\Context\TranslatedContextInterface,
Behat\Behat\Context\BehatContext,
Behat\Behat\Exception\PendingException;
use Behat\Gherkin\Node\PyStringNode,
Behat\Gherkin\Node\TableNode;
/**
* Provides dictionary for common tasks (Filling in a form etc.)
*
* Check with :
* `behat -dl`
*/
use Behat\MinkExtension\Context\MinkDictionary;
/**
* Provides
* - pageShouldExist, pageShouldNotExist etc.
*
* Check with :
* `behat -dl`
*/
use Behat\CommonContexts\MinkExtraContext;
/**
* Provides dictionary for testing redirects
*/
use Behat\CommonContexts\MinkRedirectContext;
//
// Require 3rd-party libraries here:
//
// require_once 'PHPUnit/Autoload.php';
// require_once 'PHPUnit/Framework/Assert/Functions.php';
//
/**
* Features context.
*/
class FeatureContext extends BehatContext
{
// Mink hooks
use MinkDictionary;
/**
* 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)
{
// App sepecific
$this->useContext('UserSteps', new UserContext());
// Load in utility contexts
$this->useContext('TestStatusCodes', new MinkExtraContext());
$this->useContext('TestForRedirects', new MinkRedirectContext());
}
}
<?php
// Sample UserContext delete steps and put in your own
use Behat\MinkExtension\Context\RawMinkContext;
use Behat\MinkExtension\Context\MinkAwareInterface;
use Behat\Behat\Context\Step\When;
use Behat\Behat\Exception\PendingException;
class UserContext extends RawMinkContext implements MinkAwareInterface
{
// add step hooks here
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment