From b9e505083c67e50334a2a6cca7df44e5f2168b9b Mon Sep 17 00:00:00 2001 From: "Alex.Shi" Date: Mon, 27 Jul 2020 11:18:34 +0300 Subject: [PATCH] add fixture example (#248) * add fixture example * update * update * fix --- README.md | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/README.md b/README.md index 55bbd6ba..03f67e1d 100644 --- a/README.md +++ b/README.md @@ -1361,6 +1361,46 @@ point to the target driver during the tests. )) ``` +If for some reason you want to use a single instance, you can use fixtures like this: + + +```clojure +(ns project.test.integration + "A module for integration tests" + (:require [clojure.test :refer :all] + [etaoin.api :refer :all])) + +(def ^:dynamic *driver*) + +(defn fixture-browser [f] + (let [driver (chrome-headless)] + (binding [*driver* driver] + (disconnect-driver driver) + (f)) + (connect-driver driver) + (quit driver))) + +;; if you want reset some changes (delete cookie, refresh page and etc), or Vice versa, +;; make pre-settings before test you can use fixture like this: +(defn fixture-clear-browser [f] + (connect-driver *driver*) + (go *driver* "http://google.com") + (f) + (disconnect-driver *driver*)) + +;; this is run `once` before running the tests +(use-fixtures + :once + fixture-browser) + +;;this is run `every` time before each test +(use-fixtures + :each + fixture-clear-browser) + +...some tests +``` + ### Multi-Driver Fixtures In the example above, we examined a case when you run tests against a single