Implementing questions - Galad/tranquire GitHub Wiki
There are 2 interfaces that represent a question: Question<TAnswer>
and IQuestion<TAbility, TAnswer>
. Just like with actions, you should choose to implement Question<TAnswer>
when your question does not have any direct dependen, while you should choose the second interface when it has a direct dependency, such as the Selenium WebDriver.
The IAction interfaces require to implement a method AnsweredBy
and the property Name
. The name is a string value that allow to identify what an action does, and is used in the logs.
Each methods provides a IActor instance, that you can use to execute other actions.
In order to simplify implementing actions, Tranquire provides abstract classes for you to inherit from. and Question<TAbility, TAnswer>
.
This interface is used for actions that do not require a dependency. It is recommended to inherit from the abstract class Question<TAnswer>
.
Here is an example of a question:
public class RemainingItems : IQuestion<int>
{
public int AnsweredBy(IActor actor)
{
return actor.AsksFor(TextContent.Of(ToDoPage.ToDoItemsLeftCounter).AsInteger());
}
public string Name => "Remaining items";
}
This interface is used for actions that require a dependency. It is recommended to inherit from the abstract class Question<TAbility, TAnswer>
.
Here is an example of a question:
/// <summary>
/// A question returning the page URL
/// </summary>
public class PageUrl : Question<WebBrowser, string>
{
protected override string Answer(IActor actor, WebBrowser ability)
{
return ability.Driver.Url;
}
public override string Name => "Page URL";
}