cucumber-js-tsflow icon indicating copy to clipboard operation
cucumber-js-tsflow copied to clipboard

Access world object (this)

Open okkes opened this issue 4 years ago • 5 comments

Is there any way to access/inject the world object to the step definitions?

In order to attach a screenshot to cucumber-html-reporter, I need to call this.attach() method, but that won't work in typescript as the attach method doesn't exist.

okkes avatar Oct 07 '19 07:10 okkes

I have discovered where the WorldObject goes.

Simply:

this._worldObj

kferrone avatar May 11 '20 19:05 kferrone

Type support would be nice. Otherwise you cannot access this with typescript except marking it with //ts-ignore

thees avatar Sep 02 '20 12:09 thees

As the above mentioned ticket eludes, tsflow is adapting CucumberJS to make it more object-oriented. The idea is that the class itself becomes your world (since this would represent a reference to the instance of your class). It was all originally conceived as an experiment with TypeScript decorators, but CucumberJS has moved on since then - this repo hasn't. Perhaps it's time for a refresh.

timjroberts avatar Nov 06 '20 10:11 timjroberts

Yes, the state class makes a lot of sense in the context of cucumber-tsflow, and works really well. The one missing piece is that with the Cucumber CLI, you can supply --world-parameters, a JSON object, and those are fed into the world. This really helps with things like building on multiple environments, so you can pass in dynamic configuration to your test suite.

If the tsflow state objects could take those parameters as an optional argument to their constructor, I think that would be really helpful.

jthomerson avatar Nov 06 '20 14:11 jthomerson

Hello, I got the same problem: cant attach a screenshot to multiple-cucumber-html-reporter with typescrypt. I try use "this._worldObj" but not working too. My version : . Node : 16.15.1 . "cucumber-tsflow": "^4.0.0-preview.7" . "typescript": "^4.7.4"

private _worldObj: any; @after() public async after(scenario: any, callback: any){ await this.driver.takeScreenshot().then((stream) => { this._worldObj.attach(stream, 'image/png'); fs.writeFileSync('error.html', ); //callback(); }) } I try lot of thing but in this case i replace "scenario" by "this._worldObj" after i declare it as private to attach fonction. Here i got error: "Cannot attach when a step/hook is not running. Ensure your step/hook waits for the attach to finish" If someone know a simple way to configure attach screenshot to a scenario, or tell me how to go ahead of this problem . Would be awesome. Thanks

JSLadeo avatar Jun 30 '22 07:06 JSLadeo