SamP
SamP

Reputation: 437

How to handle Cucumber AmbiguousStepDefinitions Exception?

Currently I'm running a series of tests which use the following steps:

 @And("^I select (.*) as a subject type$")
    public void click_on_subject_type(String subject) {
        String subjectType = String.format("//*[text()='%s']", subject);
        waitAndClickUsingByLocator(By.xpath(subjectType), Global_Vars.DEFAULT_TIMEOUT);
    }

    @And("^I select (.*)$")
    public void click_on_level(String level) {
        String subjectType = String.format("//*[text()='%s']", level);
        waitAndClickUsingByLocator(By.xpath(subjectType), Global_Vars.DEFAULT_TIMEOUT);
    }

Upon execution of my code it seems to be throwing the exception: cucumber.runtime.AmbiguousStepDefinitionsException: flagging both of the steps listed above.

I have also added ^ $ to the step definitions however the issue still persists, any ideas how to ressolve this issue?

Upvotes: 3

Views: 2012

Answers (1)

Justus K
Justus K

Reputation: 26

For a quick and easy fix you can just rename the second step to: @And("^I select (.*) as a level$")

This also makes it easier to understand the scenarios.

Upvotes: 1

Related Questions