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

Cucumber World constructor #10

Open
tkamsker opened this issue Oct 28, 2019 · 2 comments
Open

Cucumber World constructor #10

tkamsker opened this issue Oct 28, 2019 · 2 comments

Comments

@tkamsker
Copy link

We are using your implementation and are quite happy but for our tests we need scenario isolated context.(like https://github.com/cucumber/cucumber-js/blob/master/docs/support_files/world.md ) Do you plan to support it or know an way to make this happen ?
thx thomas

@hitmands
Copy link

hitmands commented Oct 8, 2020

you can use share context via:

cy.wrap({ msg: 'Hello World' }).as('world');

// and in a later step

cy.get('@world')

@osmolyar
Copy link

osmolyar commented Oct 8, 2024

Thank you for your maintenance of this great library! Unfortunately the use of aliases is not sufficient for a more complex case, particularly when using TypeScript, for example, as in the following custom world constructor,

`import FilterBusinessOptions from '../../businessOptions/filterBusinessOptions';
import _ from "lodash";

function CustomWorld() {
const options: Context = _.merge(
{},
new FilterBusinessOptions(),
{
page: "",
chart: "",
stackP: []
}
);
this.nav = {};
this.context=options;
this.httpOptions={};
}

export default CustomWorld`

where 'business option' type definitions for the data structures each type of page object (if using page objects) or service method (and therefore step definition calling the service methods) can accept are defined in potentially multiple type definition files. This is very useful for storing the data input to various steps for use in subsequent scenario steps - yes, we could do it using aliases or the setTo() example you provided but for a large application there are multiple type definition files with dozens of data object type definitions, with defaults, that get initialized in the cucumberWorldConstructor, and which would be extremely cumbersome to maintain in a before() hook.

Furthermore, the this.nav object stores instances of the instantiated page classes, and this.stackP maintains a dynamic array of the names of the visited pages (though suppose we could do that with the existing this, but Typescript would show warnings.)

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