Search code examples
junitcucumbercucumber-jvmserenity-bdd

cucumber.runtime.CucumberException: Not a Map or List type


If I am using a data inside the Data Table which is not type of List or Map then it is giving me error

cucumber.runtime.CucumberException: Not a Map or List type

This is how I am testing this. I am testing it bottom to top i.e. write function > then write step def > write feature file (just for testing purpose).

java function:

public String getScenarioName(Scenario scenario) {
        System.out.println("scenario.getName().toString());
    }

step def:

@And("^Get current scenario name$")
    public void get_current_scenario_name(Scenario scenario) {
        System.out.println(getScenarioName(scenario));
    }

Feature file:

  Scenario: Title of your scenario
    Given I have a scenario
    Then Get current scenario name
      |scenario|

Since I'm using Scenario interface as a parameter I have to use it across, in function, in steps and in feature file.

Note: Please don't judge by the weird scenario, I am only testing it.

I have gone through below links, but it doesn't help me. It keep giving me same error.

https://github.com/cucumber/cucumber-jvm/issues/741

http://grasshopper.tech/340/ >> this one I couldn't implement, didn't quiet understand it.


Solution

  • You're looking somewhat in the wrong direction. To print out the scenario name in a given step you have to capture it in a before hook before printing it in a step:

    import cucumber.api.Scenario;
    import cucumber.api.java.Before;
    import cucumber.api.java.en.And;
    
    public class ExampleSteps {
    
        private Scenario scenario;
    
        @Before
        public void capture_scenario(Scenario scenario){
            this.scenario = scenario;
        }
    
        @And("^get current scenario name$")
        public void get_current_scenario_name() {
            System.out.println(this.scenario.getName());
        }
    }
    

    Then this scenario will print My Scenario.

    Scenario: My Scenario
      And I get the current scenario name