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

Four Tips for More Testable UI

Four Tips for More Testable UI

Quick talk given at the 2019 Microsoft MVP summit during the ALM group's MVP2MVP sessions.

Jim Holmes

March 17, 2019
Tweet

More Decks by Jim Holmes

Other Decks in Technology

Transcript

  1. Testable UIs

    View full-size slide

  2. Or:
    How to help your test
    automation folks
    drink less

    View full-size slide

  3. Fortune 10 client
    Java 6
    Enterprise-ready components
    HP build and SCM tools
    “What’s a unit test?”

    View full-size slide

  4. Generalized Talk
    Ideas apply to all UI and
    automation tools

    View full-size slide

  5. https://github.com/jimholmes/
    Demo-Site

    View full-size slide

  6. Two main problems
    in all
    UI testing

    View full-size slide

  7. Finding Stuff

    View full-size slide

  8. Also SharePoint

    View full-size slide

  9. Finding stuff
    ==
    Locators

    View full-size slide

  10. For Web, prefer:
    IDs
    CSS/JQuery-ish
    Name
    Custom Attributes

    View full-size slide

  11. As a last resort:
    XPath

    View full-size slide

  12. Create Good
    Locators

    View full-size slide

  13. 0) Own Your
    HTML

    View full-size slide

  14. FindElement.ById(“grid”)

    View full-size slide

  15. 1) Understand your
    controls /
    frameworks

    View full-size slide

  16. FindElement.ByCss(
    “some big stupid CSS string”)

    View full-size slide

  17. Someone changes style

    View full-size slide

  18. FindElement.ById(
    “update-btn”)

    View full-size slide

  19. 2) Tweak dynamic
    data

    View full-size slide

  20. Find elements by text
    content.
    Might not be granular
    enough.

    View full-size slide

  21. No useful attributes

    View full-size slide

  22. ID is position-based.
    Data changes, IDs change.

    View full-size slide

  23. We own the code!

    View full-size slide

  24. Is there some
    useful data in your
    objects?

    View full-size slide

  25. FindElement.ById(
    contains(“Cobb”) )

    View full-size slide

  26. “Name” isn’t all that useful.
    Got contract numbers?
    Project IDs? Other stuff?
    Find good metadata!

    View full-size slide

  27. 3) Make complex async
    less painful

    View full-size slide

  28. wait until expected condition 1
    wait until expected condition 2
    IF SOMETHING
    wait until expected condition 3
    IF SOMETHING ELSE
    wait until expected condition 4
    FINALLY
    wait until expected condition 342

    View full-size slide

  29. We own the code!

    View full-size slide

  30. Create “flags”
    when async is
    complete

    View full-size slide

  31. Wait until
    flags.div(responseType=create)
    exists

    View full-size slide

  32. 0) Add static IDs
    1) Tweak controls
    2) Use data for locators
    3) Build flags/latches for
    complex async

    View full-size slide

  33. https://github.com/jimholmes/
    Demo-Site

    View full-size slide