Data table in SpecFlow

We can also pass the data in the form of Data table as shown in below feature file.

Feature: Datatable in SpecFlow

@datatable
Scenario: Datatable Scenario 1
	Given I am on the web page "https://www.softpost.org/selenium-test-page/"
	And I enter below information in the form
	| first name | last name | id    |
	| Paul       | Watson    | 29292 |
	| Shaun      | Watson    | 64545 |

Here is the step definition class for above scenario. Note that parameter in the method is of type Table and we can read data from Datatable using TableRow class.

using System;
using TechTalk.SpecFlow;

namespace SpecFlowRunnerProject
{
    [Binding]
    public class DatatableInSpecFlowSteps
    {
        [Given(@"I enter below information in the form")]
        public void GivenIEnterBelowInformationInTheForm(Table table)
        {
            foreach (TableRow row in table.Rows)
                {
                    foreach (String value in row.Values)
                    Console.WriteLine(value);
                }
        }
    }
}

 

Here is the output of above scenario.

Data table in SpecFlow

Data table in SpecFlow

You may also like...