kroe761
kroe761

Reputation: 3534

Include digits in cucumber feature files as strings?

I am writing cucumber tests that specify certain numbers should be in certain places of the data as strings. So I am trying to run this:

myFeature.feature

...
Then this segment should equal 01

mySteps.java

@Then("^Then this segment should equal 01$")
public void myThenStep() {
    // Do stuff
}

But what cucumber is telling me to use is this:

@Then("^Then this segment should equal (\\d+)$")
public void myThenStep(int arg1) {
    // Do stuff
}

I am not trying to include arguments, I am trying to assert that the string I got equals 01. How do I do this? It seems really simple, but I can't find a way to escape that number. Thanks!

Upvotes: 1

Views: 3101

Answers (1)

Niklas
Niklas

Reputation: 384

If you don't want pass in the 01 from the feature to your step but instead use it as test, this should work

@Then("^Then this segment should equal 01$")
public void myThenStep() {
    // Do stuff
}

If you want to pass in the string from your feature file, you can do something like

@Then("^Then this segment should equal (.*)$")
public void myThenStep(String arg1) {
    // arg1 will be "01" in your test
    // Do stuff
}

Upvotes: 1

Related Questions