Unable to get Scenario step text at runtime
See original GitHub issueI am trying to retrieve the Scenario step text at run time. This used to be possible in the Java implementation via reflection. See answer here:
Field f = scenario.getClass().getDeclaredField("testCase");
f.setAccessible(true);
TestCase r = (TestCase) f.get(scenario);
//You need to filter out before/after hooks
List<PickleStepTestStep> stepDefs = r.getTestSteps()
.stream()
.filter(x -> x instanceof PickleStepTestStep)
.map(x -> (PickleStepTestStep) x)
.collect(Collectors.toList());
However, with the more recent cucumber (from 4.8.0) this is no longer possible. I get the following error:
java.lang.NoSuchFieldException: testCase
Is there any other means to obtain the step text? I can do it with Cucumber.js via the Scenario.pickle object
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:16 (8 by maintainers)
Top Results From Across the Web
How to get all the cucumber scenario steps in before hook?
Try something like this: @Before public void setUp(Scenario scenario) throws Exception{ tags = (ArrayList<String>) scenario.
Read more >Cucumber - Scenario Outline - Tutorialspoint
Go to package explorer on the left hand side of Eclipse. · Expand the project CucumberTest. · Locate pom.xml file. · Right-click and...
Read more >Karate | Test Automation Made Simple.
Easily define all environments in a single file and share variables across all scenarios. Full script-ability via JS or Java interop. One nice...
Read more >Cucumber Hooks - Baeldung
Included are the scenario name, number of steps, names of steps, and status (pass or fail). This can be useful if we want...
Read more >Gherkin Reference - Cucumber Documentation
Feature: Guess the word # The first example has two steps Scenario: Maker ... you cannot have a Given , When , Then...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Your favourite answer for this 😉 Reporting/logging. I am aware that the plugin route is an option. However, we already have a fully working reporting mechanism working very well using the hooks. The only limitation we have is the fact we can’t retrieve the step text.
I have done something similar in cucumber.js along with SpecFlow (for .NET) so just seems a shame it’s not currently possibly with Java
It is not productive to discuss multiple separate issues on a closed ticket. Please open a new issue and take the time to describe the problem you are trying solve and in which ways you think Cucumber is deficient in that.