A powerful, elegant testing library for Clojure that combines Serenity BDD reporting with Playwright browser automation and REST Assured API testing. Write beautiful, readable tests in pure Clojure with automatic screenshots, step-by-step reporting, and rich HTML documentation.
clojure.test - no Java interop requiredAdd to your deps.edn:
{:deps {com.alpha-prosoft/serenity-clojure {:mvn/version "1.4"}}}
Or with Leiningen (project.clj):
:dependencies [[com.alpha-prosoft/serenity-clojure "1.4"]]
Install Playwright browsers:
npx playwright install chromium
(ns my-app.tests
(:require [clojure.test :refer [deftest is]]
[testing.junit :refer [with-serenity step take-screenshot]]))
(deftest simple-navigation-test
(with-serenity [page]
(step "Navigate to example.com"
#(do
(.navigate page "https://example.com")
(take-screenshot page "homepage")))
(step "Verify page title"
#(is (clojure.string/includes? (.title page) "Example")))))
Generate reports:
clojure -M -e "(require '[testing.junit :as junit])(junit/generate-reports)"
View results:
Open target/site/serenity/index.html in your browser to see beautiful test reports with embedded screenshots.
with-serenity [page]Main test wrapper that provides:
(deftest my-test
(with-serenity [page]
;; `page` is a Playwright Page instance
;; Browser runs in headless Chromium by default
;; All events are automatically reported to Serenity
(.navigate page "https://example.com")))
step [description f]Execute a test step with automatic reporting:
(step "Navigate to homepage"
#(.navigate page "https://example.com"))
api-step [description f]Execute an API call with automatic REST logging:
step with SerenityRest integration(api-step "Get user details"
#(-> (SerenityRest/given)
(.get "/users/1")
(.then)
(.statusCode 200)))
take-screenshot [page description]Capture and attach screenshot to current step:
(take-screenshot page "after-login")
;; => "after_login-1767163337862-1.png"
Screenshots appear in reports as:
generate-reports []Generate HTML reports from JSON test results:
(require '[testing.junit :as junit])
(junit/generate-reports)
Outputs:
========================================
Generating Serenity Reports
========================================
Source: target/site/serenity
Project: Serenity Clojure
✓ HTML reports generated
Open: target/site/serenity/index.html
========================================
serenity.properties# Project identification
serenity.project.name=My Test Project
# Output directory
serenity.outputDirectory=target/site/serenity
# Screenshot settings (manual via take-screenshot)
serenity.take.screenshots=FOR_EACH_ACTION
# Report configuration
serenity.report.json=true
serenity.report.show.step.details=true
serenity.console.colors=true
clojure -M:test -e "(require '[my-app.tests])(clojure.test/run-tests 'my-app.tests)"
clojure -M -e "(require '[testing.junit :as junit])(junit/generate-reports)"
# Open in browser
open target/site/serenity/index.html
# Or use Python
python3 -m http.server 8000 --directory target/site/serenity
Serenity Clojure follows these principles:
See LICENSE file for details.
Built with:
Made with ❤️ for the Clojure testing community
Can you improve this documentation?Edit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |