Today, I’m excited to announce the release of a new open source project for test automation: Boa Constrictor, the .NET Screenplay Pattern!
The Screenplay Pattern helps you make better interactions for better automation. The pattern can be summarized in one line: Actors use Abilities to perform Interactions.
- Actors initiate Interactions. Every test has an Actor.
- Abilities enable Actors to perform Interactions. They hold objects that Interactions need, like WebDrivers or REST API clients.
- Interactions exercise behaviors under test. They could be clicks, requests, commands, and anything else.
This separation of concerns makes Screenplay code very reusable and scalable, much more so than traditional page objects. Check it out, here’s a C# script to test a search engine:
// Create the Actor IActor actor = new Actor(logger: new ConsoleLogger()); // Add an Ability to use a WebDriver actor.Can(BrowseTheWeb.With(new ChromeDriver())); // Load the search engine actor.AttemptsTo(Navigate.ToUrl(SearchPage.Url)); // Get the page's title string title = actor.AsksFor(Title.OfPage()); // Search for something actor.AttemptsTo(Search.For("panda")); // Wait for results actor.AttemptsTo(Wait.Until( Appearance.Of(ResultPage.ResultLinks), IsEqualTo.True()));
Boa Constrictor provides many interactions for Selenium WebDriver and RestSharp out of the box, like
Appearance shown above. It also lets you compose interactions together, like how
Search is a composition of typing and clicking.
Over the past two years, my team and I at PrecisionLender, a Q2 Company, developed Boa Constrictor internally as the cornerstone of Boa, our comprehensive end-to-end test automation solution. We were inspired by Serenity BDD‘s Screenplay implementation. After battle-hardening Boa Constrictor with thousands of automated tests, we are releasing it publicly as an open source project. Our goal is to help everyone make better interactions for better test automation.
If you’d like to give Boa Constrictor a try, then start with the tutorial. You’ll implement that search engine test from above in full. Then, once you’re ready to use it for some serious test automation, add the Boa.Constrictor NuGet package to your .NET project and go!
You can view the full source code on GitHub at q2ebanking/boa-constrictor. Check out the repository for full information. In the coming weeks, we’ll be developing more content and code. Since Boa Constrictor is open source, we’d love for you to contribute to the project, too!