PHPackages                             genesis/behat-fail-aid - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. genesis/behat-fail-aid

ActiveLibrary[Testing &amp; Quality](/categories/testing)

genesis/behat-fail-aid
======================

Get more out of your test suite by getting it to work with you when tests fail. Screenshots and more. Works with Goutte and MinkExtension.

3.7.5(3y ago)281.5M—0.1%6[8 issues](https://github.com/forceedge01/behat-fail-aid/issues)[3 PRs](https://github.com/forceedge01/behat-fail-aid/pulls)16MITPHP

Since Sep 7Pushed 1y ago1 watchersCompare

[ Source](https://github.com/forceedge01/behat-fail-aid)[ Packagist](https://packagist.org/packages/genesis/behat-fail-aid)[ RSS](/packages/genesis-behat-fail-aid/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (7)Versions (54)Used By (16)

Behat Fail Aid [![Master branch](https://github.com/forceedge01/behat-fail-aid/actions/workflows/ci-tests.yaml/badge.svg?branch=master)](https://github.com/forceedge01/behat-fail-aid/actions/workflows/ci-tests.yaml/badge.svg?branch=master) [![Latest Stable Version](https://camo.githubusercontent.com/5fb624f2af1c737fbc2a98b68d4087c32570b1451819dac5d95c142960dbed53/68747470733a2f2f706f7365722e707567782e6f72672f67656e657369732f62656861742d6661696c2d6169642f762f737461626c65)](https://packagist.org/packages/genesis/behat-fail-aid) [![Total Downloads](https://camo.githubusercontent.com/316400466f3a8817f2283bf7304c18081ed1ce987f9eced0f1f5faa2fddbf0bf/68747470733a2f2f706f7365722e707567782e6f72672f67656e657369732f62656861742d6661696c2d6169642f646f776e6c6f616473)](https://packagist.org/packages/genesis/behat-fail-aid) [![License](https://camo.githubusercontent.com/918ac13673a2d5e0d519838d7b1409b0df7f807183645227b494646738641884/68747470733a2f2f706f7365722e707567782e6f72672f67656e657369732f62656861742d6661696c2d6169642f6c6963656e7365)](https://packagist.org/packages/genesis/behat-fail-aid) [![Monthly Downloads](https://camo.githubusercontent.com/50e3629185af0f05f6042d5a3624b3f02bbd97a50db0e248f17c479646c0965b/68747470733a2f2f706f7365722e707567782e6f72672f67656e657369732f62656861742d6661696c2d6169642f642f6d6f6e74686c79)](https://packagist.org/packages/genesis/behat-fail-aid) [![Quality Gate Status](https://camo.githubusercontent.com/02ecac212fb09fad7f87720ed2492936b96cc73c6080563bf24756a088351512/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d666f7263656564676530315f62656861742d6661696c2d616964266d65747269633d616c6572745f737461747573)](https://sonarcloud.io/dashboard?id=forceedge01_behat-fail-aid) [![Maintainability Rating](https://camo.githubusercontent.com/f54eb3b40df8a20b260aa13dae4cf2edda219b0ee90b12193750de842d3c6aae/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d666f7263656564676530315f62656861742d6661696c2d616964266d65747269633d7371616c655f726174696e67)](https://sonarcloud.io/dashboard?id=forceedge01_behat-fail-aid) [![Security Rating](https://camo.githubusercontent.com/45ac07ea16bf1e18d7149ae3b5071a07c25cee8cf4569d65ac9e997b6d598628/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d666f7263656564676530315f62656861742d6661696c2d616964266d65747269633d73656375726974795f726174696e67)](https://sonarcloud.io/dashboard?id=forceedge01_behat-fail-aid)
==================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#behat-fail-aid--------)

Introduction
------------

[](#introduction)

Time and time again we've all seen how difficult and stressful it can become to fix behat tests. This package is their to help gather all possible information around failures and print them as you see a failure taking out the need to do basic investigations with minimal setup.

Usual failure [![Before](https://raw.githubusercontent.com/forceedge01/behat-fail-aid/master/extras/generic-from.png#version=1)](https://raw.githubusercontent.com/forceedge01/behat-fail-aid/master/extras/generic-from.png#version=1)

With fail-aid context [![After](https://raw.githubusercontent.com/forceedge01/behat-fail-aid/master/extras/generic-to.png#version=1)](https://raw.githubusercontent.com/forceedge01/behat-fail-aid/master/extras/generic-to.png#version=1)

With config options enabled [![More info](https://raw.githubusercontent.com/forceedge01/behat-fail-aid/master/extras/max-details.png#version=1)](https://raw.githubusercontent.com/forceedge01/behat-fail-aid/master/extras/max-details.png#version=1)

The links are ready to be clicked on and opened in the browser. No faff!

You also get the following step definitions for free upon activation:

```
And I take a screenshot
And I gather facts for the current state
```

These will output relevant information on the screen. (Your formatting must be pretty for this to work --format=pretty).

Whats new:
----------

[](#whats-new)

Major: Refactor, Controlled output, scenario debug cli, clear screenshots cli, host machine screenshot url.

Minor:

- Resolve environment variables for hostUrl and hostDirectory options.
- Execute screenshot code only if requested in output.
- Override output parameters through individual context file params.
- Override more output parameters.
- Set output.api parameter to true to set all mink related flags/operations to false for quick settings.

Patch: NA.

Installation:
-------------

[](#installation)

```
composer require genesis/behat-fail-aid --dev
```

CLI
---

[](#cli)

### Clear screenshots:

[](#clear-screenshots)

The `--clear-screenshots` flag, if supplied will remove existing screenshots from the directory specified.

### Scenario debug:

[](#scenario-debug)

The `--scenario-debug` flag, if supplied will take attempt to screenshots after each step and display in the console to aid debugging. Best used when working on a single scenario along with the autoclean feature.

### Wait on failure:

[](#wait-on-failure)

the `--wait-on-failure={seconds}` option can be used to investigate/inspect failures in the browser.

### Feedback on failure:

[](#feedback-on-failure)

the `--feedback-on-failure` flag can be used to print failures as soon as they occur. This is useful when using the progress formatter for example in long running test packs such as CI.

Config/Usage:
-------------

[](#configusage)

```
#behat.yml
default:
  suites:
    default:
      contexts:
        - FailAid\Context\FailureContext
  extensions:
    FailAid\Extension: ~
```

This is the basic setup and will give you a lot of information on failures. For more options read through the rest of the README. Any of the options below can be used in conjunction with each other.

Output options:
---------------

[](#output-options)

You can control the verbosity of the aid text from the config file. By default, all options are enabled.

```
default:
  extensions:
    FailAid\Extension:
      output:
        api: false # (Set this to true if testing against API's which don't use mink).
        url: false
        status: false
        tags: false
        feature: false
        context: false
        screenshot: false
        driver: false
        rerun: false
        debugBarSelectors: false
```

These params can be overridden for each FailureContext declaration in behat.yml

```
#behat.yml
default:
  suites:
    web:
      contexts:
        - FailAid\Context\FailureContext
    API:
      contexts:
        - FailAid\Context\FailureContext:
          - output:
            screenshot: false
  extensions:
    FailAid\Extension:
      output:
        screenshot: true
```

screenshot options:
-------------------

[](#screenshot-options)

```
#behat.yml
...
    FailAid\Extension:
      screenshot:
        directory: /temp/failures/behat/screenshots/
        mode: default
        autoClean: false
        size: 1444x1280
        hostDirectory: /tmp/$USER/failures/
        hostUrl: http://ci/failures/$BRANCH_NAME/$JOB_NUMBER/failures/
```

### directory (string):

[](#directory-string)

Override default screenshot path. Default folder is provided by `sys_get_temp_dir()` function. Can be a relative path.

### mode (string):

[](#mode-string)

default: Drivers will produce a png where supported, html otherwise.

html: All drivers will produce html screenshots, useful for interrogating runtime code.

png: All drivers will produce png screenshots, or die trying.

### autoClean (bool):

[](#autoclean-bool)

Clean up the directory before the test suite runs.

### Size (string):

[](#size-string)

The size of the screenshot to be taken on failure. At present, does not reset the size of the window. May conflict with the maximiseWindow API.

### hostDirectory (string):

[](#hostdirectory-string)

If running against a VM or container, you can set this path to the screenshots directory on the host machine. The screenshots will be produced the same, the output will be for your host machine instead. Resolves environment variables.

### HostUrl (string):

[](#hosturl-string)

If running on a remote environment it may be that the failures are available on a url. Resolves environment variables.

siteFilters option:
-------------------

[](#sitefilters-option)

```
#behat.yml
...
    FailAid\Extension:
      siteFilters:
        '/images/': 'http://dev.environment/images/'
        '/js/': 'http://dev.environment/js/'
```

Applied on the content of a html screenshot. Useful when working with relative urls for assets.

Tracking js errors/logs:
------------------------

[](#tracking-js-errorslogs)

You can easily track JavaScript activity on the page whenever a fail occurs. Place the following snippet in the head section of your application (make sure its global):

```

  window.jsErrors = []; window.jsWarns = []; window.jsLogs = [];
  window.onerror = function(error, url, line) {
      window.jsErrors.push('[Uncaught error]: ' + error + '; Line: ' + line);
  };

  if (!console) var console = {};
  var _privateError = console.error;
  console.error = function() {
    window.jsErrors.push('[Console error]: ' + JSON.stringify(arguments)); _privateError.apply(console, arguments);
  }

  var _privateWarn = console.warn;
  console.warn = function() {
    window.jsWarns.push('[Console warn]: ' + JSON.stringify(arguments)); _privateWarn.apply(console, arguments);
  }

  var _privateLog = console.log;
  console.log = function() {
    window.jsLogs.push('[Console log]: ' + JSON.stringify(arguments)); _privateLog.apply(console, arguments);
  }

```

Your original debugging messages will still appear in your console.

```
#behat.yml
...
    FailAid\Extension:
      defaultSession: chrome # If you've got multiple sessions registered. If its a standard setup you won't need this.
      trackJs:
        errors: true
        warns: true
        logs: true
        trim: 1000
```

When errors is enabled, any intended console.error calls and js exceptions will be recorded and displayed as part of the failure. Trim is applied on messages to shorten to the specified length.

debugBarSelectors option:
-------------------------

[](#debugbarselectors-option)

```
#behat.yml
...
    FailAid\Extension:
      debugBarSelectors: #Only CSS selectors allowed.
        'Status Code': '#debugBar .statusCode'
        'Error Message': '#debugBar .errorMessage'
        'Queries Executed': '#debugBar .executedQueries'
        xhrRequests:
          callback: MyXhrRequestsInfoExtractor::extract
```

The above will go through each of the selector and find the element. If the element is found, it will display the text contained in the failure output. The debug bar details are gather after taking a screenshot of the page, so its safe to navigate out to another page if needs be. If you have to do this, have a look at the 'Advanced Integration' section for more information.

defaultSession option:
----------------------

[](#defaultsession-option)

When you're using multiple sessions you can configure to use a particular session only with the fail aid extension.

```
...
    FailAid\Extension:
      defaultSession: mySession
...
```

Recording states:
-----------------

[](#recording-states)

You can record the state of your test for a failure. A state resets before each scenario.

```
# FeatureContext.php
