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

get js logs #36

Closed
igrishaev opened this issue Aug 1, 2017 · 8 comments
Closed

get js logs #36

igrishaev opened this issue Aug 1, 2017 · 8 comments

Comments

@igrishaev
Copy link
Collaborator

https://stackoverflow.com/questions/20907180/getting-console-log-output-from-chrome-with-selenium-python-api-bindings

@igrishaev
Copy link
Collaborator Author

@igrishaev
Copy link
Collaborator Author

@igrishaev
Copy link
Collaborator Author

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

@igrishaev
Copy link
Collaborator Author

more

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

@igrishaev
Copy link
Collaborator Author

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

@metametadata
Copy link

The default logging level seems to be WARNING in Chrome and PhantomJS. One can bump it via loggingPrefs:

(e/connect-driver d {:desired-capabilities {:loggingPrefs {:browser "INFO"}}})

@igrishaev
Copy link
Collaborator Author

@metametadata thank you, added in 0.2.1

@metametadata
Copy link

@igrishaev awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants