At present we have this step:
[When(@"I set the scenario price for product (.*) to (.*)")]
public void WhenISetTheScenarioPriceForProductPToN(string product, string priceStr)
I wish to add the step:
[When(@"I set the scenario price for product (.*) to (.*) in the (.*) zone")
public void WhenISetTheScenarioPriceInZoneForProductPToN(string product, string priceStr, string zone)
However spec flow gives an “Ambiguous step definitions found for step” error between the two steps.
I have tired:
[When(@"I set the scenario price for product (.*) to (.*) in the (.*) zone")]
[When(@"I set the scenario price for product (.*) to (.*)")]
public void WhenISetTheScenarioPriceInZoneForProductPToN(string product, string priceStr, string zone)
but that fails with a “binding error: Parameter count mismatch!” I was hopeing it would pass null for the 2nd “when”.
The problem is second your (.*). That can expand to match “xyz in the abc zone”. Can you instead match just a single word? i.e. (\w+)
That would then prevent the shorter Regex matching in the abc zone as well.
You can test this by commenting out your longer When attribute and method and debugging to see what matches the shorter one.
Also, you always have to have the same number of Regexes as parameters which is why the combined one doesn’t work.
This did not work for me, this is due to a price of “0.99” and “.” not being matched by \w. However this works:
as our “test values” don’t have spaces in them.