Behatch contexts provide most common Behat tests.
This extension requires:
- PHP 8.1+
- Behat 3.20+ or 4
- Mink
- Mink extension
- Install Composer
- Require the package with Composer:
$ composer require --dev soyuka/contexts
- Activate extension by specifying its class in your
behat.php:
// behat.php
use Behat\Config\Config;
use Behat\Config\Extension;
use Behat\Config\Profile;
use Behatch\Extension as BehatchExtension;
return (new Config())
->withProfile((new Profile('default'))
// ...
->withExtension(new Extension(BehatchExtension::class)));Or in your behat.yml (Behat 3 only, Behat 4 reads PHP configuration only):
# behat.yml
default:
# ...
extensions:
Behatch\Extension: ~- Download the Behatch skeleton with composer:
$ php composer.phar create-project behatch/skeleton
Browser, json, table and rest step need a mink configuration, see Mink extension for more information.
In behat.php, enable desired contexts:
// behat.php
use Behat\Config\Config;
use Behat\Config\Profile;
use Behat\Config\Suite;
return (new Config())
->withProfile((new Profile('default'))
->withSuite((new Suite('default'))
->addContext('behatch:context:browser')
->addContext('behatch:context:debug')
->addContext('behatch:context:system')
->addContext('behatch:context:json')
->addContext('behatch:context:table')
->addContext('behatch:context:rest')
->addContext('behatch:context:xml')));Or in behat.yml:
default:
suites:
default:
contexts:
- behatch:context:browser
- behatch:context:debug
- behatch:context:system
- behatch:context:json
- behatch:context:table
- behatch:context:rest
- behatch:context:xmlThis project is self-tested, you can explore the features directory to find some examples.
browser- more browser related steps (like mink)timeout- default timeout
debug- helper steps for debuggingscreenshotDir- the directory where store screenshots
system- shell related stepsroot- the root directory of the filesystem
json- JSON related stepsevaluationMode- javascript "foo.bar" or php "foo->bar"
table- play with HTML the tablesrest- send GET, POST, ... requests and test the HTTP headersxml- XML related steps
For example, if you want to change default directory to screenshots - you can do it this way:
(new Suite('default'))
->addContext('behatch:context:debug', [
'screenshotDir' => 'var',
])default:
suites:
default:
contexts:
- behatch:context:debug:
screenshotDir: "var"