承接 25th/behat-js-errorlog 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

25th/behat-js-errorlog

Composer 安装命令:

composer require 25th/behat-js-errorlog

包简介

README 文档

README

JS Error Logger Context for Behat 3.

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

To get this working you need to add a js snippet into the html code of your project.

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.

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

Installation

Just install via composer

Configuration

behat

Add the context to your behat confguration file. There are no Constructor Parameters

your application

You need to adjust your application to work with the context.

<!-- Catch JS Errors for Selenium-->
<script type="text/javascript">
    window.jsErrors = [];

    window.onerror = function (errorMessage) {
        window.jsErrors[window.jsErrors.length] = errorMessage;
    };
</script>

Depending if you are using a javascript framework you might to adjust to that as well

Angular

If you are using angular you might want to add your own exception handler to catch js errors.

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

统计信息

  • 总下载量: 16.64k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 9
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2015-04-10