Liking cljdoc? Tell your friends :D

com.blockether.spel.test-fixtures

Shared Playwright test fixtures using Lazytest around hooks.

Provides dynamic vars for Playwright instance, browser, and page, along with around hooks that can be used with Lazytest's :context metadata.

Usage: (ns my-test (:require [com.blockether.spel.allure :refer [defdescribe describe it expect]] [com.blockether.spel.test-fixtures :refer [page with-playwright with-browser with-page]]))

(defdescribe my-test (describe "with full setup" {:context [with-playwright with-browser with-page]} (it "can access page" (expect (some? page)))))

Import defdescribe, describe, it, and expect from com.blockether.spel.allure instead of lazytest.core for a single require. expect auto-creates an Allure step per expectation with its own pass/fail status. The other three delegate to lazytest.core unchanged. All are zero-overhead when not running under the Allure reporter.

Shared Playwright test fixtures using Lazytest around hooks.

Provides dynamic vars for Playwright instance, browser, and page,
along with around hooks that can be used with Lazytest's :context metadata.

Usage:
(ns my-test
  (:require
   [com.blockether.spel.allure :refer [defdescribe describe it expect]]
   [com.blockether.spel.test-fixtures :refer [*page* with-playwright with-browser with-page]]))

(defdescribe my-test
  (describe "with full setup" {:context [with-playwright with-browser with-page]}
    (it "can access page"
      (expect (some? *page*)))))

Import `defdescribe`, `describe`, `it`, and `expect` from
`com.blockether.spel.allure` instead of `lazytest.core` for a single
require. `expect` auto-creates an Allure step per expectation with
its own pass/fail status. The other three delegate to `lazytest.core`
unchanged. All are zero-overhead when not running under the Allure
reporter.
raw docstring

*browser*clj

Dynamic var holding the current Browser instance.

Dynamic var holding the current Browser instance.
sourceraw docstring

*browser-api*clj

Dynamic var holding an APIRequestContext bound to the current BrowserContext. API calls through this context automatically appear in Playwright traces (unlike standalone APIRequestContexts). Bound by with-page (auto-tracing) and with-traced-page. nil otherwise.

Dynamic var holding an APIRequestContext bound to the
current BrowserContext. API calls through this context automatically
appear in Playwright traces (unlike standalone APIRequestContexts).
Bound by with-page (auto-tracing) and with-traced-page. nil otherwise.
sourceraw docstring

*browser-context*clj

Dynamic var holding the current BrowserContext. Bound by with-page (auto-tracing) and with-traced-page. nil otherwise. Useful for accessing context-level APIs like (.request ctx) for traced API calls, cookies, routes, etc.

Dynamic var holding the current BrowserContext.
Bound by with-page (auto-tracing) and with-traced-page. nil otherwise.
Useful for accessing context-level APIs like (.request ctx) for traced
API calls, cookies, routes, etc.
sourceraw docstring

*page*clj

Dynamic var holding the current Page instance.

Dynamic var holding the current Page instance.
sourceraw docstring

*pw*clj

Dynamic var holding the current Playwright instance.

Dynamic var holding the current Playwright instance.
sourceraw docstring

browser-engineclj

(browser-engine)

Returns the browser engine keyword to launch. Checks system property spel.browser first, then env var SPEL_BROWSER. Returns :chromium when unset. Supported: :chromium, :firefox, :webkit.

Usage: clojure -J-Dspel.browser=firefox -M:test SPEL_BROWSER=webkit clojure -M:test

Returns the browser engine keyword to launch.
Checks system property `spel.browser` first, then env var `SPEL_BROWSER`.
Returns :chromium when unset. Supported: :chromium, :firefox, :webkit.

Usage:
  clojure -J-Dspel.browser=firefox -M:test
  SPEL_BROWSER=webkit clojure -M:test
sourceraw docstring

ct-fixtureclj

(ct-fixture around-hook)

