-
Notifications
You must be signed in to change notification settings - Fork 11
SharedSteps Defention Class
Mahmoud A. Zaid edited this page Mar 13, 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
- Define the public variables as below
public static RestClient api = new RestClient(ConfigurationManager.AppSettings["RestAPI"]);
public static RestRequest request;
public static IRestResponse apiResult;
- 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;
}
- Implement creat URL step
[When(@"Create URL segment for ""(.*)"" with parameter (.*)")]
public void ThenCreateURLSegmentForWithParameter(string _segment, string _parameter)
{
request.AddUrlSegment(_segment, _parameter);
}
- Implement excuattion Step
[When(@"Execute API")]
public void ThenExecuteAPI()
{
apiResult = api.Execute(request);
}
- 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);
}
Mahmoud A. Zaid
- Introduction
- HTTP Methods
- HTTP Request
- API Parameters
- HTTP Response
- HTTP Status Code
- Methods Examples
- Idempotence