nbb

ag 2025-01-24T21:37:13.456709Z

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?

Chris McCormick 2025-01-26T01:23:41.638969Z

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/37ecd1ceaddbd5edcfdc62fbed5a724b

ag 2025-01-27T15:22:11.682729Z

Sorry 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!

borkdude 2025-01-24T22:13:09.718079Z

I have an example here: https://github.com/nextjournal/clerk/tree/main/ui_tests Not sure if it's good

Chris McCormick 2025-01-27T01:41:55.613369Z

@borkdude thanks for sharing that link - I ported the reporting stuff into my own one. Very useful!