cucumber-android: cucumber.runtime.CucumberException: No CucumberOptions annotation

Hello, I’m trying to configure an automation project with this tool but I’m getting this error :C

cucumber.runtime.CucumberException: No CucumberOptions annotation
at io.cucumber.junit.AndroidJunitRuntimeOptionsFactory.createRuntimeOptions(AndroidJunitRuntimeOptionsFactory.java:55)
at io.cucumber.junit.CucumberJUnitRunner.<init>(CucumberJUnitRunner.java:83)
at io.cucumber.junit.CucumberJUnitRunnerBuilder.runnerForClass(CucumberJUnitRunnerBuilder.java:11)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:70)
at androidx.test.internal.runner.AndroidRunnerBuilder.runnerForClass(AndroidRunnerBuilder.java:147)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:70)
at androidx.test.internal.runner.TestLoader.doCreateRunner(TestLoader.java:73)
at androidx.test.internal.runner.TestLoader.getRunnersFor(TestLoader.java:104)
at androidx.test.internal.runner.TestRequestBuilder.build(TestRequestBuilder.java:793)
at androidx.test.runner.AndroidJUnitRunner.buildRequest(AndroidJUnitRunner.java:547)
at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:390)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2189)

I have tried several things but i haven’t been able to fix it. Maybe I’m doing something wrong but I don’t know what it is. ¿Could someone help me?

This is my app/build.gradle configuration:

android {

    defaultConfig {
        multiDexEnabled true
        applicationId "com.example”
        testApplicationId "com.example.test"
        testInstrumentationRunner "io.cucumber.android.runner.CucumberAndroidJUnitRunner"
    }
}

dependencies {

    //Cucumber
    androidTestImplementation "io.cucumber:cucumber-android:4.8.3"

    //UIAutomator
    androidTestImplementation 'androidx.test:rules:1.2.0'
    androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'

    //OKHttp3
    implementation 'com.squareup.okhttp3:okhttp:3.14.1'

}

src/androidTest/assets/features/SearchUsers.feature:

Feature: Search users

    Background: Open App
      Given the user open the app

    Scenario Outline: Check error message
      When the user enters the ID number "<number>" and tap on search
      Then the message "<message>" is visible
      Examples:
        | number   | message                |
        | ABCDE    | The user doesn't exist.|
        | 792486201| The user doesn't exist |
        |          | Internal server error  |

Cucumber Options file:

package com.example.test;

import io.cucumber.junit.CucumberOptions;

@CucumberOptions(
        glue = "com.example.test.steps",
        plugin = {"pretty"},
        features = "assets/features")

public class Cucumber { }

And my step definitions:

package com.example.test.steps;

import androidx.test.uiautomator.UiObjectNotFoundException;
import com.example.test.pageObjects.IndexPage;
import org.json.JSONException;
import java.io.IOException;
import io.cucumber.java.en.*;

public class SearchSteps {

    private IndexPage indexPage = new IndexPage();

    @Given("the user open the app")
    public void openApp() {
        indexPage.openApp();
    }

    @When("the user enters the ID number {string} and tap on search")
    public void introduceCredentials(String number) throws UiObjectNotFoundException {
        indexPage.search(number);
    }

    @Then("the message {string} is visible")
    public void checkMessage(String message) {
        indexPage.checkMessage(message);
    }

}

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 18 (5 by maintainers)

Most upvoted comments

The most common error in configuration is that class annotated with @CucumberOptions is not placed in <testApplicationId> package which by default is <applicationId>.test e.g. com.example.myapp.test. This testApplicationId can be changed in build.gradle or can be different for different flavours

Hello, I made the configuration from the beginning and I was able to get it working. Thanks for the help and sorry for the spam. 🚀

Hi @JoshuaW-kr I don’t remember exactly the problem, because it was a long time ago. But it was in the class with the cucumberOptions annotation.

I had to make changes to the class annotated with @CucumberOptions:

package com.example.test;

import io.cucumber.android.runner.CucumberAndroidJUnitRunner;
import io.cucumber.junit.CucumberOptions;

@CucumberOptions(
        features = "features",
        glue = "com.example.steps"
)
public class TestRunner extends CucumberAndroidJUnitRunner {

}

Also in the step definitions i had to change {string} for "([^"]*)"

I hope this helps you