Se ha denunciado esta presentación.
Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.
SCREENPLAY

A Journey Beyond The PageObject Pattern

Antony Marcano

Jan Molak

Kostas Mamalis
CONTACT
•

Kostas Mamalis
@agiletestinguk

kostas@masterthought.net
•

Antony Marcano
@AntonyMarcano

antony@riverglide.co...
CONTEXT
IN THE BEGINNING
•

Long established financial institution

•

Used Scrum with 2 week Sprints

•

Outsourced development t...
ALONG THE JOURNEY
•

Realised that automated tests were essential

•

Wrote lots of Cucumber tests

•

Backed by Selenium/...
SELENIUM
AND
THE PAGE OBJECT PATTERN
Illustrated with the Pet Clinic
TESTING THE PET CLINIC
WEBDRIVER EXAMPLE
DesiredCapabilities capabilities = new DesiredCapabilities();
WebDriver driver = new PhantomJSDriver(des...
FINDING ALL OWNERS - WEBDRIVER EXAMPLE
DesiredCapabilities capabilities = new DesiredCapabilities();
WebDriver driver = ne...
FINDING ALL OWNERS - PAGEOBJECT EXAMPLE
DesiredCapabilities capabilities = new DesiredCapabilities();
WebDriver driver = n...
PROBLEMS AROSE
•

Large PageObject classes

•

Brittle test-code (less than raw Selenium)

•

Duplication across PageObjec...
THEY TRIED THE FOLLOWING
•

Separate behaviour into Navigation Classes

•

Reduce duplication with inheritance

Causing .....
EFFECTS ON THE TEAM
•

Took longer and longer to add new tests

•

Got harder to diagnose problems

•

Low trust in the ‘t...
WHAT WAS THE ANSWER?
Antony Marcano at first AAFTT in 2007
THE INSIGHT
Roles
← Who
➥ Goals
← Why
➥ Tasks
← What
➥ Actions ← How
Inspired by Kevin Lawrence’s talk at the first AAFTT ...
2008 - JNARRATE
@Test
public void should_be_able_to_edit_a_page() {
Given.thatThe(wiki).wasAbleTo(beAtThe(PointWhereItHasB...
2009 - SCREENPLAY - A TASK
public void perform() {
you.need(To.doTheFollowing( // actions
Click.onThe(OptionsMenu.EDIT_BUT...
2012 - THE JOURNEY PATTERN
Actor

performs

Tasks

has

Abilities

composed of

enable

Actions

interact with

Screen
con...
JOURNEY PATTERN APPLIED
JUNIT
Roles
➥ Goals

➥ Tasks

← Who
← Why

← What

➥ Actions ← How

Actor theReceptionist =
new Ac...
JOURNEY PATTERN APPLIED
CUCUMBER
Roles

← Who

As a Pet Clinic Receptionist

➥ Goals

← Why

Scenario: Find all owners by ...
PUTTING IT ALL TOGETHER
Actor theReceptionist = new Actor().with(WebBrowsing.ability());
theReceptionist.attemptsTo(
Go.to...
A TASK
…
private static String searchTerms;
@Override
public void performAs(Actor asAReceptionist) {
asAReceptionist.attem...
A SCREEN

@Url("owners/find.html")
public class FindOwnersScreen extends WebScreen {
@LocateBy(css="#search-owner-form inp...
AN ACTION
public class Enter extends WebDriverInteraction implements Perform {
private String text;
private ScreenElement ...
PROBLEMS SOLVED
•

Smaller “Screen” classes

•

Small, focused “Task” classes

•

Readable code

•

Consistent metaphor

•...
DESIGN PRINCIPLES
•

DRY - navigational steps in one place

•

Separation of Concerns - Page Structure and Actions separat...
SCREENPLAY REVIVED
Under development for everyone to use
Watch This Space!
CONTACT
•

Kostas Mamalis
@agiletestinguk

kostas@masterthought.net
•

Antony Marcano
@AntonyMarcano

antony@riverglide.co...
THANK YOU!
A journey beyond the page object pattern
Próximo SlideShare
Cargando en…5
×

de

A journey beyond the page object pattern Slide 1 A journey beyond the page object pattern Slide 2 A journey beyond the page object pattern Slide 3 A journey beyond the page object pattern Slide 4 A journey beyond the page object pattern Slide 5 A journey beyond the page object pattern Slide 6 A journey beyond the page object pattern Slide 7 A journey beyond the page object pattern Slide 8 A journey beyond the page object pattern Slide 9 A journey beyond the page object pattern Slide 10 A journey beyond the page object pattern Slide 11 A journey beyond the page object pattern Slide 12 A journey beyond the page object pattern Slide 13 A journey beyond the page object pattern Slide 14 A journey beyond the page object pattern Slide 15 A journey beyond the page object pattern Slide 16 A journey beyond the page object pattern Slide 17 A journey beyond the page object pattern Slide 18 A journey beyond the page object pattern Slide 19 A journey beyond the page object pattern Slide 20 A journey beyond the page object pattern Slide 21 A journey beyond the page object pattern Slide 22 A journey beyond the page object pattern Slide 23 A journey beyond the page object pattern Slide 24 A journey beyond the page object pattern Slide 25 A journey beyond the page object pattern Slide 26 A journey beyond the page object pattern Slide 27 A journey beyond the page object pattern Slide 28 A journey beyond the page object pattern Slide 29 A journey beyond the page object pattern Slide 30 A journey beyond the page object pattern Slide 31
Próximo SlideShare
Serenity and the Journey Pattern
Siguiente
Descargar para leer sin conexión y ver en pantalla completa.

15 recomendaciones

Compartir

Descargar para leer sin conexión

A journey beyond the page object pattern

Descargar para leer sin conexión

A story of one organisation taking an idea, formed by Antony Marcano and evolved by many, to solve some of the challenges that encountered with the growth of Selenium/WebDriver PageObjects in their Automated Tests. Talk co-presented with two of the people who have been a part of the journey – including Kostas Mamalis & Jan Molak.

Audiolibros relacionados

Gratis con una prueba de 30 días de Scribd

Ver todo

A journey beyond the page object pattern

  1. 1. SCREENPLAY A Journey Beyond The PageObject Pattern Antony Marcano Jan Molak Kostas Mamalis
  2. 2. CONTACT • Kostas Mamalis @agiletestinguk kostas@masterthought.net • Antony Marcano @AntonyMarcano antony@riverglide.com • Jan Molak @JanMolak jan.molak@smartcodeltd.co.uk
  3. 3. CONTEXT
  4. 4. IN THE BEGINNING • Long established financial institution • Used Scrum with 2 week Sprints • Outsourced development to large consultancy • No automated acceptance tests (few unit tests)
  5. 5. ALONG THE JOURNEY • Realised that automated tests were essential • Wrote lots of Cucumber tests • Backed by Selenium/WebDriver • Used the PageObject Pattern
  6. 6. SELENIUM AND THE PAGE OBJECT PATTERN Illustrated with the Pet Clinic
  7. 7. TESTING THE PET CLINIC
  8. 8. WEBDRIVER EXAMPLE DesiredCapabilities capabilities = new DesiredCapabilities(); WebDriver driver = new PhantomJSDriver(desiredCapabilities()); driver.get(baseUrl+"owners/find.html"); driver.findElement(By.cssSelector("#search-owner-form button")).click(); assertThat( driver.findElements(By.cssSelector("owners tbody tr")).size(), is(10) );
  9. 9. FINDING ALL OWNERS - WEBDRIVER EXAMPLE DesiredCapabilities capabilities = new DesiredCapabilities(); WebDriver driver = new PhantomJSDriver(desiredCapabilities()); driver.get(baseUrl+"owners/find.html"); driver.findElement(By.cssSelector("#search-owner-form button")).click(); assertThat( driver.findElements(By.cssSelector("owners tbody tr")).size(), is(10) );
  10. 10. FINDING ALL OWNERS - PAGEOBJECT EXAMPLE DesiredCapabilities capabilities = new DesiredCapabilities(); WebDriver driver = new PhantomJSDriver(desiredCapabilities()); driver.get(baseUrl+"owners/find.html"); FindOwnersPage findOwners = PageFactory.initElements(driver, FindOwnersPage.class); OwnersPage owners = findOwners.findWith(EMPTY_SEARCH_TERMS); assertThat(owners.numberOfOwners(), is(10));
  11. 11. PROBLEMS AROSE • Large PageObject classes • Brittle test-code (less than raw Selenium) • Duplication across PageObjects for each of the ‘portals’
  12. 12. THEY TRIED THE FOLLOWING • Separate behaviour into Navigation Classes • Reduce duplication with inheritance Causing ... • Large Navigation classes • Deep inheritance hierarchy
  13. 13. EFFECTS ON THE TEAM • Took longer and longer to add new tests • Got harder to diagnose problems • Low trust in the ‘test framework’ and Cucumber • Reduced faith in automated testing • Impacted morale
  14. 14. WHAT WAS THE ANSWER?
  15. 15. Antony Marcano at first AAFTT in 2007
  16. 16. THE INSIGHT Roles ← Who ➥ Goals ← Why ➥ Tasks ← What ➥ Actions ← How Inspired by Kevin Lawrence’s talk at the first AAFTT in 2007 More of his thinking here: http://www.developertesting.com/archives/month200710/20071013-In%20Praise%20of %20Abstraction.html
  17. 17. 2008 - JNARRATE @Test public void should_be_able_to_edit_a_page() { Given.thatThe(wiki).wasAbleTo(beAtThe(PointWhereItHasBeen.JUST_INSTALLED)); And.thatThe(user).wasAbleTo(navigateToTheHomePage()); And.thatThe(user).wasAbleTo(navigateToTheHomePage()); When.the(user).attemptsTo( tas k changeTheContent().to("Welcome to Acceptance Test Driven Development") tas k ); Then.the(textOnTheScreen().ofThe(user)). tas k shouldBe("Welcome to Acceptance Test Driven Development"); } Playing with fluent APIs and started to explore the model of Tasks & Actions (although back then the labels I used more like Kevin’s labels).
  18. 18. 2009 - SCREENPLAY - A TASK public void perform() { you.need(To.doTheFollowing( // actions Click.onThe(OptionsMenu.EDIT_BUTTON), ClearTheContent.ofThe(Editor.CONTENT_PANEL), Type.theText(newContent). intoThe(Editor.CONTENT_PANEL), Click.onThe(Editor.SAVE_BUTTON) )); }
  19. 19. 2012 - THE JOURNEY PATTERN Actor performs Tasks has Abilities composed of enable Actions interact with Screen contains Elements
  20. 20. JOURNEY PATTERN APPLIED JUNIT Roles ➥ Goals ➥ Tasks ← Who ← Why ← What ➥ Actions ← How Actor theReceptionist = new Actor().with(WebBrowsing.ability()); @Test public void should_find_all_owners_by_default theReceptionist.attemptsTo( Go.to(findOwnersScreen.url()), Search.forOwnersWith(EMPTY_SEARCH_TERMS), Count.theNumberOfOwners() ); Enter.the(searchTerms). into(findOwnersScreen.searchTerms), Click.onThe(findOwnersScreen.searchButton)
  21. 21. JOURNEY PATTERN APPLIED CUCUMBER Roles ← Who As a Pet Clinic Receptionist ➥ Goals ← Why Scenario: Find all owners by default ← What When I search for owners with BLANK search terms @When (“^I search for owners with BLANK search terms$”) ➥ Tasks theReceptionist.attemptsTo( Search.forOwnersWith(EMPTY_SEARCH_TERMS) ); ➥ Actions ← How Enter.the(searchTerms). into(findOwnersScreen.searchTerms),
  22. 22. PUTTING IT ALL TOGETHER Actor theReceptionist = new Actor().with(WebBrowsing.ability()); theReceptionist.attemptsTo( Go.to(findOwnersScreen.url()), Search.forOwnersWith(EMPTY_SEARCH_TERMS), Count.theNumberOfOwners() ); assertThat( theReceptionist.sawThatThe(numberOfOwners()), was(theExpectedNumberOfOwners) );
  23. 23. A TASK … private static String searchTerms; @Override public void performAs(Actor asAReceptionist) { asAReceptionist.attemptTo( Enter.the(searchTerms).into(findOwnersScreen.searchTerms), Click.onThe(findOwnersScreen.searchButton) ); } public SearchForOwnersWith(String searchTerms) { this.searchTerms = searchTerms; } …
  24. 24. A SCREEN @Url("owners/find.html") public class FindOwnersScreen extends WebScreen { @LocateBy(css="#search-owner-form input") public ScreenElement searchTerms; @LocateBy(css="#search-owner-form button") public ScreenElement searchButton; }
  25. 25. AN ACTION public class Enter extends WebDriverInteraction implements Perform { private String text; private ScreenElement field; public void performAs(Actor actor) { web(actor).findElement(field.locator()).sendKeys(text); } public Enter(String text) { this.text = text; } public static Enter the(String text) {return new Enter(text);} public Perform into(ScreenElement field) { this.field = field; return this; } }
  26. 26. PROBLEMS SOLVED • Smaller “Screen” classes • Small, focused “Task” classes • Readable code • Consistent metaphor • Minimal inheritance • Removed need for duplication across behaviours previously in PageObjects or “Navigation” classes
  27. 27. DESIGN PRINCIPLES • DRY - navigational steps in one place • Separation of Concerns - Page Structure and Actions separate • Small Classes - easy to comprehend • Single Responsibility - classes focused on one thing and one thing only • Minimise conditional logic - navigational if-thens replaced with composable sequences
  28. 28. SCREENPLAY REVIVED Under development for everyone to use Watch This Space!
  29. 29. CONTACT • Kostas Mamalis @agiletestinguk kostas@masterthought.net • Antony Marcano @AntonyMarcano antony@riverglide.com • Jan Molak @JanMolak jan.molak@smartcodeltd.co.uk
  30. 30. THANK YOU!
  • CrissChan

    Sep. 30, 2018
  • escame1

    Sep. 11, 2018
  • kolodzig

    Jan. 11, 2018
  • atilainovecky

    Apr. 10, 2017
  • draganspiridonov

    Nov. 6, 2016
  • DermitzakisYiannis

    Oct. 5, 2015
  • derylspielman

    May. 31, 2015
  • trinhhung1801

    Mar. 19, 2015
  • dav1d1uu

    Dec. 17, 2014
  • itrendafilova

    Apr. 29, 2014
  • stefanbirkner

    Nov. 26, 2013
  • acarpe

    Nov. 25, 2013
  • powerirs

    Nov. 11, 2013
  • deniskozhevnikov

    Nov. 10, 2013
  • stasde

    Nov. 8, 2013

A story of one organisation taking an idea, formed by Antony Marcano and evolved by many, to solve some of the challenges that encountered with the growth of Selenium/WebDriver PageObjects in their Automated Tests. Talk co-presented with two of the people who have been a part of the journey – including Kostas Mamalis & Jan Molak.

Vistas

Total de vistas

13.165

En Slideshare

0

De embebidos

0

Número de embebidos

282

Acciones

Descargas

124

Compartidos

0

Comentarios

0

Me gusta

15

×