question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add Step information in @BeforeStep and @AfterStep hook

See original GitHub issue

Currently, we can only access Scenario level information in @BeforeStep & @AfterStep, it would be really great having step level information like, step name, line no, etc.

This will help to add implementation like, common step level log.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:15
  • Comments:33 (13 by maintainers)

github_iconTop GitHub Comments

9reactions
laeubicommented, Feb 3, 2021

Is there a complete description somewhere what event contain what information and when they are are and so on for the plugin API? Maybe that’s not always clear, I personally just look at existing plugins and start a debugger to see whats going really on but if you have found your way its very powerful but have the following limitations:

  1. You need to write extra code on a different API that has much more “power” that one probably need for this simple case (access additional information about the Step the annotation is targeting)
  2. You need to “glue” somewhere your Plugin code with your step-code most likely via static fields as (correct me if I’m wrong) plugins can’t participate in the DI mechanism as they are instantiated by Cucumber in a very early stage
  3. You need to make sure your plugin is actually included in the run
  4. Hooks can be contained to only run on given tags for example, that’s of course possible for a plugin but requires extra handling if placed in a plugin

on the other hand the proposed style:

@BeforeStep
public void before_step(Scenario scenario, Step step){

}

makes it clear what happens here (no side-band communication) and is something that one intuitively would expect, why should a before-stepp hook should not know about the step?

4reactions
darsh9292commented, May 8, 2020

Yes, I would agree with @bhreinb , why before_step can not be extended with additional information on a step, where its job is on step level. Then we should not inject the Scenario object as well.

My purpose in raising this request was, I want this step log information on the console log just for additional log information. Also, sometimes I faced, the runner goes into the infinite mode, but I don’t know where it was exactly stopped executing.

This will help in case we will not have a final report at all.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cucumber Hooks - Baeldung
First, our two @Before hooks execute. Then before and after every step, the @BeforeStep and @AfterStep hooks run, respectively. Finally, the @ ...
Read more >
After Step and before Step Cucumber - java - Stack Overflow
BeforeStep and AfterStep hooks are available in the latest cucumber jvm api. Just update your pom with the latest version for cucumber-jvm.
Read more >
[cucumber-jvm] @BeforeStep and @AfterStep Usage example
So I want to get the step name and step status, and can be added to the ... Hook, like @BeforeStep and @AfterStep,...
Read more >
What are Cucumber Hooks And How to Use ... - Tools QA
Cucumber supports hooks, which are blocks of code that run before or after each scenario. You can define them anywhere in your project...
Read more >
Hooks - SpecFlow's documentation
In order to use hooks, you need to add the Binding attribute to your class: ... If you need to execute specific steps...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found