首页 > 解决方案 > npm 包如何影响 Protractor 执行的 beforeLaunch 阶段?

问题描述

在查看 protractor-jasmine2-screenshot-reporter npm 包中的代码时,我注意到它包含一个 beforeLaunch 函数,该函数与其余函数一起导出。

我知道生命周期阶段按以下顺序运行,所以我的问题是:当 jasmine 对象本身在 onPrepare 阶段之前不可用时,这个记者怎么可能影响执行的 beforeLaunch 阶段?

--- beforeLaunch           
    --- onPrepare          (set in conf) ***reporters initialized here
      --- jasmineStarted   (set in reporter)
        --- beforeAll
         --- suiteStarted  (set in reporter)
          --- specStarted  (set in reporter)
           --- beforeEach  (set in testFile)
           +++ afterEach   (set in testFile)
          +++ specDone     (set in reporter)
         +++ suiteDone     (set in reporter)
        +++ afterAll
      +++ jasmineDone      (set in reporter)
    +++ onComplete         (set in conf)
+++ afterLaunch

protractor-jasmine2-screenshot-reporter 中的代码

function Jasmine2ScreenShotReporter(opts) {

  this.beforeLaunch = function (callback) {
  };

  this.afterLaunch = function (callback) {
  };

  this.jasmineStarted = function (suiteInfo) {
  };

  this.suiteStarted = function (suite) {
  };

  this.suiteDone = function (suite) {
  };

  this.specStarted = function (spec) {
  };

  this.specDone = function (spec) {
  };

  this.jasmineDone = function () {
  };

  return this;
}

我可能从根本上误解了这里的一些行为,但希望有人能为我阐明这一点。

标签: node.jsnpmjasmineprotractorjasmine-reporters

解决方案


Protractor 使用了额外的插件钩子,并在 Jasmine 钩子之外解决了这些问题。这些通常在 Protractor 的赛跑者中解决。您可以在此处阅读插件:https ://github.com/angular/protractor/blob/master/lib/plugins.ts#L25

例如,onPrepare插件在配置中检查(https://github.com/angular/protractor/blob/selenium4/lib/runner.ts#L63)并由运行器执行(https://github.com/angular /protractor/blob/selenium4/lib/runner.ts#L82)。引用 runner 的这两个文件用于 selenium 4 升级分支。查看这些版本更容易,因为它们没有一系列可用的 Promise。


推荐阅读