Skip to content

Commit

Permalink
Simplify cookies tests
Browse files Browse the repository at this point in the history
They don't vary across browsers, so stop distinguishing.
I think we are accidentally skipping checks for edge as well.
And delete phantom specific handling, we don't support phantom anymore.
  • Loading branch information
lread committed Mar 17, 2024
1 parent 3191663 commit ceda6b3
Showing 1 changed file with 25 additions and 98 deletions.
123 changes: 25 additions & 98 deletions test/etaoin/api_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -543,105 +543,32 @@

(deftest test-cookies
(testing "getting all cookies"
(let [cookies (e/get-cookies *driver*)]
(e/when-safari *driver*
;; Safari Webdriver v16.4 added sameSite, we'll ignore it for now
(let [cookies (map #(dissoc % :sameSite) cookies)]
(is (= cookies
[{:domain ".^filecookies^"
:secure false
:httpOnly false
:value "test1"
:path "/"
:name "cookie1"}
{:domain ".^filecookies^"
:secure false
:httpOnly false
:value "test2"
:path "/"
:name "cookie2"}]))))
(e/when-chrome *driver*
(is (= cookies [{:domain "localhost"
:httpOnly false
:name "cookie2"
:path "/"
:sameSite "Lax"
:secure false
:value "test2"}
{:domain "localhost"
:httpOnly false
:name "cookie1"
:path "/"
:sameSite "Lax"
:secure false
:value "test1"}])))
(e/when-firefox *driver*
;; Firefox Webdriver added sameSite, we'll ignore it for now
(let [cookies (map #(dissoc % :sameSite) cookies)]
(is (= cookies [{:name "cookie1",
:value "test1",
:path "/",
:domain "localhost",
:secure false,
:httpOnly false}
{:name "cookie2",
:value "test2",
:path "/",
:domain "localhost",
:secure false,
:httpOnly false}]))))
(e/when-phantom *driver*
(is (= cookies [{:domain "localhost",
:httponly false,
:name "cookie2",
:path "/",
:secure false,
:value "test2"}
{:domain "localhost",
:httponly false,
:name "cookie1",
:path "/",
:secure false,
:value "test1"}])))))
(let [cookies (e/get-cookies *driver*)
sorted-cookies (->> cookies
(map #(dissoc % :sameSite)) ;; varies, maybe we don't care about this one
(sort-by :name) ;; order varies we don't care
)]
(is (= sorted-cookies [{:domain "localhost"
:httpOnly false
:name "cookie1"
:path "/"
:secure false
:value "test1"}
{:domain "localhost"
:httpOnly false
:name "cookie2"
:path "/"
:secure false
:value "test2"}]))))
(testing "getting a cookie"
(let [cookie (e/get-cookie *driver* :cookie2)]
(e/when-safari *driver*
;; Safari Webdriver v16.4 added sameSite, we'll ignore it for now
(let [cookie (dissoc cookie :sameSite)]
(is (= cookie
{:domain ".^filecookies^"
:secure false
:httpOnly false
:value "test2"
:path "/"
:name "cookie2"}))))
(e/when-chrome *driver*
(is (= cookie
{:domain "localhost"
:httpOnly false
:name "cookie2"
:path "/"
:sameSite "Lax"
:secure false
:value "test2"})))
(e/when-firefox *driver*
;; Firefox Webdriver added sameSite, we'll ignore it for now
(let [cookie (dissoc cookie :sameSite)]
(is (= cookie
{:name "cookie2"
:value "test2"
:path "/"
:domain "localhost"
:secure false
:httpOnly false}))))
(e/when-phantom *driver*
(is (= cookie
{:domain ""
:httponly false
:name "cookie2"
:path "/"
:secure false
:value "test2"})))))
(let [cookie (e/get-cookie *driver* :cookie2)
cookie (dissoc cookie :sameSite)]
(is (= cookie {:domain "localhost"
:httpOnly false
:name "cookie2"
:path "/"
:secure false
:value "test2"}))))
(testing "deleting a cookie"
(e/when-not-phantom
*driver*
Expand Down

0 comments on commit ceda6b3

Please sign in to comment.