1

I want to get a scenario name for each scenario to set it as Test name while running it on saucelabs. This test name can be set using MutableCapabilities just before creating webdriver. I'm creating the driver using google Guice @ScenarioScoped, hence driver will be created even before @Before hook method is invoked. So, is there any way I can access Scenario name without using @Before hook?

CMM
  • 543
  • 4
  • 16

3 Answers3

1

As per cucumber implementation, it is not possible to get the scenario names without using @Before or @After hooks. However, below should work for your problem: You can utilize the advantage of ordering hooks. These hooks will be executed based on the order specified. For reference: https://cucumber.io/docs/cucumber/api/ Example:

@Before(order = 10)
public void doSomething(){
    // Do something before each scenario
}

So, you can add another hook with lower order @Before hook in the class where you are creating webdriver, and this method needs to be placed before the webdriver is created.

CloudM
  • 38
  • 1
  • 1
  • 5
0

Cucumber implementation shall not allow you accessing scenarios name without using @Before hook

TheSociety
  • 1,936
  • 2
  • 8
  • 20
0

Create the cucumber runner class with testng. In run_cukes method will get the current feature file & scenario name by using the method cucumberFeature.getCucumberFeature().getGherkinFeature().getName()

enter image description here

Balakrishnan
  • 279
  • 2
  • 7
  • 1
    Is there any chance you could please cut and paste the text instead of using an image? Indenting by 4 spaces will render it as code; there are also shortcut buttons above the edit area which will do this for you. This will help anyone who can't read the small-size font in the image, and enable search engines to find it too. – Lunivore Apr 09 '19 at 21:55