Discussion:
[Cucumber] How to capture step name being executed in @BeforeStep annotation
(too old to reply)
Anukul Singhal
2018-06-14 22:27:44 UTC
Permalink
Hi,

I have a use case which requires me to capture the step name being
executed, just like how you can do it with Scenario class. Here is the
Hooks class content that I have:

public class Hooks {

TestContext testContext;

public Hooks(TestContext context) {
testContext = context;
}

@Before
public void beforeScenario(Scenario scenario) {
System.out.println("Executing before scenario for : " +
scenario.getName());
}

@After
public void afterScenario(Scenario scenario) {
System.out.println("Executing after scenario for : " +
scenario.getName());
}

@BeforeStep
public void beforeStep() {
System.out.println("In Before step...");
//TODO: Need to capture the Step which is going to execute
//Need some kind of implementation like step.getName()
}

@AfterStep
public void afterStep() {

}

}

I tried to pass in *PickleStep object* as an argument to *beforeStep()*
method but seems like it only likes to have args of type
*cucumber.api.Scenario* class (or no args). Is there anyway I can *capture
the current step name* being executed in @BeforeStep annotation?

I am using *cucumber-java - 3.0.2 (io.cucumber)*

Thanks,
Anukul
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
MP Korstanje
2018-06-17 10:02:39 UTC
Permalink
Hey Anukul,

I suspect you are trying to use this information to create a report of some
sort. If so you should look into implementing a formatter instead. Have a
look at the existing formatters to see how:

https://github.com/cucumber/cucumber-jvm/blob/master/core/src/main/java/cucumber/runtime/formatter/

-MP
Post by Anukul Singhal
Hi,
I have a use case which requires me to capture the step name being
executed, just like how you can do it with Scenario class. Here is the
public class Hooks {
TestContext testContext;
public Hooks(TestContext context) {
testContext = context;
}
@Before
public void beforeScenario(Scenario scenario) {
System.out.println("Executing before scenario for : " +
scenario.getName());
}
@After
public void afterScenario(Scenario scenario) {
System.out.println("Executing after scenario for : " +
scenario.getName());
}
@BeforeStep
public void beforeStep() {
System.out.println("In Before step...");
//TODO: Need to capture the Step which is going to execute
//Need some kind of implementation like step.getName()
}
@AfterStep
public void afterStep() {
}
}
I tried to pass in *PickleStep object* as an argument to *beforeStep()*
method but seems like it only likes to have args of type
*cucumber.api.Scenario* class (or no args). Is there anyway I can *capture
I am using *cucumber-java - 3.0.2 (io.cucumber)*
Thanks,
Anukul
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Anukul Singhal
2018-06-18 20:36:39 UTC
Permalink
Hey MP,

Thanks a ton for this reference, was able to create a custom formatter
(captured test step name), and plugged in to the cucumber options.

Thanks,
Anukul
Post by MP Korstanje
Hey Anukul,
I suspect you are trying to use this information to create a report of
some sort. If so you should look into implementing a formatter instead.
https://github.com/cucumber/cucumber-jvm/blob/master/core/src/main/java/cucumber/runtime/formatter/
-MP
Post by Anukul Singhal
Hi,
I have a use case which requires me to capture the step name being
executed, just like how you can do it with Scenario class. Here is the
public class Hooks {
TestContext testContext;
public Hooks(TestContext context) {
testContext = context;
}
@Before
public void beforeScenario(Scenario scenario) {
System.out.println("Executing before scenario for : " +
scenario.getName());
}
@After
public void afterScenario(Scenario scenario) {
System.out.println("Executing after scenario for : " +
scenario.getName());
}
@BeforeStep
public void beforeStep() {
System.out.println("In Before step...");
//TODO: Need to capture the Step which is going to execute
//Need some kind of implementation like step.getName()
}
@AfterStep
public void afterStep() {
}
}
I tried to pass in *PickleStep object* as an argument to *beforeStep()*
method but seems like it only likes to have args of type
*cucumber.api.Scenario* class (or no args). Is there anyway I can *capture
I am using *cucumber-java - 3.0.2 (io.cucumber)*
Thanks,
Anukul
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...