I'm messing around with Playwright, what's the current way of running tests with assertions? Should I use nbb-test-runner? Does anyone know some good examples?
I've done this on a couple of projects for e2e tests (which have been a lifesaver for checking all the basic things work before deploying). I integrated playwright with clojure.test. Here's a stripped down demo I just made that just runs one test checking the title of the page:
(ns testdemo
(:require
["playwright$default" :as pw]
[clojure.test :refer [deftest is use-fixtures async] :as t]
[promesa.core :as p]))
(def rig (atom nil))
(use-fixtures
:once
{:before
#(async done
(p/let [browser (.launch pw/chromium #js {:headless true})
context (.newContext browser)
page (.newPage context)]
(reset! rig {:page page :browser browser})
(done)))
:after
#(async done
(p/let [{:keys [browser]} @rig]
(.close browser)
(done)))})
(deftest load-localhost
(async
done
(p/let [{:keys [page]} @rig]
(.goto page "")
(p/let [title (.title page)]
(is (= title "Expected Title"))
(done)))))
(t/run-tests 'testdemo)
https://gist.github.com/chr15m/37ecd1ceaddbd5edcfdc62fbed5a724bSorry for the delayed response - fell off the grid for a couple of days. I'm looking at these tests (very nice and educational btw, thanks @borkdude) and I don't see stuff like:
(require '["playwright/test" :refer [test expect]])
So, you don't use Playwright assertions at all? One thing that makes me confused is that something like:
(p/then #(.toBeVisible (expect %))) surprisingly returns nil - even when the assertion is correct.
I'm curious if you guys know anything about that?
Anyway, I'll probably try to adopt your style, Michiel. Many thanks!
I have an example here: https://github.com/nextjournal/clerk/tree/main/ui_tests Not sure if it's good
@borkdude thanks for sharing that link - I ported the reporting stuff into my own one. Very useful!