An entity selector lets a business-readable phrase, such as “the earliest order,” invoke domain logic that chooses the intended entity. It keeps scenarios focused on what matters while automation resolves the phrase against available data. section 13.4 section 13.0
A selector connects scenario language to reusable automation:
- Write the phrase that expresses the choice the scenario needs, rather than spelling out incidental details such as an order’s timestamp. section 13.4
- Resolve the phrase by querying scenario context or another data source, then pass the selected entity to the step. section 13.4
Listing 13.12 Scenario with multiple orders
*** Features/OrderProcessing.feature ***
Scenario: Start work on orders in order of arrival
Given the following orders have been placed
| placed at |
| 13:33:47 |
| 13:45:30 |
When a kitchen staff member asks for an order to work on
Then the earliest order received should be takenCompare the scenario’s explicit timestamp with “the earliest order received,” which expresses the selection in domain language. section 13.4
Listing 13.13 Extend parameter type to handle earliest order
*** Support/CustomParameterTypes.cs ***
[Binding]
public class CustomParameterTypes(OrderingContext orderingContext)
{
[StepArgumentTransformation("the order|the placed order|the new order",
Name = "order")] #A
public int ConvertOrder()
{
return orderingContext.ChosenOrderNo ??
throw new InvalidOperationException("No current order");
}
[StepArgumentTransformation(
"the earliest order received", Name = "order")] #B
public int ConvertEarliestOrder()
{
return orderingContext.PlacedOrders
.OrderBy(o => o.PlacingTime)
.FirstOrDefault()?.OrderNo ??
throw new InvalidOperationException("No orders available");
}
}The order parameter type matches the selector phrase to a transformation that sorts placed orders by time and returns the first order number. section 13.4