Extract the underlying function from a Lazytest around hook.

Lazytest around hooks are maps {:around fn}. clojure.test needs plain functions. This helper extracts the :around fn so you can use Lazytest fixtures with clojure.test/use-fixtures:

(use-fixtures :once (ct-fixture with-playwright) (ct-fixture with-browser)) (use-fixtures :each (ct-fixture with-traced-page) with-allure-context)

Extract the underlying function from a Lazytest around hook.

Lazytest around hooks are maps {:around fn}. clojure.test needs plain
functions. This helper extracts the :around fn so you can use Lazytest
fixtures with clojure.test/use-fixtures:

  (use-fixtures :once (ct-fixture with-playwright) (ct-fixture with-browser))
  (use-fixtures :each (ct-fixture with-traced-page) with-allure-context)
sourceraw docstring

interactive?clj

(interactive?)

Returns true when tests should run in interactive (headed) mode. Checks system property spel.interactive first, then env var SPEL_INTERACTIVE. Any truthy string value (e.g. "true", "1", "yes") enables interactive mode.

Usage: clojure -J-Dspel.interactive=true -M:test SPEL_INTERACTIVE=true clojure -M:test

Returns true when tests should run in interactive (headed) mode.
Checks system property `spel.interactive` first, then env var `SPEL_INTERACTIVE`.
Any truthy string value (e.g. "true", "1", "yes") enables interactive mode.

Usage:
  clojure -J-Dspel.interactive=true -M:test
  SPEL_INTERACTIVE=true clojure -M:test
sourceraw docstring

slow-moclj

(slow-mo)

Returns the slow-mo delay in milliseconds for browser actions. Checks system property spel.slow-mo first, then env var SPEL_SLOW_MO. Returns 0 when unset. Useful for watching tests step-by-step in headed mode.

Usage: clojure -J-Dspel.slow-mo=500 -J-Dspel.interactive=true -M:test SPEL_SLOW_MO=500 SPEL_INTERACTIVE=true clojure -M:test

Returns the slow-mo delay in milliseconds for browser actions.
Checks system property `spel.slow-mo` first, then env var `SPEL_SLOW_MO`.
Returns 0 when unset. Useful for watching tests step-by-step in headed mode.

Usage:
  clojure -J-Dspel.slow-mo=500 -J-Dspel.interactive=true -M:test
  SPEL_SLOW_MO=500 SPEL_INTERACTIVE=true clojure -M:test
sourceraw docstring

with-api-tracingclj

Around hook: creates a BrowserContext with Playwright tracing for API-only tests (no page needed).

Configuration via system properties / env vars: spel.interactive / SPEL_INTERACTIVE — headed mode (default: headless) spel.slow-mo / SPEL_SLOW_MO — action delay in ms (default: 0) spel.browser / SPEL_BROWSER — engine: chromium|firefox|webkit (default: chromium)

Requires pw to be bound (use with with-playwright). Binds: browser-context — the BrowserContext (for advanced use) browser-api — APIRequestContext from the context; all HTTP calls through this appear in the Playwright trace

When the Allure reporter is active, also enables tracing and HAR recording: allure/trace-path — where the trace zip will be written allure/har-path — where the HAR file will be written

When the Allure reporter is NOT active, browser-api is still bound (backed by a real BrowserContext) so tests work consistently — just without trace overhead.

Usage: {:context [with-playwright with-test-server with-api-tracing]}

(it "calls API with tracing" (let [resp (api/api-get browser-api (str test-server-url "/health"))] (expect (= 200 (api/api-response-status resp)))))

Around hook: creates a BrowserContext with Playwright tracing
 for API-only tests (no page needed).

Configuration via system properties / env vars:
  spel.interactive / SPEL_INTERACTIVE — headed mode (default: headless)
  spel.slow-mo     / SPEL_SLOW_MO    — action delay in ms (default: 0)
  spel.browser     / SPEL_BROWSER    — engine: chromium|firefox|webkit (default: chromium)

