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

Allow scenarios to access suite configuration parameters #2745

Open
mpkorstanje opened this issue Apr 29, 2023 · 0 comments
Open

Allow scenarios to access suite configuration parameters #2745

mpkorstanje opened this issue Apr 29, 2023 · 0 comments
Labels
⚡ enhancement Request for new functionality
Milestone

Comments

@mpkorstanje
Copy link
Contributor

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

Users may want to run the same suite of feature files against multiple browsers. Currently this can only effectively be done by defining an environment variable and running Cucumber multiple times.

With JUnit 5 and TestNG it is possible to define suites that define these parameters externally. E.g:

@Suite
@IncludeEngines("cucumber")
@SelectClasspathResource("io/cucumber/examples/calculator")
@ConfigurationParameter(key = "projectname.browser", value = "firefox")
public class RunCucumberOnFirefoxTest {
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Run Cucumber" parallel="tests">
    <test name="Cucumber on Firefox">
        <parameter name="cucumber.features" value="classpath:io/cucumber/examples/calculator"/>
        <parameter name="projectname.browser" value="firefox"/>
        <classes>
            <class name="com.example.RunCucumber"/>
        </classes>
    </test>
</suite>

However there is no easy way to access the projectname.browser value within a Scenario.

✨ What's your proposed solution?

@Before
public void setupBrowser(Scenario scenario){
    Optional<String> browser = scenario.configurationParameters().get("projectname.browser");
    // Create browser here
}

We can use JUnit 5s ConfigurationParameters interface for inspiration.

⛏ Have you considered any alternatives or workarounds?

  1. Launching multiple test executions
  2. Using a ThreadLocal to pass information to scenarios e.g: https://stackoverflow.com/a/76136072/3945473

📚 Any additional context?

Doing this properly would require rewriting Cucumbers RuntimeOptions. Ideally cucumber would read properties on demand using the ConfigurationParameters rather than parsing everything ahead of time. So probably something to consider for v8.

@mpkorstanje mpkorstanje added the ⚡ enhancement Request for new functionality label Apr 29, 2023
@mpkorstanje mpkorstanje added this to the v8.0.0 milestone Apr 29, 2023
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

1 participant