Quickstart Guide

This brief guide should help you start using Boa Constrictor quickly. Please read What is Screenplay? to learn more about the Screenplay Pattern itself, and please complete the tutorial to learn Boa Constrictor’s code in depth. You can also watch videos and read user guides about Boa Constrictor.

Setup

Boa Constrictor is a .NET library written in C#. To start using it:

  1. Install the Boa.Constrictor package from NuGet.org into your .NET project.
  2. Install appropriate WebDriver executables on your system PATH.
    • For example, install ChromeDriver to run tests using Google Chrome.
    • Follow the instructions on the Driver Requirements page to set them up.
    • If your code raises a DriverServiceNotFoundException, then double-check your WebDriver installation.

Example Code

Here’s how to automate a Wikipedia search in Chrome using Boa Constrictor.

Write Screenplay calls:

using Boa.Constrictor.Screenplay;
using Boa.Constrictor.Selenium;
using OpenQA.Selenium.Chrome;

// Set up the Screenplay actor
IActor actor = new Actor(logger: new ConsoleLogger());

// Inject the Selenium WebDriver instance
actor.Can(BrowseTheWeb.With(new ChromeDriver()));

// Load a page
actor.AttemptsTo(Navigate.ToUrl(MainPage.Url));

// Get the page's title
string title = actor.AsksFor(Title.OfPage());

// Search for something
actor.AttemptsTo(SearchWikipedia.For("Giant panda"));

// Wait for results
Actor.WaitsUntil(Text.Of(ArticlePage.Title), IsEqualTo.Value("Giant panda"));

With locator classes:

using Boa.Constrictor.Selenium;
using OpenQA.Selenium;
using static Boa.Constrictor.Selenium.WebLocator;

public static class MainPage
{
  public const string Url = "https://en.wikipedia.org/wiki/Main_Page";

  public static IWebLocator SearchButton => L(
    "Wikipedia Search Button",
    By.XPath("//button[text()='Search']"));

  public static IWebLocator SearchInput => L(
    "Wikipedia Search Input",
    By.Name("search"));
}

public static class ArticlePage
{
  public static IWebLocator Title => L(
    "Title Span",
    By.CssSelector("[id='firstHeading'] span"));
}

And a custom SearchWikipedia Task:

using Boa.Constrictor.Screenplay;
using Boa.Constrictor.Selenium;

public class SearchWikipedia : ITask
{
  public string Phrase { get; }

  private SearchWikipedia(string phrase) =>
    Phrase = phrase;

  public static SearchWikipedia For(string phrase) =>
    new SearchWikipedia(phrase);

  public void PerformAs(IActor actor)
  {
    actor.AttemptsTo(SendKeys.To(MainPage.SearchInput, Phrase));
    actor.AttemptsTo(Click.On(MainPage.SearchButton));
  }
}