Closed mrsenzy closed 11 months ago
Could you elaborate by providing your step definition code and configuration?
Step definition:
Given("my color is {string}", async function(this: CustomWorld, color: string) {
console.log("Given Color: ", this.parameters.color)
this.parameters.color = color;
console.log("Given Color after assigning: ", this.parameters.color)
})
Then("my color should not be red", async function(this: CustomWorld) {
console.log("Then Color: ", this.parameters.color)
let favColor = this.parameters.color
if(favColor!="blue"){
logger.error("Assertion failed: ",favColor=="blue")
console.trace('trace')
}
expect(favColor).toStrictEqual("blue")
})
let common = [
'./e2e/features/**/*.feature',
'--require-module ts-node/register',
'--require ./e2e/stepDefinitions/**/*.ts',
'--require ./cucumber.config.ts',
'--format json:./report/report.json',
'--format html:./report/cucumberjs-report.html',
'--format progress-bar',
'--format @cucumber/pretty-formatter',
'--format rerun:@failedScenarios.txt',
].join(' ');
Thanks @mrsenzy. So, yeah, currently the world parameters are mutable from user code.
The normal pattern is to use world parameters as a source of arbitrary configuration, and set state on the world itself e.g. this.color = 'red'
- however it's important to have guard rails. I think we should address this by:
this.parameters
, those changes are gone once the scenario finishesSomewhat related to https://github.com/cucumber/cucumber-js/issues/2308, in that probably most things we pass to user code should be immutable (practically if not physically).
👓 What did you see?
For below scenarios, when i try to assign color to world parameter from first scenario as blue, it get retained until the red color from second scenario get assigned.
Scenario: Will pass Given my color is "blue" Then my color should not be red
Scenario: Will fail Given my color is "red" Then my color should not be red
✅ What did you expect to see?
When world is isolated for each scenario, shouldn't the parameters.color get undefined for second scenario before getting assigned with color red. Currently it is retaining the color blue from previous scenario
📦 Which tool/library version are you using?
@cucumber/cucumber: 10.0.1