Site Loader
Auckland, New Zealand
There are situations where we might need to call a step or steps from within a step definition, so that
  • Number of steps within feature files can be reduced
  • Number of duplicate steps can be used
Hence the scenarios will look something like this, the second scenario step definition as you can see has a step (Given I login and enter user details) performs all the operation of scenario one by calling steps within step definition

Here is the complete video of the above discussion Here is the complete code of the above video
        [Given(@"I login and enter user details")]
        public void GivenILoginAndEnterUserDetails()
            //Create a column header
            string[] colHeader = { "UserName", "Password" };
            string[] row = { "admin", "admin" };
            //Created a table with values
            var table = new Table(colHeader);

            Given("I login to application", table);

            string[] colHeaderForUF = { "Title", "FirstName", "Initial" };
            string[] rowForUF = { "Mr.", "Karthik", "KK" };
            table = new Table(colHeaderForUF);

            Given("I enter following details", table);
Thanks for reading the post and watching the video!!! Please leave your comments and let me know if there is anything I should update in this post. Thanks, Karthik KK

Post Author: Karthik kk

5 Replies to “Calling steps from step definition”

  1. Hi Karthik,
    I try to call a step from another step, but get a syntax error from C# not recognizing Given as a keyword in:
    using TechTalk.SpecFlow;

    namespace …
    public class HomePageSteps

    [Then(@”the user opens application”)
    public void ThenTheUserOpensApplication()
    Given(“the user navigates to the Home Page”);

    How do I make C# understand that Given is a keyword for SpecFlow?
    Thanks … gyorgy …

  2. Hey Karthik, This code snippet is really helpful, can we use same semantics for Java & Cucumber framework? to carryout the same expectation of calling steps in an another step.

  3. Hi Karthik,

    Can you please share the syntax with typescript cucumber as well for the above scenarios. Where the reduce the number of steps or does it support typescript?

Leave a Reply

Your email address will not be published. Required fields are marked *