timjroberts / cucumber-js-tsflow

Provides 'specflow' like bindings for Cucumber.js in TypeScript 1.7+.
MIT License
133 stars 34 forks source link

Access world object (this) #40

Closed okkes closed 1 year ago

okkes commented 5 years ago

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.

kferrone commented 4 years ago

I have discovered where the WorldObject goes.

Simply:

this._worldObj
thees commented 4 years ago

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

timjroberts commented 3 years ago

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.

jthomerson commented 3 years ago

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.

JSLadeo commented 2 years ago

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