April 2, 2017

Learning Serenity: The Screenplay Tutorial

We've covered a lot with Serenity BDD over the past few weeks!

This has all prepared us for John Ferguson Smart's tutorial on the Serenity BDD Screenplay Pattern. See http://serenity-bdd.info/docs/articles/screenplay-tutorial.html



Why Replace the Page Object Pattern with The Screenplay Pattern? 



Personally, I am trying to learn Serenity BDD and the Screenplay pattern because it is already the toolset and techniques we are already using where I am assigned as a contractor. I just started my career in automated testing two years ago.

Why does John Ferguson Smart and his group recommend this pattern they created? From Page Objects Refactored: SOLID steps to the Screenplay / Journey Pattern (2/11/2016):
"PageObjects have been the staple of automated web testing for over seven years. Simon Stewart wrote the original Selenium PageObject wiki entry in 2009. The concept was introduced to help test-developers reduce maintenance issues that, for many, resulted in flaky tests. Some mistook this as issues with Selenium, rather than with their own coding practices. While PageObjects can act as training wheels and be a good place to start, in this article we show you issues inherent to PageObjects and the benefits of refactoring them using SOLID OO principles. We then introduce the Screenplay Pattern, an alternative approach that could save you the trouble".
... I also heard that the Screenplay pattern has Appium built in as a way to kick off mobile automation. I'll be investigating that, next!

How to Get Started

Following the instructions on Writing automated acceptance tests using Serenity and the Screenplay Pattern:

"The easiest way to create a project skeleton for a Serenity Screenplay project is to use the Maven Archetype Plugin. To do this, run the mvn archetype:generate command (with a filter to reduce the number of artifacts Maven proposes) as shown here:"
$ mvn archetype:generate -Dfilter=screenplay
...
[INFO] No archetype defined. Using maven-archetype-quickstart (org.apache.maven.archetypes:maven-archetype-quickstart:1.0)
Choose archetype:
1: remote -> net.serenity-bdd:serenity-junit-screenplay-archetype (Serenity automated acceptance testing project using Screenplay, Selenium 2 and JUnit)
Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): :
"[...] You will then be prompted to enter a groupId, artifactId, and version for your project, and a root package for your classes [...]".

Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): : 1
Define value for property 'groupId': : net.serenitybdd.tutorials
Define value for property 'artifactId': : todomvctests
Define value for property 'version':  1.0-SNAPSHOT: : 1.0.0-SNAPSHOT
Define value for property 'package':  net.serenitybdd.tutorials: :
Confirm properties configuration:
groupId: net.serenitybdd.tutorials
artifactId: todomvctests
version: 1.0.0-SNAPSHOT
package: net.serenitybdd.tutorials
 Y: : Y
"You will find your new project in the screenplay-tutorial directory".

$ cd screenplay-tutorial
$ mvn clean verify
... And the tests should run!

Explore the tutorial to learn more about all the moving parts as shown below:


Enjoy!

And thank you for Learning Serenity with me! Happy Testing!


-T.J. Maher
Twitter | LinkedIn | GitHub

// Sr. QA Engineer, Software Engineer in Test, Software Tester since 1996.
// Contributing Writer for TechBeacon.
// "Looking to move away from manual QA? Follow Adventures in Automation on Facebook!"
Post a Comment