Fork me on GitHub
#off-topic
<
2023-04-27
>
DenisMc04:04:00

Hi, I’m looking for some pointers from people who have an automated test set-up for a web app that they are happy with. I need to put together an automated suite of functional and unit tests thst will comprehensively test a web app, It would be great if I had a test setup that a) makes it easy to add additional functional/unit tests, and b) can deal with the inherently flaky nature of browser tests in a straightforward way. Any tips/examples of test setups that are working well for people most welcome.

Robert Todea05:04:13

Hi @U02HPS0397S! What is your previous experience in the automation ecosystem? You mention functional/unit/browser tests.

DenisMc05:04:52

Been a few years on the browser side, but I developed a selenium suite in my time. Our project already has api tests using clojure.test/ring.mock, which are executed on GitHub actions. I also have Datadog synthetic tests that run on deployed systems (staging and production). It’s that selenium-type bit that I’m most curious about where the current state of the art might be, plus any other tips or insights that people might have of course.

Robert Todea05:04:08

Thanks for the context. In the browser tests ecosystem, the new kid on the block is Cypress, https://docs.cypress.io/guides/end-to-end-testing/writing-your-first-end-to-end-test. The developer experience is better than Selenium.

Robert Todea05:04:25

And of course, nothing is for free, there are some limitations: https://docs.cypress.io/guides/references/trade-offs

Robert Todea05:04:03

I.e. • Cypress is not a general purpose https://docs.cypress.io/guides/references/trade-offs#Automation-restrictions. • Cypress commands run https://docs.cypress.io/guides/references/trade-offs#Inside-the-browser. • There will never be support for https://docs.cypress.io/guides/references/trade-offs#Multiple-tabs. • You cannot use Cypress to drive https://docs.cypress.io/guides/references/trade-offs#Multiple-browsers-open-at-the-same-time. • Each test is bound to a single superdomain. Cross-origin navigation inside tests can be enabled by using the cy.origin command. Please read our https://docs.cypress.io/guides/guides/cross-origin-testing.

Robert Todea05:04:11

Also, if you want to test individual components (not setting up the entire stack) you can go the Storybook route: https://storybook.js.org/docs/react/writing-tests/introduction The main features: 1. https://storybook.js.org/docs/react/writing-tests/interaction-testing --- similar to Cypress/Selenium 2. https://storybook.js.org/docs/react/writing-tests/visual-testing --- the KILLER feature ⚠️ Again, nothing is for free, visual regression needs a https://www.chromatic.com/ account, where you have quotas (how many individual snapshots you are comparing per month).

DenisMc05:04:19

Thanks. I have heard of cypress but not storybook. I’m ok paying a little money if the dev time savings make it a sensible choice.

respatialized13:04:03

are you looking to stay primarily in JS, or is this a ClojureScript context? if so, the three libraries that you can combine to simulate and test against flaky behavior with retry capabilities would be: • https://github.com/clj-commons/etaoin for webdriver actions and browser automation • https://github.com/BrunoBonacci/safely for controlled retries of requests and actions • https://github.com/clojure/test.check to generate sequences of actions with controlled randomness and define higher-level properties that should still hold across failures and retries I like how easily I could get etaoin set up and define sequences of browser actions as pure data, but it may be less fully featured than the JS libraries you're considering (nothing even close to visual regressions, for example).

Daniel Gerson14:04:46

The intent behind the functionality mentioned in this post might be useful https://clojurians.slack.com/archives/C029PTWD3HR/p1681476571721689

alpox19:04:37

There is now also https://playwright.dev/ in the space of cypress. I have seen some people moving over

DenisMc20:04:59

No clojurescript yet, pure JS.

DenisMc23:04:15

Thanks for the feedback anyhow folks, very useful:+1:

ezra00:04:21

+1 for Playwright - Cypress is great (I’ve used it since ~2018), but Playwright feels much more powerful to me

flowthing09:04:58

I’ve also come to prefer Playwright. Playwright for Java is especially nice in that it makes it easy to e.g. seed your database with test data before running your tests (if you have a Clojure backend).