在浏览protractor-jasmine2-screenshot-reporter npm软件包中的代码时,我注意到它包含一个beforeLaunch函数,该函数与其余函数一起导出。
我知道生命周期阶段按以下顺序运行,所以我的问题是: 当茉莉花对象本身在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;
}
我可能会从根本上误解了这里的某些行为,但希望有人能为我提供一些启示。
答案 0 :(得分:2)
量角器除了Jasmine钩子之外,还使用了额外的插件钩子并解决了这些问题。这些通常在量角器的运行器中解决。您可以在这里阅读插件: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)执行。这两个引用运行程序的文件是selenium 4升级分支的文件。由于这些版本没有可实现的承诺链,因此更容易查看。