Skip to content
soyukaPublic
forked from Behatch/contexts

About

Behat extension with most custom helper steps

Resources

Code of conduct

Contributing

Security policy

Stars

28 stars

Watchers

2 watching

Forks

 
 

Repository files navigation

Behatch contexts

CI

Behatch contexts provide most common Behat tests.

Installation

This extension requires:

  • PHP 8.1+
  • Behat 3.20+ or 4
  • Mink
  • Mink extension

Project dependency

  1. Install Composer
  2. Require the package with Composer:
$ composer require --dev soyuka/contexts
  1. 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: ~

Project bootstraping

  1. 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.

Usage

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:xml

Examples

This project is self-tested, you can explore the features directory to find some examples.

Configuration

  • browser - more browser related steps (like mink)
    • timeout - default timeout
  • debug - helper steps for debugging
    • screenshotDir - the directory where store screenshots
  • system - shell related steps
    • root - the root directory of the filesystem
  • json - JSON related steps
    • evaluationMode - javascript "foo.bar" or php "foo->bar"
  • table - play with HTML the tables
  • rest - send GET, POST, ... requests and test the HTTP headers
  • xml - XML related steps

Configuration Example

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"

About

Behat extension with most custom helper steps

Resources

Code of conduct

Contributing

Security policy

Stars

28 stars

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages