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

Expose Profiles to step definitions #2314

Open
michael-lloyd-morris opened this issue Aug 17, 2023 · 1 comment
Open

Expose Profiles to step definitions #2314

michael-lloyd-morris opened this issue Aug 17, 2023 · 1 comment
Labels
⚡ enhancement Request for new functionality

Comments

@michael-lloyd-morris
Copy link
Contributor

🤔 What's the problem you're trying to solve?

Commander, the CLI parser in use, throws an error if there are unrecognized arguments on the CLI. So something like cucumber-js --debug doesn't work. Profiles are a partial workaround in that they can be tied to World Parameters, and they can be overloaded so the last profile in the chain will win. Hence cucumber-js -p firefox -p phone could be used to run a test with the firefox browser using phone dimensions.

The problem arises in that the BeforeAll and AfterAll hooks can't see the world parameters. Neither can step bodies. With Playwright the most efficient setup is to start the browser before all, then refresh the context before each test so that each test gets its own context. This avoids the overhead of restarting the browser for each test which can add up in a large enough suite.

✨ What's your proposed solution?

Expose the loaded profiles as an array so that it can be imported and examined, like so

import { profiles } from "@cucumber/cucumber"

if ( profiles.includes("debug") ) {
  // do something that you'd only do while the debug profile is loaded.
}

⛏ Have you considered any alternatives or workarounds?

It is possible to independently examine the cli arguments using process.argv, but it's tedious and needs a tool in place if the check needs to be in multiple places. Cucumber already processes the argv so why not expose part of the work already done.

📚 Any additional context?

For this suggestion to be quickly added profiles need to be loaded before step definitions are. Since command line arguments have to be processed before step loading (as step locations can be specified on the CLI) I believe this is already the case, but if it isn't doing this feature becomes significantly more difficult.

I'm suggestion just the names of the loaded profiles to keep the scope down. It should be possible to expose the parsed arguments, including the World Parameters, but I fear problems with separation of concerns if that wide a tool is provided. In the example given debug could be an empty profile in and of itself, but some of the things you might want to do in debug is relax or even remove timeout considerations, and the most frequent use for debug is to have a browser go into headed mode where it presents the GUI during the test.

@michael-lloyd-morris michael-lloyd-morris added the ⚡ enhancement Request for new functionality label Aug 17, 2023
@davidjgoss
Copy link
Contributor

Step bodies can see this.parameters, but yeah BeforeAll is where you have a problem currently. I wouldn't be keen to have profiles (a means of managing configuration) accessible from steps (the execution layer where configuration should long have been resolved).

But #1393 should solve this, because it will make the world parameters available from those global hooks. There was a draft PR there which seems to have stalled; I'd suggest giving it a ping to see if it's abandoned, and if so that can be freely picked up.

In the meantime, I think the best workaround would be avoid the CLI and set some environment variables externally - you can then pick these up in your config file, hooks and steps (including on parallel workers).

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

No branches or pull requests

2 participants