-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Welcome to the APIFlow wiki!
The ultimate API Integration Testing framework.
APIFlow allows test automation engineers to quickly create API Integration Tests without the necessity of repeatedly wiring up models / payload. Using a forward-feed mechanism, APIFlow can execute any number of API endpoints in succession and automatically construct a request payload.
For instance, you have a collection of endpoints to fetch and update user account details.`
- Fetch Users => /Users
- Fetch User Account Details => /Users?Id={User.Id}
By configuring API Contexts similarly to how you would do in Entity Framework, http requests can be configured to forward inputs from a previously executed endpoint to the next request without needing to wire each request / construct payloads.
UserContext
Contains no special setup. Simple HTTP GET request
public class User
{
public int Id { get; set; }
}
public class UserContext : ApiContext<List<User>, HTTPDataExtender>
{
[HttpGet()]
[Route("https://aef3c493-6ff3-47a2-be7f-150688405f7e.mock.pstmn.io/Users")]
public override void ApplyContext(EndpointInputModel model)
{
}
public override void ConfigureClient(ref HttpClientWrapper wrapper)
{
base.ConfigureClient(ref wrapper);
// Add necessary headers etc.
}
public UserContext(List<User> baseObject,
EndpointInputModel inputModel) : base(baseObject, inputModel)
{
}
}
UserInformationContext
Contains two forward-feed configurations
- Configure URL to add query parameter
Id={UserContext.Id}
- Configure UserInformationContext to accept
{UserContext.Id}
as a forward-fed input.{UserInformationContext.Id}
will be replaced with{UserContext.Id}
public class UserInformation
{
public int Id { get; set; }
public int Email { get; set; }
}
public class UserInformationContext : ApiContext<UserInformation, HTTPDataExtender>
{
public override void ConfigureEndpoint(ref string endpoint, EndpointInputModel inputModel, bool randomizedInput = false)
{
base.ConfigureEndpoint(ref endpoint, inputModel, randomizedInput);
base.ConfigureEndpoint<UserContext>("Id", (u) => u.Value[0].Id);
}
[HttpGet()]
[Route("https://aef3c493-6ff3-47a2-be7f-150688405f7e.mock.pstmn.io/UserInformation")]
public override void ApplyContext(EndpointInputModel inputModel)
{
base.ConfigureModel<UserContext>((u, o) => o.Id = u.Value[0].Id);
base.ConfigureEndpoint<UserContext>("Id", (u) => u.Value[0].Id);
}
public UserInformationContext(UserInformation baseObject, EndpointInputModel inputModel) : base(baseObject, inputModel)
{
}
}
Walking the HTTP chain is simple, and straight forward.
var apiContext = new APIFlowContext();
apiContext.Walk<UserContext>()
.Walk<UserInformationContext>();
- Execute Endpoint https://aef3c493-6ff3-47a2-be7f-150688405f7e.mock.pstmn.io/Users
Returns
[
{ "Id": 147586 },
{ "Id": 146253 },
{ "Id": 142223 },
{ "Id": 147656 },
{ "Id": 140250 }
}
- Apply forward-feed.
UserInformationContext.Id
gets replaced by an Id from/Users
response as specified inUserInformationContext
class. Variables in the UserInformationContext class get updated as well. - Execute Endpoint https://aef3c493-6ff3-47a2-be7f-150688405f7e.mock.pstmn.io/UserInformation?Id=147586
As you can see, aside from model and context definition, with just a few lines of code you can execute any number of endpoints and not ever have to explicitly construct any HTTP request payloads.