cucumber-jvm
cucumber-jvm copied to clipboard
read feature name from feature file during runtime
These are the cucumber dependency i have in my pom.xml.
When i try to read feature name from feature file during runtime using below line of code it return feature file path instead of feature name. Can someone please suggest how to read feature name from feature file during runtime with io.cucumber version
private String getFeatureFileNameFromScenarioId(Scenario scenario) { String featureName = "Feature "; String Feature = scenario.getId().split(";")[0].replace("-"," "); return Feature; }
What are you using the feature name for?
Thanks @mpkorstanje for getting back. I am using Feature name to create browserStack build so all scenarios to that specific feature file can store in that specific build.
This line in below code snippet "caps.setCapability("build", FeatureName);" where i am passing featureName from featureFile to create browserStack build during runtime.
DesiredCapabilities caps = new DesiredCapabilities();
ChromeOptions options = new ChromeOptions();
options.addArguments("--incognito");
options.setExperimentalOption("excludeSwitches", new String[]{"enable-automation"});
caps.setCapability(ChromeOptions.CAPABILITY, options);
caps.setCapability("browser", "Chrome");
caps.setCapability("browser_version", "70.0");
caps.setCapability("os", "OS X");
caps.setCapability("os_version", "Mojave");
// caps.setCapability("resolution", "1920x1080");
caps.setCapability("browserstack.debug", "true");
caps.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
caps.setCapability("build", FeatureName);
caps.setCapability("name", TestCaseName + "_CHROME");
try {
driver = new RemoteWebDriver(new URL(URL), caps);
} catch (MalformedURLException e) {
e.printStackTrace();
}
Configuration.timeout = 10000;
Configuration.baseUrl = brwoserURL;
driver.get(Configuration.baseUrl);
driver.manage().window().maximize();
WebDriverRunner.setWebDriver(driver);
Thanks Victor
Ah. I see. Normally I would recommend using the plugin system to make reports but this is obviously not possible in this case because you can must interact with your platform through the glue.
This isn't a use case that has come up before so it's currently not possible. However I don't see a reason not to make it possible. I can implement this along with #1870 but if you want to speed things up you can also send a pull request.
You'd add a String getFeatureName() method toScenario, TestCase and Pickle until you end up in GherkinVintagePickle. Once you've arrived there you can use the GherkinDocument to get the feature name.
Let's think more than twice before adding this. We do plan to add support for Markdown as an alternative to Gherkin, so anything new we add should use abstractions that aren't tied to Gherkin.
With Markdown there might not make sense to have a "Feature name". However, it might make sense to have a "Source file name" or something of the sort.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in a week if no further activity occurs.
This also was removed from cucumber-ruby in the 3.x->4.x update. So perhaps we need a general consensus if we want to keep the API's standard.
I had a similar requirement. Here is what solved my problem. Check this out if it solves your purpose.
public static String getFeatureNameFromScenario(Scenario scenario) { String[] test = scenario.getUri().toString().split("/"); String[] longFeatureName = test[test.length - 1].split("\."); return longFeatureName[0]; }
I am using cucumber latest version 7.7.0