Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix chrome profile #289

Merged
merged 3 commits into from
Aug 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
11 changes: 8 additions & 3 deletions src/etaoin/driver.clj
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,14 @@
;; Chrome adds the trailing `/Default` part to the profile path.
;; To prevent duplication, let's clear the given path manually.
[driver profile]
(let [default #"(\\|/)Default$"
p (string/replace profile default "")]
(set-options-args driver [(format "--user-data-dir=%s" p)])))
(let [profile (java.io.File. profile)
profile (if (= "Default" (.getName profile))
(.getParent profile)
profile)
user-data-dir (str (.getParent profile))
profile-dir (str (.getName profile))]
(set-options-args driver [(format "--user-data-dir=%s" user-data-dir)
(format "--profile-directory=%s" profile-dir)])))

(defmethod set-profile
:firefox
Expand Down
10 changes: 9 additions & 1 deletion test/etaoin/api_test2.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
(ns etaoin.api-test2
(:require [etaoin.api :refer :all]
[etaoin.proc]
[clojure.test :refer :all]))
[clojure.test :refer :all]
[clojure.java.io :as io]))

(deftest test-firefox-driver-args
(with-redefs
Expand Down Expand Up @@ -29,6 +30,13 @@
(is (= ["geckodriver" "--port" 1234 "--marionette-port" 2821]
(:args @driver)))))))

(deftest test-chrome-profile
(let [profile-path (str (io/resource "chrome-profile"))]
(with-chrome {:profile profile-path} driver
(go driver "chrome://version")
(is profile-path
(get-element-text driver :profile_path)))))

(deftest test-fail-run-driver
(is (thrown-with-msg?
clojure.lang.ExceptionInfo
Expand Down