News for hackers. Stuff that matters.
Re:Web Automation: Don't Use Selenium, Use Playwright by MetaWhirledPeas on Wednesday November 09, 2022 @06:03PM (#33539435)
> It's awfully nice if you used Page Object Model and you have a single-point-of-truth to fix it.

I like fewer sources of truth, but I dislike trying to force everything into a "page" analogy. Try maintaining a library of commonly-used actions instead, like:

  logIn()
  registerNewUser()
  addItemToCart()
And maybe group them thematically.

The underlying intent is the same... reduce duplication, improve organization. But you won't be stuck wondering "what page am I on now?" in a single page application, or rifling through folder upon folder of nonsensical "page" files.

And even in the worst case, Ctrl-Shift-H still works.

Re:Web Automation: Don't Use Selenium, Use Playwright by geoelectric on Wednesday November 09, 2022 @06:09PM (#33539495)
I could get into an even longer discussion on this, but basically when I brought up UI automation teams my advice was:

Use granular element-oriented functions (i.e. loginButton.click() or fillForm(name, pw) type stuff for the very small part of the very few tests that were specifically exercising that portion of the UI. Those you probably define traditionally for POM, as methods of the page (or functions in the page module depending on the language).

Use result-oriented functions (logIn(), registerNewUser()) whenever it's "travel" i.e. things you do to get to the start of your scenario, or a setup/cleanup task. Those you do not keep with your pages, they live in modules organized by task or result.

Travel is really all setup, but for some reason when it's "set up yourself via login, navigation, option selection, etc" people's thought process goes out the window.

The advantage is that if you could wave a magic wand for setup, travel, or cleanup and get the result, the test would still work and be valid. IOW, you can select the most robust and direct way to accomplish those things, even going completely around the UI with cookie injection or whatever.

Intelligently separating out the very small set of "critical UI manipulation that causes a state change + verification of that change" that is the test from everything else in the scenario that is setup/travel/cleanup gives you much more maintainable tests.

What most other teams I've had visibility into tend to do differently than I advised is they'll use the granular functions everywhere except fixture setup/cleanup. They don't have the "travel" concept of things you have to do on the way to your scenario start, and they include that in the test scenario itself with granular element calls.

Or even when they do separate them out, they're not really "result-oriented" functions. Instead they're "flow-oriented" macros that you couldn't replace with a magic wand, because the meat of the test assumes intermediate UI operations they performed rather than just end state.

Then you have the systems that try to use the same functions for setup/cleanup and testing, caught in between the need for granularity and robustness. Those tend to get extra "doItThisWay" flags on their functions and stuff really goes to hell.

Gotta keep 'em separated!

TL;DR I agree with you, and even a few steps further.

Re:Web Automation: Don't Use Selenium, Use Playwright by abracadabra_ on Thursday November 10, 2022 @05:08AM (#33544454)
That sounds similar to the Screenplay pattern [1]

This has the concept of actors, abilities, interactions, questions, and tasks. This allows good separation of concerns as well as much more user-focused tests.

[1] https://serenity-js.org/handbook/design/screenplay-pattern.h...

Re:Web Automation: Don't Use Selenium, Use Playwright by geoelectric on Thursday November 10, 2022 @04:03PM (#33553329)
Oh, wow! I had been trying to develop a pattern like this out a few years ago, ~2016 (at the time, called Action-Flow), but ended up shifting out of test as a primary focus before I could put polish on it and make it cohesive enough to publish something.

I hadn't realized there was prior art to look at or potentially clone by mistake. I wonder how old this pattern is.

Thanks for showing me!

Re:Web Automation: Don't Use Selenium, Use Playwright by nickstinemates on Thursday November 10, 2022 @10:52AM (#33548234)
A long time ago I wrote an enterprise automation platform that abstracted things into a business-minded DSL like your example above. Wired together with XML. Allowed a tools team to define new DSL and tests to be composed more simply by intent. Workflow would look something like

    createUser
    logIn
    addCreditCard
    addItemToCart
    checkoutItem
Was pretty powerful, but ended up being used more as a CD platform for testing and less like automated regression testing.
Re:Web Automation: Don't Use Selenium, Use Playwright by epolanski on Thursday November 10, 2022 @05:47PM (#33554708)
You can write fixtures for those in Playwright.