Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protractor with cucumber AfterStep hook throws TypeError: cucumber_2.AfterStep is not a function #1473

Closed
kalebhushan opened this issue Nov 12, 2020 · 3 comments

Comments

@kalebhushan
Copy link

I am trying to run a cucumber feature file and I would like to capture a screenshot in the cucumber html report after each step of the test. I used a AfterStep hook as follows (I have also used After, Before and BeforeAll hooks all of which run fine):

import { AfterStep } from "cucumber";

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

When I try to run my test, I get an error

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)

I tried to modify the node_modules/@types/cucumber/index.d.ts file and added the following there:

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

Also modified the node_modules/cucumber/dist/cucumber.js with the following entry:

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

However, I still face this error. I didn't have to do all these modifications while using BeforeAll, Before, After hooks. PS: cucumber version used 5.1.0, protractor 5.4.2, typescript 3.6.2

@luke-hill
Copy link

Different languages have different support structures for the hooks. So bare this in mind.

It looks like your using CucumberJS. I believe that doesn't support AfterStep. But I'll let someone else confirm. That might be why it's giving you an error.

Check docs here https://cucumber.io/docs/cucumber/api/#hooks and alter your language accordingly. You'll see each language has slightly different support

@aslakhellesoy aslakhellesoy transferred this issue from cucumber/common Nov 18, 2020
@davidjgoss
Copy link
Contributor

Hi @kalebhushan - we just merged support for BeforeStep and AfterStep via #1416 in the last couple of days, and it's not released yet but should be very shortly with 7.0.0.

@kalebhushan
Copy link
Author

Perfect. Thank you so much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants