Feature: Users
Operations about user
Scenario: Get user by user name
When I perform GET operation for user using endpoint "/user/{username}" by using Username "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
Post a Comment