[Cucumber-jvm][TestNG] How to get scenario info in testng runner

537 views
Skip to first unread message

Chetan Dewangan

unread,
Nov 12, 2017, 12:01:20 AM11/12/17
to Cukes
I am running my cucumber test using testng runner in RunCukesByCompositionTest style with testng hooks.

I was trying to get all the tags defined in the current scenario in testNG @Before method.

Can someone please help me, I wanted to perfom some precondition steps for  scenario which has specific tags.

Björn Rasmusson

unread,
Nov 12, 2017, 5:02:37 AM11/12/17
to Cukes
You should use @cucumber.api.java.Before method instead of the testNG @Before method, the former can be parameterized with specific tag-expressions for which it should be executed (see for instance the java-calculator-testng example project).

Cheers
Björn

Chetan Dewangan

unread,
Nov 13, 2017, 2:32:16 PM11/13/17
to Cukes
Yes I gone through those approach but I am using all different annotation from testng like BeforeTest and BeforeSuite. I am not sure if I will be able to combine these fixtures and what will be final affect.

Chetan Dewangan

unread,
Nov 27, 2017, 3:04:41 PM11/27/17
to Cukes
Is there other way (may be listener) where I can get test feature/scenario meta data?

If I am not able to use testNG annotation with full feature then what's the point using TestNG with cucumber JVM.

Björn Rasmusson

unread,
Dec 1, 2017, 3:15:43 PM12/1/17
to Cukes
Chetan Dewangan wrote:
Is there other way (may be listener) where I can get test feature/scenario meta data?

If I am not able to use testNG annotation with full feature then what's the point using TestNG with cucumber JVM.

It has never been the intention of the TestNG runner (or JUnit runner) of Cucumber-JVM to transform Cucumber scenarios into TestNG test (or JUnit test). They can be used to trigger the execution of Cucumber-JVM, and provide notifications back to the TestNG (or JUnit) domain about the results of the execution of the Cucumber-JVM scenarios (test cases). Still Cucumber-JVM and TestNG (or JUnit) belong to different domains. Cucumber-JVM does not know about the TestNG (or JUnit) domain. TestNG (or JUnit) does not know about the Cucumber-JVM domain.

Cucumber-JVM has annotations to define hook method in the glue classes (@cucumber.api.java.Before/After) which can and should be used for set up and tear down. Technically it might be possible to also use TestNG (or JUnit) mechanisms like @org.testng.annotations.BeforeMethod or (@org.junit.BeforeClass) but, since they live in the TestNG (or JUnit) they does not know about the Cucumber-JVM domain. Also by relying on TestNG (or JUnit) mechanism you are blocking yourself from the opportunity to run individual features from the Eclipse or IntelliJ IDE's, both have plugins to edit and run Cucumber-JVM feature files, and both rely on the command line runner of Cucumber-JVM for executing individual feature files.

Having said that, Cucumber-JVM is a community maintained open-source software, you are welcome to provide a pull-request with improvements to the TestNG runner of Cucumber-JVM.

Cheers
Björn

sridevi ennam

unread,
Dec 6, 2017, 3:57:42 AM12/6/17
to cu...@googlegroups.com

Use @Before("@<yourScenarioTagname>")

On 12 Nov 2017 04:58, "Chetan Dewangan" <chetan....@gmail.com> wrote:
I am running my cucumber test using testng runner in RunCukesByCompositionTest style with testng hooks.

I was trying to get all the tags defined in the current scenario in testNG @Before method.

Can someone please help me, I wanted to perfom some precondition steps for  scenario which has specific tags.

--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Chetan Dewangan

unread,
Dec 7, 2017, 4:37:53 PM12/7/17
to Cukes
Thanks for the explanation Bjorn.

I was using testNG because I have various setup and teardown to be done at different level of test (@Method, @Class, @Suite and @Test).

But finally I got it, its not possible, I will look for another approach. Thanks again.
Reply all
Reply to author
Forward
0 new messages