3

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?

SamP
  • 417
  • 5
  • 24
  • Surround the regex by single quotes in stepdef method and the variable in feature file. ^I select '(.*)' as a subject type$ and ^I select '(.*)'$ – Grasshopper Feb 15 '19 at 07:31
  • I'm afraid its unable to locate a matching step definition by appending '' to the regex statement. – SamP Feb 15 '19 at 11:50

1 Answers1

1

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.

Justus K
  • 26
  • 5