Cuke JVM Scen Outline: Accessing current Scenario Outline row in the @Before hook in Cucumber-JVM

10 views
Skip to first unread message

br...@qualityhabit.com

unread,
Apr 10, 2018, 9:36:32 AM4/10/18
to Cukes
Hi all,

Can anyone point me to the right way to access current scenario outline row in the @Before hook in cucumber jvm?  I'm looking to store an integration synchronization key there and would like to expose it in a common test context rather than wait for the step file to access it.  Cucumber 1.2.5/Gherkin 2.12.2 had something like this available through a Scenario ID hack, but having trouble finding the same in current Cucumber 2.4.0/Gherkin 5.0.0 release.

I did look through code and samples before posting and had found that the Pickle.class seems to have rendered this by the time "runPickle()" of the Runner.class is executed, but you have to know what step renders it, and you have to know what text to look for (not to mention kluge your way to that data).  I was hoping it would be available directly in the Scenario.class, but this seems to have been removed or changed at some point since the 2.0.0 Cucumber release.

I'm currently investigating something along the lines of below and then using that to access fields inside the class that renders the Examples row during execution.. 
    private static Object getPrivateField(Object subject, String fieldName) throws NoSuchFieldException, IllegalAccessException {
        Field f = subject.getClass().getDeclaredField(fieldName);
        f.setAccessible(true);
        return f.get(subject);
    }

Any help would be much appreciated!
Brian Brewer
Reply all
Reply to author
Forward
0 new messages