Upgrade to Pro — share decks privately, control downloads, hide ads and more …

UI ATDD with Selenium

UI ATDD with Selenium

Some slides I put together for a presentation that I never gave, regarding how developers and QA/QE can work together on UI test automation via ATDD with Selenium and page object model.

David Luu

June 08, 2015
Tweet

More Decks by David Luu

Other Decks in Programming

Transcript

  1. (UI) ATDD with Selenium Page Object Model with a bit

    of BDD and Data Driven Testing for developers, QA, the team… Thoughts of David Luu
  2. Audience Statistics • Developers… • Like writing tests? E.g. unit,

    API, integration • Ever developed for non‐web applications? (e.g. desktop, mobile, telecom, hardware) • Ever hear about hooks, back doors added to code or test harnesses built to facilitate (automated) testing? • Like UI/class/object modeling? • Do you prefer writing code for tests or UI/modeling?
  3. Audience Statistics • Quality Engineers, Release QA… • Like writing

    tests? E.g. UI, API, unit, etc. • Like creating & modeling page objects? • Like working on test framework code (!tests)? • Which do of the above do you prefer?
  4. ATDD vs (or from) TDD • The following are just

    my thoughts, not industry standards… • ATDD = doing TDD but via the UI and hence (user) acceptance testing. • ATDD = ignore back end stuff – indirect testing via front end • ATDD = treat sections/components of UI as a unit and test as a UI unit test via ATDD (localized UI test)
  5. ATDD vs (or from) TDD continued • Test interaction/integration of

    different components (i.e. units) of UI with ATDD test that covers interaction of them (an integration test but not end to end test yet) • Test complete implementation with final true ATDD (acceptance) tests of end to end system flow.
  6. How to do ATDD then? • Can do unit &

    API tests followed by ATDD or skip either of the first two, up to team. • Instead of or while creating TDD based unit (or even API) tests, do same for ATDD tests. • ATDD tests are conceived from user stories (in Jira) and more importantly the visual mockups & wireframes.
  7. How to do ATDD continued • Using visual mockups, define

    page object model (POM) for the page. • Start small with sections of the page (i.e. units). • As you build out the units, think of how they interact with each other, and account for that in the modeling (and later testing) • Expand to inter‐page interactions
  8. ATDD by POM • Break down page UI into elements

    (a.k.a. locators, for Selenium) or sets of them • Break down or define the actions or behaviors that can be performed on the page (i.e. this is where the bit of BDD comes in) • Group/organize the actions & elements into logical groupings (i.e. units). • Sort of building a test harness
  9. ATDD by POM continued • Actions include high level ones

    vs low level. High level ones call sets of low level ones, abstracting out the details from the caller/user. • Define actions based on behaviors of elements. It can be: “selected”, “clicked”, “type‐able”. E.g. selectItemName(), clickItem() • We also want to represent state like isItemSelected()
  10. ATDD by POM continued • While not exactly matching the

    model, we also need helper methods to extract data off the page ( getTextOfItemName() ) • We usually type data in as sets of data and consolidate them (rather than be atomic) as methods named fillSomething() like fillPRA(), fillPersonalInfo()
  11. Good POM design vs test cases • Good design practice

    & modeling to not hard code anything into POM classes, with element locator definitions as an exception. • That means no test “data” hard coded as constants/variable or within the methods. • Such test “data” to put in under test case base/parent classes and passed in as arguments/parameters
  12. Good POM design vs test cases • POM class methods

    should take arguments/parameters to define what it should do. • POM class methods w/o arguments do some default action, but that action must not be use default “data”. If it works with data, that data must be passed in as argument whether default or not. Add a wrapper method in base/parent test case that calls POM method with argument for simplicity.
  13. Good POM design vs test cases • What I just

    mentioned previously is the data driven testing aspect of POM and ATDD. • POM classes don’t do assertions. • POM classes that need to check/verify state simply check state and throw exception if not meet criteria. Test case can then assert and/or handle the exception.
  14. How dev & QA/QE involved? • My thoughts… • Devs

    (might) have better UI modeling & programming skills • Devs (might) have better XPath and CSS selectors skills • QEs and RQA have (more?) experience with testing & testing techniques & test automation
  15. How dev & QA/QE involved? • So it seems natural/complementary

    to have… • Devs code the page objects (locators & methods) • QA/QE can write the automated test cases that use the page objects • Or roles can be swapped too or mix & match • Test framework/infrastructure code can be either as well
  16. Ok, when can we start? • Good planning & experience

    tells me that… • You can start ATDD for POM and test cases as soon as the visual specifications are available. • The specs don’t have to be final. The coding of the POM and test cases can be revised midway. • Revising midway is a lot easier than implementing from scratch near the end of the project
  17. Ok, when can we start? Tips • Best to start

    with the POM. • Test cases can come later if need be. • POM should be done when the UI is done. i.e. done in tandem. • That means tests can be written when UI done w/o having to do all the POM work first when project complete
  18. Ok, when can we start? Tips • POM and test

    cases don’t have to work from the start. Just like with TDD, they’re expected to fail until UI (or component) is complete. • For POM, you don’t need to know the element locator values in advance. Fill in later. • For POM, just need to know how to model the methods via spec before implementation. • Use pseudo code as needed in the beginning
  19. Possible concerns… • I heard someone say this type of

    thing… • But implementing all the POM stuff before writing tests could leave unused code. Better to develop POM while/when writing tests. • Well, doing that may fail seeing bigger picture of test coverage areas to cover than doing POM 1st. • Unused methods (and via code coverage check of POM) = test coverage gaps you need to fill by writing tests that use them. That’s the answer.
  20. Possible concerns… • But that don’t cover all… • Be

    sure to think about missing integration test coverage between POM methods (or units) • Think about any missing user stories, or use cases not covered as well.
  21. Benefits of dev & QA in automation • There’s more

    developers than QA/QE to share the automation workload • Devs might do their part faster than QA/QE • Devs (and as result PM, PMO via project schedule) can see that automation work not easy to do & takes time (to do well) by actually participating in the test automation. • Devs can improve on automation codebase with their programming & development skills.