Is there a way I can get the js/console output?
good point, there are some APIs in webdriver
but I’ve not implemented or tested them yet
Where do I find this API? Maybe I can use etaoin.client myself
I googled for it, but all I find are pages about selenium
oh wait, webdriver is something by Selenium
or not, it’s w3c now? https://w3c.github.io/webdriver/webdriver-spec.html
hmm, still doesn’t work exactly like I expect it… after the first call it returns an empty array, always
ok, I guess it only retrieves the newer errors everytime, that’s ok
(def chrome (eta/chrome {:capabilities {:loggingPrefs {:browser “ALL”}}}))
(eta/go chrome “<https://codex.wordpress.org/Using_Your_Browser_to_Diagnose_JavaScript_Errors“>)
(client/call chrome :post [:session (:session @chrome) “log”]
{:type “browser”}) #_{:sessionId “5290da6788ac528d2f7d21550bf96111”, :status 0, :value [{:level “SEVERE”, :message “<https://codex.wordpress.org/skins/common/wikibits.js> 242:3 Uncaught ReferenceError: mediaWiki is not defined”, :source “javascript”, :timestamp 1508767605273}]}
not sure if adding the capabilities was needed, it works without it too
oh, great! Let me wrap it into an issue
Is there a a way to use the API without run-driver
? when I connect to Docker it’s already running
I still would like to use the rest of the API as is, like the with-chrome
macro etc
you should use a combination of create-driver and connect-driver
(or driver-create/connect, I don’t remember).
I figured that out, so no macros then
I need to disconnect, but not stop the driver, also
yes, right
What is a good way to count the amount of elements that may be returned by a query
ah, query-all
Wonderful:
(eta/wait-predicate
#(pos?
(count (eta/query-all chrome [{:class “signals-table”}
{:tag “tbody”}
{:tag “tr”}]))))
This is what I use to get logs (no additional capabilities needed):
(defn -get-browser-log
"Retrieves browser log using unofficial WebDriver endpoint. Depends on :loggingPrefs WebDriver capability.
Example return value:
[{:level \"WARNING\"
:message \"<http://localhost:5000/js/compiled/frontend/out/app/core.js> 17:8 \"App debug mode is ON.\"\"
:source \"console-api\"
:timestamp 1494439209317} ,,,]
Empirical knowledge about browser differences:
Chrome:
Returns all recorded logs.
Clears log cache (so that the immediate subsequent invocation will return nothing).
Entries about errors will have SEVERE level.
PhantomJS:
Return all recorded logs since the last URL change.
Does not clear recorded logs on subsequent invocations.
Entries about errors will have WARNING level, as coded here:
<https://github.com/detro/ghostdriver/blob/be7ffd9d47c1e76c7bfa1d47cdcde9164fd40db8/src/session.js#L494>"
[driver]
(e/with-resp driver :post
[:session (:session @driver) :log] {:type "browser"}
response
(:value response)))
I also have this to filter away all network-related errors:
; Chrome:
; 1) It doesn't always provide the full error message.
; 2) It treats all failed network requests as errors, even if they are handled by application (e.g. failed AJAX requests).
;
; PhantomJS:
; 1) Some JS errors can pass undetected because it stores log entries only since the last URL change.
; 2) It doesn't detect ex-info exceptions.
(defn -logged-errors
"Parses the provided log and returns all non-network errors."
[driver log]
(assert (#{:chrome :phantom} (:type @driver)) (str "getting logs hasn't been checked for browser " (:type @driver)))
(let [error-level (case (:type @driver)
:chrome "SEVERE"
:phantom "WARNING")
all-errors (filter #(= (:level %) error-level) log)]
(filter #(not= (:source %) "network") all-errors)))