How to get name of scenario in cucumber java?

user2365105 picture user2365105 · May 12, 2014 · Viewed 33.4k times · Source

I would like to get name of scenario to have meaningful logs and to generate custom report at run-time in java. Scenario class have only has getStatus() and getSourceTagNames() methods. I don't find a way to get scenario name.

Can someone help me to get this resolved ?

Answer

Sridevi Yedidha picture Sridevi Yedidha · May 12, 2014

From version 1.6, in addition to, getStatus() and getSourceTagNames(), there is another method, getName() that returns the scenario's description. For example, for a scenario as follows:

Scenario: verify number of topics shown in the UI

scenario.getName() returns "verify number of topics shown in the UI"

I initialize scenario in @Before as follows:

@Before
public void before(Scenario scenario) {
    this.scenario = scenario;
}

Hope this helps.