How to get the name and parameters of the script? specflow

In this script question, .getName is used for the script name. I need to get a name in addition to the parameters. For example, if the script:

Scenario Outline: name of scenario Given I am on the proper page When I apply <filter> with <params> And I click filter Then the data should be filtered Examples: | filter | params | | Date | Today | | Name | Some Name | 

I want to get nameOfScenario (Date, Today).

I also use C #, not java

UPDATE

I know when I open test cases with NUnit, they are displayed as nameOfScenario(Date,Today) . Any ideas how Nunit does this?

+6
source share
3 answers

Feel free to use TestContext.CurrentContext.Test.Name - this will definitely help you get the exact parameterized script name.

The spectrometer does not lead with parameters at runtime; it is NUnit (or another unit test framework).

At the very least, you can examine the properties of TestContext.CurrentContext.Test for a list of parameters.

+6
source

You can get the name of the current script using ScenarioContext.Current.ScenarioInfo.Title , but I don't think there is any way to get the parameter names.

NUnit has a parameter name, since Specflow generates unit test classes with these names at design time, it does not get them from specflow at run time

+5
source

I do not believe that SpecFlow has direct support for this. However, with a little effort you can achieve the desired result.

Change your script definition as follows:

 Background: Given parameters <filter> and <params> Scenario Outline: name of scenario Given I am on the proper page When I apply <filter> with <params> And I click filter Then the data should be filtered Examples: | filter | params | | Date | Today | | Name | Some Name | 

and complete the step definition corresponding to the Given parameters etc. step .

Alternatively, if all you need is a way to distinguish between examples, i.e. it doesn’t matter to you that it is “Date” and “Today,” you just want to know what exactly this row is, and not the other, you can add another column to your examples:

 Scenario Outline: name of scenario Given I am on the proper page And I am working example number <example number> When I apply <filter> with <params> And I click filter Then the data should be filtered Examples: | filter | params | example number | | Date | Today | 1 | | Name | Some Name | 2 | 
0
source

Source: https://habr.com/ru/post/983038/


All Articles