带黄瓜AfterStep钩的量角器抛出TypeError:Cucumul_2.AfterStep不是一个函数

时间:2020-11-12 15:55:42

标签: typescript protractor cucumber

我正尝试运行一个黄瓜功能文件,并且在测试的每个步骤之后,我想在cumul html报告中捕获一个屏幕截图。我使用了AfterStep钩子,如下所示(我也使用了After,Before和BeforeAll钩子,它们都可以正常运行):

import { AfterStep } from "cucumber";

AfterStep(async function() {
  const screenshot = await browser.takeScreenshot();
  this.attach(screenshot, "image/png"); 
});

当我尝试运行测试时,出现错误

E/launcher - Error: TypeError: cucumber_2.AfterStep is not a function
    at Object.<anonymous> (SmokeTest\hooks\ScenarioHook.ts:64:1)
    at Module._compile (internal/modules/cjs/loader.js:1158:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
    at Module.load (internal/modules/cjs/loader.js:1002:32)
    at Function.Module._load (internal/modules/cjs/loader.js:901:14)
    at Module.require (internal/modules/cjs/loader.js:1044:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at SmokeTest\node_modules\cucumber\lib\cli\index.js:142:42
    at Array.forEach (<anonymous>)
    at Cli.getSupportCodeLibrary (SmokeTest\node_modules\cucumber\lib\cli\index.js:142:22)
    at SmokeTest\node_modules\cucumber\lib\cli\index.js:169:41
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (SmokeTest\node_modules\cucumber\lib\cli\index.js:44:103)
    at _next (SmokeTest\node_modules\cucumber\lib\cli\index.js:46:194)

我试图修改node_modules/@types/cucumber/index.d.ts文件并在其中添加以下内容:

export interface Hooks {
   AfterStep(code: HookCode): void;
}

还用以下条目修改了node_modules/cucumber/dist/cucumber.js

var AfterStep = methods.AfterStep;
exports.AfterStep = AfterStep;
...
function () {
    ...
    AfterStep: this.defineTestRunHook('afterTestRunHookDefinitions'),
    ...
}

但是,我仍然会遇到此错误。在使用BeforeAll,Before,After挂钩时,我不必进行所有这些修改。 PS:使用的黄瓜版本5.1.0,量角器5.4.2,打字稿3.6.2

0 个答案:

没有答案
相关问题