Add tests classes to Login dialog (and others)

I’ve been using Selenium to automate some end-to-end tests, and had to do some funky XPATH locaters to automate typing an email and password into the built-in login dialog and then clicking the Login button. It would be super helpful if all the built-in UIs had testing classes on all their elements for making locating them easier.

1 Like

You could use playwright instead of selenium and just avoid that pain entirely.

1 Like

I’m sure there’s some clever way that Playwright uses to select items that doesn’t require using classes or ids, but a quick glance at their front page didn’t show it. Can you share how it avoids the pain of locating the fields on the built-in login dialog?

Playwright uses selectors similar to jQuery, optimized for testing.

I’m on my cell now and don’t remember exactly what I do, but I remember using it with anvil apps and selecting a button by the text it contains or a textbox by its placeholder or the nth textbox in the page for example.

By default it works with an headless browser, which didn’t play nice with some features. I modified my tests so they use a visible browser, it’s slightly slower, but on the bright side it allows to interrupt the test and play around with the selector on the browser used by playwright.

Yeah, I’d rather not need to change my tests when cosmetic changes happen. Selecting by a class insulates me from that. It just doesn’t work on the built-in Anvil dialogs, since they weren’t built with that in mind.

I agree, and you can use roles or other classes part of the Anvil framework.

I do agree, but I still like to use attributes that are visible. In my experience understanding the reason of the failure and updating a test that fails because a text in a button has changed takes a few seconds, while designing solid tests takes forever, those tests are never solid anyway, and understanding that a selector stopped working because classes have changed is a pain. I like even less creating classes just for the tests, because it’s time expensive and you end up testing your tests instead of testing your app.

EDIT
I am at the computer now, here is how I test a sign in in playwright (get_secret is a helper function that gets values from a source external to the repository):

    page.fill('input[placeholder="email@address.com"]', get_secret('anvil user name'))
    page.fill('input[placeholder="password"]', get_secret('anvil password'))
    page.click(".btn-success >> text='Log In'")