Requires *pw* to be bound (use with with-playwright).
Binds:
  *browser-context*   — the BrowserContext (for advanced use)
  *browser-api*       — APIRequestContext from the context; all HTTP calls
                        through this appear in the Playwright trace

When the Allure reporter is active, also enables tracing and HAR recording:
  allure/*trace-path* — where the trace zip will be written
  allure/*har-path*   — where the HAR file will be written

When the Allure reporter is NOT active, *browser-api* is still bound
(backed by a real BrowserContext) so tests work consistently — just
without trace overhead.

Usage:
  {:context [with-playwright with-test-server with-api-tracing]}

  (it "calls API with tracing"
    (let [resp (api/api-get *browser-api*
                            (str *test-server-url* "/health"))]
      (expect (= 200 (api/api-response-status resp)))))
sourceraw docstring

with-browserclj

Around hook: launches and closes a browser.

Configuration via system properties / env vars: spel.interactive / SPEL_INTERACTIVE — headed mode (default: headless) spel.slow-mo / SPEL_SLOW_MO — action delay in ms (default: 0) spel.browser / SPEL_BROWSER — engine: chromium|firefox|webkit (default: chromium)

Requires pw to be bound (use with with-playwright). Binds the Browser instance to browser.

Around hook: launches and closes a browser.

Configuration via system properties / env vars:
  spel.interactive / SPEL_INTERACTIVE — headed mode (default: headless)
  spel.slow-mo     / SPEL_SLOW_MO    — action delay in ms (default: 0)
  spel.browser     / SPEL_BROWSER    — engine: chromium|firefox|webkit (default: chromium)

Requires *pw* to be bound (use with with-playwright).
Binds the Browser instance to *browser*.
sourceraw docstring

with-pageclj

Around hook: creates and closes a page (default — no context opts).

Requires browser to be bound (use with with-browser). Binds the Page instance to page and allure/page (for automatic step screenshots).

When the Allure reporter is active, automatically enables Playwright tracing (screenshots + DOM snapshots + sources) and HAR recording. Also binds browser-context and browser-api so API calls made through browser-api appear in the Playwright trace. The Allure reporter picks up the trace and HAR files and attaches them to the test result — zero configuration needed in tests.

To pass context-opts (viewport, locale, etc.), use with-page-opts instead.

Around hook: creates and closes a page (default — no context opts).

Requires *browser* to be bound (use with with-browser).
Binds the Page instance to *page* and allure/*page* (for automatic
step screenshots).

When the Allure reporter is active, automatically enables Playwright
tracing (screenshots + DOM snapshots + sources) and HAR recording.
Also binds *browser-context* and *browser-api* so API calls made
through *browser-api* appear in the Playwright trace.
The Allure reporter picks up the trace and HAR files and attaches
them to the test result — zero configuration needed in tests.

To pass context-opts (viewport, locale, etc.), use `with-page-opts` instead.
sourceraw docstring

with-page-optsclj

(with-page-opts context-opts)

Like with-page but accepts context-opts for the BrowserContext.

Returns a Lazytest around hook that creates a BrowserContext with the given opts merged in, then creates a page from that context.

Context opts support all Browser$NewContextOptions keys: :locale, :viewport, :color-scheme, :storage-state, :user-agent, :timezone-id, :permissions, etc.

Usage: {:context [with-playwright with-browser (with-page-opts {:locale "fr-FR" :viewport {:width 375 :height 812}})]}

HAR recording opts are set automatically when the Allure reporter is active.

Like `with-page` but accepts context-opts for the BrowserContext.

Returns a Lazytest around hook that creates a BrowserContext with the
given opts merged in, then creates a page from that context.

Context opts support all Browser$NewContextOptions keys:
  `:locale`, `:viewport`, `:color-scheme`, `:storage-state`,
  `:user-agent`, `:timezone-id`, `:permissions`, etc.

Usage:
  {:context [with-playwright with-browser (with-page-opts {:locale "fr-FR"
                                                            :viewport {:width 375 :height 812}})]}

HAR recording opts are set automatically when the Allure reporter is active.
sourceraw docstring

with-playwrightclj

Around hook: creates and closes a Playwright instance.

Binds the Playwright instance to pw. Also installs a lightweight try-test-case wrapper that binds allure/*test-title* from the test case doc string, so trace groups and step names work even without the Allure reporter.

Around hook: creates and closes a Playwright instance.

Binds the Playwright instance to *pw*.
Also installs a lightweight try-test-case wrapper that binds
`allure/*test-title*` from the test case doc string, so trace
groups and step names work even without the Allure reporter.
sourceraw docstring

with-traced-pageclj

Around hook: creates a BrowserContext with HAR recording and Playwright tracing enabled, then creates a page from that context (default — no context opts).

Requires browser to be bound (use with with-browser). Binds: page — the Page instance allure/page — for automatic step screenshots allure/trace-path — where the trace zip will be written allure/har-path — where the HAR file will be written

On teardown:

  1. Closes page (removes page-level activity)
  2. Stops tracing (writes trace.zip, decrements tracingCount)
  3. Closes context on a daemon thread with a 5s timeout (writes HAR).

The Allure reporter picks up trace-path and har-path and attaches them to the test result automatically.

To pass context-opts (viewport, locale, etc.), use with-traced-page-opts instead.

Around hook: creates a BrowserContext with HAR recording and Playwright
tracing enabled, then creates a page from that context (default — no context opts).

Requires *browser* to be bound (use with with-browser).
Binds:
  *page*             — the Page instance
  allure/*page*      — for automatic step screenshots
  allure/*trace-path* — where the trace zip will be written
  allure/*har-path*   — where the HAR file will be written

 On teardown:
   1. Closes page (removes page-level activity)
   2. Stops tracing (writes trace.zip, decrements tracingCount)
   3. Closes context on a daemon thread with a 5s timeout (writes HAR).

The Allure reporter picks up *trace-path* and *har-path* and attaches
them to the test result automatically.

To pass context-opts (viewport, locale, etc.), use `with-traced-page-opts` instead.
sourceraw docstring

with-traced-page-optsclj

(with-traced-page-opts context-opts)

Like with-traced-page but accepts context-opts for the BrowserContext.

Returns a Lazytest around hook that creates a BrowserContext with the given opts merged in, HAR recording, and Playwright tracing enabled.

Context opts support all Browser$NewContextOptions keys: :locale, :viewport, :color-scheme, :storage-state, :user-agent, :timezone-id, :permissions, etc.

HAR recording opts (:record-har-path, :record-har-mode) are always set by this hook — user opts are merged first, then HAR opts overlay.

Usage: {:context [with-playwright with-browser (with-traced-page-opts {:locale "fr-FR" :viewport {:width 375 :height 812}})]}

The Allure reporter picks up trace-path and har-path and attaches them to the test result automatically.

Like `with-traced-page` but accepts context-opts for the BrowserContext.

Returns a Lazytest around hook that creates a BrowserContext with the
given opts merged in, HAR recording, and Playwright tracing enabled.

Context opts support all Browser$NewContextOptions keys:
  `:locale`, `:viewport`, `:color-scheme`, `:storage-state`,
  `:user-agent`, `:timezone-id`, `:permissions`, etc.

HAR recording opts (`:record-har-path`, `:record-har-mode`) are always
set by this hook — user opts are merged first, then HAR opts overlay.

Usage:
  {:context [with-playwright with-browser (with-traced-page-opts {:locale "fr-FR"
                                                                   :viewport {:width 375 :height 812}})]}

The Allure reporter picks up *trace-path* and *har-path* and attaches
them to the test result automatically.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close