Search code examples
bddrest-assuredjbehaveserenity-bddcucumber-serenity

RESTAssured/Serenity jBehave ExamplesTable throwing "Not a Map or List type" exception


I have the following Given statement:

ServiceSatus.feature:

Given I run a request for service status with the following options
|field1  |field2     |field3  |
|all     |1517029200 |5234817 |     

StepDefinition.java:

private HashMap<String,String> options = new HashMap<String, String>();

@Given("I run a request for service status with the following options")
public void i_run_a_request_for_service_status(ExamplesTable featureOptions) {
    options.put("field1",featureOptions.getRows().get(0).get("field1"));
    options.put("field2",featureOptions.getRows().get(0).get("field2"));
    options.put("field3",featureOptions.getRows().get(0).get("field3"));    
}

Cucumber is identifying this as a valid Examples Table, however I am getting an error saying it's not a Map or List type.

Cucumber exception: Not a Map or List type: class org.jbehave.core.model.ExamplesTable

Do I have some type of syntax error in my feature file?

EDIT: I'm using jBehave ExampleTables on top of rest-assured, bdd-serenity, and cucumber for jUnit.

pom.xml:

Dependencies:

<properties>
    <serenity.version>1.9.1</serenity.version>
    <serenity.maven.version>1.5.8</serenity.maven.version>
    <junit.version>4.12</junit.version>
    <slf4j.version>1.6.1</slf4j.version>
    <maven.failsafe.plugin.version>2.18</maven.failsafe.plugin.version>
    <maven.compiler.plugin.version>3.2</maven.compiler.plugin.version>
    <serenity.cucumber.version>1.9.1</serenity.cucumber.version>
</properties>

<dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
</dependency>
<dependency>
      <groupId>io.rest-assured</groupId>
      <artifactId>rest-assured</artifactId>
      <version>3.0.7</version>
      <scope>test</scope>
</dependency>
<dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.8.1</version>
</dependency>
<dependency>
        <groupId>net.serenity-bdd</groupId>
        <artifactId>serenity-core</artifactId>
        <version>${serenity.version}</version>
</dependency>
<dependency>
        <groupId>net.serenity-bdd</groupId>
        <artifactId>serenity-junit</artifactId>
        <version>${serenity.version}</version>
</dependency>
<dependency>
        <groupId>net.serenity-bdd</groupId>
        <artifactId>serenity-cucumber</artifactId>
        <version>${serenity.cucumber.version}</version>
        <scope>test</scope>
</dependency>
<dependency>
        <groupId>net.serenity-bdd</groupId>
        <artifactId>serenity-rest-assured</artifactId>
        <version>${serenity.version}</version>
</dependency>
<dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>${slf4j.version}</version>
</dependency>
<dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>${junit.version}</version>
        <scope>test</scope>
</dependency>
<dependency>
        <groupId>org.jbehave</groupId>
        <artifactId>jbehave-maven-plugin</artifactId>
        <version>4.1.3</version>
</dependency>   
<dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
        <version>20160810</version>
</dependency>

Plugins:

<plugin>
    <groupId>net.serenity-bdd.maven.plugins</groupId>
    <artifactId>serenity-maven-plugin</artifactId>
    <version>${serenity.maven.version}</version>
    <dependencies>
        <dependency>
            <groupId>net.serenity-bdd</groupId>
            <artifactId>serenity-core</artifactId>
            <version>${serenity.version}</version>
        </dependency>
    </dependencies>
    <executions>
        <execution>
            <id>serenity-reports</id>
            <phase>post-integration-test</phase>
            <goals>
                <goal>aggregate</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Solution

  • JBehave and Cucumber models are mixed:

    • JBehave: org.jbehave.core.model.ExamplesTable
    • Cucumber: cucumber.api.DataTable

    These classes are analogues, they represent the same class of objects (BDD tables), but belong to different libraries.

    It's better to choose one BDD framework and follow its model. But if it's still required to use org.jbehave.core.model.ExamplesTable as step input parameter in Cucumber context, a custom transformer should be implemented: https://static.javadoc.io/info.cukes/cucumber-core/1.2.5/cucumber/api/Transformer.html