Skip to main content

Scenario for GET operation for Users

 Feature: Users

       Operations about user

Scenario: Get user by user name

When I perform GET operation for user using endpoint "/user/{username}" by using User        name "Raju"

       Then I should see the response as successful with status code as 200 ok

Step Definition for GET operation  

namespace APIAutomation.Features

{

    [Binding] //It's binding the feature file with step definition file

    public class UsersSteps

    {

        public RestClient client;

        public RestRequest request;

        public IRestResponse response;

[Given(@"I perform api operation on petstore server ""(.*)""")]

        public void GivenIPerformApiOperationOnPetstoreServer(string baseUrl)

        {

            //Create a Request pointing to the Service Endpoint

            client = new RestClient(baseUrl);

        }

[When(@"I perform GET operation for user using endpoint ""(.*)"" by using User name ""(.*)""")] public void WhenIPerformGETOperationForUserUsingEndpointByUsingUserName(string endpoint, string username)

        {

            //Create the GET request using given endpoint

            request = new RestRequest(endpoint, Method.GET);

            //passing url segment

            request.AddParameter("username", username, ParameterType.UrlSegment);

            //execute the request

            response = client.Execute(request);

        }

 

  [Then(@"I should see the response as successful with status code as (.*) ok")]

        public void ThenIShouldSeeTheResponseAsSuccessfulWithStatusCodeAsOk(int status)

        {

            //Converting the status code from response to integer format

            int statusCode = (int)response.StatusCode;

 

            //Asserting the status code from the response

            Assert.AreEqual(status, statusCode, "Statuscode is not a " + status);

        }

    }

}



Comments

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 ...

What is BDD?

  Behavior Driven Framework (BDD) :           In software engineering, behavior-driven development (BDD) is a software development process that evolved from test-driven development (TDD). These tools are frequently designed for use in BDD projects, they can be viewed as specialized forms of test-driven development . The grammar used in the tests is simple descriptive English. Tests are more user-focused and are explained as application behavior. Examples are used to clarify requirements. This distinction necessitates the use of a language that can define in an understandable manner. Features of BDD : Shifting from thinking in terms of "tests" to thinking in terms of "behavior." Collaboration among business stakeholders, business analysts, the QA team, and developers. It's simple to describe a language that's everywhere. Business value is the driving force. Test Driven Development (TDD) is extended by using natural language that non-technical stakeholders ca...

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 ·      ...