Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Optional table in SpecFlow

I have a step in SpecFlow to check whether some area is displayed (e.g. User info).

Then "User Info" area is displayed

And I would like to have optional table for this step checking some other information in the area (e.g. First name, Surname, Address...).

Then "User Info" area is displayed
| Surname |
| Smith   |

I tried to create a method with optional argument:

public void ThenUserInfoAreaIsDisplayed(Table table = null)
{
  ...
}

But I got this exception when using a step without the table:

Parameter count mismatch! The binding method 'Example.ThenUserInfoAreaIsDisplayed()' should have 0 parameters

I also tried to overload the method:

public void ThenUserInfoAreaIsDisplayed()
{
  ...
}
public void ThenUserInfoAreaIsDisplayed(Table table)
{
  ...
}

In this case I get the following exception:

Parameter count mismatch! The binding method 'Example.ThenUserInfoAreaIsDisplayed()' should have 1 parameters

Any ideas? Thanks.

like image 846
JPM Avatar asked Sep 05 '25 16:09

JPM


1 Answers

I think that this is not possible exactly as you want it. You just could add another step definition for the version with the table using a somewhat extended/modified wording:

Then "User Info" area is displayed

and

Then "User Info" area is displayed with this information:
| Surname |
| Smith   |
like image 144
paulroho Avatar answered Sep 07 '25 08:09

paulroho