2017 © Pedro Peláez
 

library behat-js-errorlog

image

25th/behat-js-errorlog

  • Friday, April 10, 2015
  • by dready
  • Repository
  • 9 Watchers
  • 0 Stars
  • 7,001 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 1 Versions
  • 3 % Grown

The README.md

behat-js-errorlog

JS Error Logger Context for Behat 3., (*1)

The Context extends from Mink and was tested with the selenium2 driver. Basically it looks after every Step if there is an error present., (*2)

To get this working you need to add a js snippet into the html code of your project., (*3)

Selenium

The Context was tested soley with the selenium2 driver. There can be Situations that the check for js errors after a step can break the testcase. There was no reason why the setup behaves that way., (*4)

The only workaround was to introduce a ignore tag called ignore-js-error. Scenarios with that tag will not be checked in any way., (*5)

Installation

Just install via composer, (*6)

Configuration

behat

Add the context to your behat confguration file. There are no Constructor Parameters, (*7)

your application

You need to adjust your application to work with the context., (*8)







Depending if you are using a javascript framework you might to adjust to that as well, (*9)

Angular

If you are using angular you might want to add your own exception handler to catch js errors., (*10)

"use strict";

!function (angular) {

    var Module = angular.module('myModule');

    Module.provider("$exceptionHandler",
        {
            $get: ['errorLogService', function (errorLogService) {
                return (errorLogService);
            }]
        }
    );

    //
    // Factory to provider error log service
    // - simple console logger
    //
    Module.factory(
        "errorLogService",
        ['$log', function ($log) {

            function log(exception, cause) {
                // Default behavior, log to browser console
                $log.error.apply($log, arguments);

                // for selenium
                exception.message += ' (caused by "' + cause + '")';
                if ($window.jsErrors !== undefined) {
                    $window.jsErrors[$window.jsErrors.length] = exception.message;
                }
            }

            // Return the logging function.
            return (log);
        }]
    );

}(angular);

Scenarios

You don't need to adjust anything in your Scenarios to get this working. But there is way if you don't want the Context to run at a specific Scenario or a whole Feature File. You can use the tag @ignore-js-logging if you don't want any step to check for js errors., (*11)

The Versions

10/04 2015

dev-master

9999999-dev

  Sources   Download

The Requires

 

by Thomas Subera