With info.cucumber version i used to have this code to read feature name from feature file during runtime and it was working fine
**private String getFeatureFileNameFromScenarioId(Scenario scenario) {
String featureName = "Feature ";
String Feature = scenario.getId().split(";")[0].replace("-"," ");
return Feature;
}**
After upgrading cucumber version with list of dependencies which is latest out there
**io.cucumber cucumber-core 5.0.0-RC1 compile io.cucumber cucumber-java 5.0.0-RC1 compile io.cucumber cucumber-java8 5.0.0-RC1 compile io.cucumber cucumber-junit 5.0.0-RC1 compile io.cucumber cucumber-testng 5.0.0-RC1 compile**
The above code has stopped working and not returning "Feature name from feature file" during runtime.
Can someone out there please help suggest solution on this.
I dont know if it is still relevant but I got it by using:
/**
* Extracts the feature name from the feature file.
*
* @param filePath the path of feature file.
* @return String feature name or empty if encounters an error.
*/
public static String getFeatureName(String filePath) {
final String FEATURE_PATTERN = "Feature:";
File file = new File(filePath);
try {
List<String> data = Files.readAllLines(file.toPath());
for(String line : data) {
if(line.contains(FEATURE_PATTERN))
return line.substring(FEATURE_PATTERN.length()); //get everything after feature pattern
}
} catch (IOException e) {
e.getMessage();
}
return "";
}
Cucumber version: 6.11.0
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.