Skip to main content

Specflow

 Specflow:

           Specflow is a testing framework that supports the.NET technology's Behavior Driven Development (BDD). It defines a test case's behavior in plain English using a simple grammar language known as "Gherkin."

Feature: A feature file is a point of entry into the Specflow test. It is an essential component of specflow because it serves as both an automation test script and live documents. A scenario can be contained in a single feature file or multiple scenarios can be contained in a single feature file, but it usually contains a list of scenarios.

            With feature extension, you can add a feature file to your project, and your test scenario will be written in Gherkin language in the format of Given, When, And, Then.

Example:

Feature: API Application

Scenario: Get API response using given endpoint

             Given I have an endpoint "/endpoint/"

            And I have a base url "http://mydomain.com"

            when I call GET method of API

            Then I get API response in JSON format

Step Definition: A step argument transformation is a method that converts text (specified by a regular expression) to an arbitrary.NET type. Scoped bindings can be used to limit the scope of a step definition or hook.

           The step definition consists of a.cs file and a sealed class that cannot be inherited. Also, the step class has a [Binding] attribute above the class name, indicating that it is bound to the feature file. All methods with the Given, When, And, Then attributes on methods with given statements in the same feature file.

namespace APIAutomation.Steps

{

    [Binding]

    public class API Application

    {

 

        [Given (@"I have an endpoint (.*)")]

        public void GivenIHaveAnEndpoint(string endpoint)

        {

                        ScenarioContext.Current.Pending ();

             }

      }

}

Comments

Post a Comment

Popular posts from this blog

Specflow Tables – Convert Table to Dictionary

            Tables can be used both vertically and horizontally. In the first table examples, we'll use the Data Vertically as a Key-Value pair, which the Dictionary object allows. 1) Add a New Step The first step is to create a new Step that will accept data in the form of a table. It is once again simple to specify data for the step in Vertical format. Let's look at how to pass Vertical Data in the same Users scenario that was used in the previous SpecFlow :   Feature : Users        Operations about user   Background :        Given I perform api operation on petstore server " https://petstore.swagger.io/v2/ "   Scenario : POST operation with table        When I perform POST operation for User using endpoint " /user " using table data               | Key         | Value                |               | Id          | 2                    |               | username    | Ravi                 |               | firstname   |

Specflow Tables – Convert Table to Data Table

                 Vertical Data Using Tables was covered in the previous chapter of Covert Table into Dictionary. When we have a long list of Data, this is useful. Personal information includes first and last name, address, and job title, among other things.                However, this has some limitations. For example, if we want to repeat the same step, it is difficult to manage with a Dictionary Key-Value pair. To obtain the functionality, Horizontal Data must be used rather than Vertical Data, which can be accomplished by using the “Convert Table into Data Table” command. Table to Data Table Conversion We will use the same example of the Users Feature and modify it to suit our needs. Before proceeding, please review the first chapter of Data Driven Testing and see how the basic functionality works for the Users Scenario. 1) Add a New Step The first step is to create a new Step that will accept data in the form of a table. It is once again simple to specify data for the st

Json Response Deserialization

  How Do I Deserialize a JSON Response to a Class Using Rest Sharp? Let's continue from the earlier section, Creating a POST request with Rest-Sharp. In the earlier section, we made a successful post request and received the Response body shown below. To validate parts of the Response body, we used JObject.Parse. We will make this Response body into a Class. Deserialization of JSON refers to the process of converting a JSON or any structured data, including XML, into a programming class. Deserialization refers to the process of converting JSON from its String form to its Class form. This is also known as structured data object representation. JSON is used to represent structured data in this case. To integrate the JSON to a Class representation, we will first create a Class that contains all of the nodes in the JSON. There are three nodes in the Success response above. ·          Success code ·          Type ·          Message String is the value of these three nodes