Skip to content

SharedSteps Defention Class

Mahmoud A. Zaid edited this page Mar 15, 2019 · 4 revisions

In the previous lesson we are created our first feature file and generate the step definitions methods now we will implement those methods you will find the final implemented class here

1. Define the public variables as below

public static RestClient api = new RestClient(ConfigurationManager.AppSettings["RestAPI"]);
public static RestRequest request;
public static IRestResponse apiResult;

2. Implement create request step

[Given(@"Create Request ""(.*)"" with ""(.*)"" method")]
public void GivenCreateRequestWithMethod(string _request, Method _method)
{
request = new RestRequest(_request, _method);
request.RequestFormat = DataFormat.Json;
}

3. Implement creat URL step

[When(@"Create URL segment for ""(.*)"" with parameter (.*)")]
public void ThenCreateURLSegmentForWithParameter(string _segment, string _parameter)
{
request.AddUrlSegment(_segment, _parameter);
}

4. Implement excuattion Step

[When(@"Execute API")]
public void ThenExecuteAPI()
{
apiResult = api.Execute(request);
}

5. Implement validation step to check the returned response status code

[Then(@"returned status code will be ""(.*)""")]
public void ThenReturnedStatusCodeWillBe(int _status)
{
var code = apiResult.StatusCode;
code.Should().Be(_status);
}