Skip to content
Craig Fowler edited this page Mar 18, 2019 · 4 revisions

A persona is a class which describes a well-known actor. When used, it provides the actor's name and a set of abilities, serving as a template for configuring actor objects to a specification.

Development teams are encouraged to create a persona class for each well-known actor. That persona should be used to create the actor and configure their normal abilities, corresponding to the actor's role in test scenarios.

By using actors with standard names and abilities they will become recognisable in tests, aiding communication and understanding.

Example

Here is a sample persona. It describes an actor who should use the name "Matthew" and who has a (fictitious) ability to solve maths puzzles.

using CSF.FlexDi;
using CSF.Screenplay;
using CSF.Screenplay.Actors;

public class Matthew : Persona
{
    public override string Name => "Matthew";

    public override void GrantAbilities(ICanReceiveAbilities actor,
                                        IResolvesServices resolver)
    {
        actor.IsAbleTo<SolveMathsPuzzles>();
    }
}

In your own implementation you may grant the actor whichever abilities they should have. Abilities may be directly created or resolved from dependency injection via the provided instance of IResolvesServices.

Usage

Both the Cast and Stage support the use of personas to get actors.

Sticking with the example above:

var matthew = cast.Get<Matthew>();

ICast.Get is always safe to use. The cast will only create the actor if they do not already exist.

Tips

To help team members remember actors and their corresponding roles, consider using a mnemonic naming convention. This means using a name which reminds you of their role.

Here are a few ideas/examples:

  • "Youssef" is a normal user of the application
  • "Susan" has supervisor permissions
  • "Adam" is an administrator