Skip to content

Commit

Permalink
add test examples (#251)
Browse files Browse the repository at this point in the history
* add test examples

* update
  • Loading branch information
Uunnamed authored Jul 27, 2020
1 parent b9e5050 commit 52d503a
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1373,15 +1373,13 @@ If for some reason you want to use a single instance, you can use fixtures like
(def ^:dynamic *driver*)

(defn fixture-browser [f]
(let [driver (chrome-headless)]
(with-chrome-headless {:args ["--no-sandbox"]} driver
(disconnect-driver driver)
(binding [*driver* driver]
(disconnect-driver driver)
(f))
(connect-driver driver)
(quit driver)))
(connect-driver 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:
;; creating a session every time that automatically erases resources
(defn fixture-clear-browser [f]
(connect-driver *driver*)
(go *driver* "http://google.com")
Expand All @@ -1393,14 +1391,34 @@ If for some reason you want to use a single instance, you can use fixtures like
:once
fixture-browser)

;;this is run `every` time before each test
;; this is run `every` time before each test
(use-fixtures
:each
fixture-clear-browser)

...some tests
```

For faster testing you can use this example:

```clojure
.....

(defn fixture-browser [f]
(with-chrome-headless {:args ["--no-sandbox"]} driver
(binding [*driver* driver]
(f))))

;; note that resources, such as cookies, are deleted manually,
;; so this does not guarantee that the tests are clean
(defn fixture-clear-browser [f]
(delete-cookies *driver*)
(go *driver* "http://google.com")
(f))

......
```

### Multi-Driver Fixtures

In the example above, we examined a case when you run tests against a single
Expand Down

0 comments on commit 52d503a

Please sign in to comment.