1
votes

I am trying to write a scenario using specflow where I am downloading a file and checking if the file with specific name is getting downloaded.

Scenario Outline: Download excel files

Given I am on the Shipping

When I download a <downloadfile> file

Then I should be able to download the file.

Examples:

| downloadfile    |

| xyz             |

| abc             |

When i generate the step file the following gets generated in my steps.cs file:

[When(@"I download a xyz file\.")]

public void WhenIDownloadAXyzFile_()

{
   ScenarioContext.Current.Pending();
}

Can anybody tell me why I am not getting (.*) in step definition? It is showing first example content in step definition.

1
That's really weird. I got the same behavior. A workaround is to remove all the data (everything below the | downloadfile | line) and then it seems to work properly. Add the data back in after you generate step definitions. - tnw
try adding single quotes i.e. '<downloadfile>' - Joel
@tnw- The work around is fine. I commented the data and and tried generating the step definition. Thank you.. :) - user1943608
@Joel- The solution you suggested is working as well. Thank you. - user1943608

1 Answers

0
votes

When the step is plain text, such as:

When I download a xyz file

There is nothing that the framework can use to determine that "xyz" is an item that you want to capture.

Placing quotation marks around it, will let the framework know that it's something to capture and use in your step definition.

When I download a "xyz" file

And

When I download a 'xyz' file

Will both generate the correct step definition. It's dangerous within any cucumber-based framework to use (.*) within the regex of the step definition, because of ambiguous matches.

Using the (.*) where you intend it will mess with a future step definition if you want to download a file with a certain size, for instance.

When I download a jpeg file

And

When I download a 500kb jpeg file 

Will both match the same thing. So be careful with that.