etaoin

borkdude 2017-10-23T12:01:23.000067Z

Is there a way I can get the js/console output?

igrishaev 2017-10-23T12:19:52.000182Z

good point, there are some APIs in webdriver

igrishaev 2017-10-23T12:20:27.000144Z

but I’ve not implemented or tested them yet

borkdude 2017-10-23T13:07:16.000553Z

Where do I find this API? Maybe I can use etaoin.client myself

borkdude 2017-10-23T13:09:34.000173Z

I googled for it, but all I find are pages about selenium

borkdude 2017-10-23T13:13:51.000176Z

oh wait, webdriver is something by Selenium

borkdude 2017-10-23T13:14:25.000034Z

or not, it’s w3c now? https://w3c.github.io/webdriver/webdriver-spec.html

borkdude 2017-10-23T13:53:54.000472Z

hmm, still doesn’t work exactly like I expect it… after the first call it returns an empty array, always

borkdude 2017-10-23T14:00:26.000169Z

ok, I guess it only retrieves the newer errors everytime, that’s ok

borkdude 2017-10-23T14:07:17.000165Z

(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}]}

borkdude 2017-10-23T14:08:03.000370Z

not sure if adding the capabilities was needed, it works without it too

igrishaev 2017-10-23T14:32:02.000391Z

oh, great! Let me wrap it into an issue

igrishaev 2017-10-23T14:32:31.000766Z

https://github.com/igrishaev/etaoin/issues/36

borkdude 2017-10-23T15:04:46.000741Z

Is there a a way to use the API without run-driver? when I connect to Docker it’s already running

borkdude 2017-10-23T15:05:14.000062Z

I still would like to use the rest of the API as is, like the with-chrome macro etc

igrishaev 2017-10-23T15:05:45.000248Z

you should use a combination of create-driver and connect-driver

igrishaev 2017-10-23T15:06:26.000234Z

(or driver-create/connect, I don’t remember).

borkdude 2017-10-23T15:06:49.000323Z

I figured that out, so no macros then

borkdude 2017-10-23T15:07:00.000494Z

I need to disconnect, but not stop the driver, also

igrishaev 2017-10-23T15:07:10.000004Z

yes, right

borkdude 2017-10-23T18:10:16.000419Z

What is a good way to count the amount of elements that may be returned by a query

borkdude 2017-10-23T18:11:34.000200Z

ah, query-all

borkdude 2017-10-23T18:15:58.000076Z

Wonderful:

(eta/wait-predicate
   #(pos?
     (count (eta/query-all chrome [{:class “signals-table”}
                                   {:tag “tbody”}
                                   {:tag “tr”}]))))

metametadata 2017-10-23T22:43:09.000004Z

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)))