3

In my Selenium test cases, I have added an special assert to ensure the code under test didn't generate errors in the browser console. To implement such a thing, I'm capturing the browser logs and seeing if there are any log entries for which the log level > info.

I'm able to get the browser logs using Chrome or Firefox when running selenium testing, when test is configured as follows (example below for PhantomJS):

LoggingPreferences logs = new LoggingPreferences();
logs.enable(LogType.BROWSER, Level.ALL);
DesiredCapabilities caps = DesiredCapabilities.phantomjs();
caps.setCapability(CapabilityType.LOGGING_PREFS, logs);
driver = new PhantomJSDriver(caps);

However when using PhantomJS, i don't get any logs, i.e. the following expression returns 0:

driver.manage().logs().get(LogType.BROWSER).getAll().size()

Configuration:

  • selenium: 2.45.0
  • phantomjs: 1.9.8
  • OS: mac-10.10 (Yosemite)-32bit
  • phantomjs driver: 1.2.1 (using "com.codeborne" % "phantomjsdriver" % "1.2.1")
  • ghostdriver 1.1.0

When querying available log types, via:

driver.manage().logs().getAvailableLogTypes()

I get: [har, browser, client], 'har' and 'client' do have get logentries.

Here is below the output when executing the test. You will notice there are indeed a few page.onError (what i m trying to catch, via the logs) which should be part of the captured browser logs.

Can you see what's wrong in the driver setup?

Looking at the unit test: https://github.com/detro/ghostdriver/blob/master/test/java/src/test/java/ghostdriver/LogTest.java, it should be working, so it must be something wrong in my setup (code or libraries), but i was not able to spot it.

Thanks!

Apr 29, 2015 1:24:35 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init> INFO: executable: /tmp/phantomjs-1.9.8-macosx/bin/phantomjs Apr 29, 2015 1:24:35 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init> INFO: port: 8208 Apr 29, 2015 1:24:35 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init> INFO: arguments: [--webdriver=8208, --webdriver-logfile=/tmp/phantomjsdriver.log] Apr 29, 2015 1:24:35 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init> INFO: environment: {} PhantomJS is launching GhostDriver... [INFO - 2015-04-29T11:24:36.729Z] GhostDriver - Main - running on port 8208 [INFO - 2015-04-29T11:24:37.222Z] Session [51a8f330-ee62-11e4-b50f-c5e60b20f37e] - page.settings - {"XSSAuditingEnabled":false,"javascriptCanCloseWindows":true,"javascriptCanOpenWindows":true,"javascriptEnabled":true,"loadImages":true,"localToRemoteUrlAccessEnabled":false,"userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.9.8 Safari/534.34","webSecurityEnabled":true} [INFO - 2015-04-29T11:24:37.222Z] Session [51a8f330-ee62-11e4-b50f-c5e60b20f37e] - page.customHeaders: - {} [INFO - 2015-04-29T11:24:37.222Z] Session [51a8f330-ee62-11e4-b50f-c5e60b20f37e] - Session.negotiatedCapabilities - {"browserName":"phantomjs","version":"1.9.8","driverName":"ghostdriver","driverVersion":"1.1.0","platform":"mac-10.10 (Yosemite)-32bit","javascriptEnabled":true,"takesScreenshot":true,"handlesAlerts":false,"databaseEnabled":false,"locationContextEnabled":false,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"cssSelectorsEnabled":true,"webStorageEnabled":false,"rotatable":false,"acceptSslCerts":false,"nativeEvents":true,"proxy":{"proxyType":"direct"}} [INFO - 2015-04-29T11:24:37.222Z] SessionManagerReqHand - _postNewSessionCommand - New Session Created: 51a8f330-ee62-11e4-b50f-c5e60b20f37e Running selenium with org.openqa.selenium.phantomjs.PhantomJSDriver [info] application - ElasticSearch at localhost:9300 [ERROR - 2015-04-29T11:24:39.523Z] Session [51a8f330-ee62-11e4-b50f-c5e60b20f37e] - page.onError - msg: Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting! Watchers fired in the last 5 iterations: [] http://errors.angularjs.org/1.3.15/$rootScope/infdig?p0=10&p1=%5B%5D [ERROR - 2015-04-29T11:24:39.523Z] Session [51a8f330-ee62-11e4-b50f-c5e60b20f37e] - page.onError - stack: (anonymous function) (http://localhost:3333/assets/bundles/js/vendor-6fac01f5.js:26446) (anonymous function) (http://localhost:3333/assets/bundles/js/vendor-6fac01f5.js:26668) bootstrapApply (http://localhost:3333/assets/bundles/js/vendor-6fac01f5.js:13555) invoke (http://localhost:3333/assets/bundles/js/vendor-6fac01f5.js:16300) (anonymous function) (http://localhost:3333/assets/bundles/js/vendor-6fac01f5.js:13556) bootstrap (http://localhost:3333/assets/bundles/js/vendor-6fac01f5.js:13570) angularInit (http://localhost:3333/assets/bundles/js/vendor-6fac01f5.js:13464) (anonymous function) (http://localhost:3333/assets/bundles/js/vendor-6fac01f5.js:38401) (anonymous function) (http://localhost:3333/assets/bundles/js/vendor-6fac01f5.js:3048) (anonymous function) (http://localhost:3333/assets/bundles/js/vendor-6fac01f5.js:3160) (anonymous function) (http://localhost:3333/assets/bundles/js/vendor-6fac01f5.js:433) (anonymous function) (http://localhost:3333/assets/bundles/js/vendor-6fac01f5.js:104) [ERROR - 2015-04-29T11:24:39.535Z] Session [51a8f330-ee62-11e4-b50f-c5e60b20f37e] - page.onError - msg: Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting! Watchers fired in the last 5 iterations: [] http://errors.angularjs.org/1.3.15/$rootScope/infdig?p0=10&p1=%5B%5D [ERROR - 2015-04-29T11:24:39.535Z] Session [51a8f330-ee62-11e4-b50f-c5e60b20f37e] - page.onError - stack: (anonymous function) (http://localhost:3333/assets/bundles/js/vendor-6fac01f5.js:26446) (anonymous function) (http://localhost:3333/assets/bundles/js/vendor-6fac01f5.js:26668) done (http://localhost:3333/assets/bundles/js/vendor-6fac01f5.js:21795) completeRequest (http://localhost:3333/assets/bundles/js/vendor-6fac01f5.js:21985) requestLoaded (http://localhost:3333/assets/bundles/js/vendor-6fac01f5.js:21930) [ERROR - 2015-04-29T11:24:39.551Z] Session [51a8f330-ee62-11e4-b50f-c5e60b20f37e] - page.onError - msg: Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting! Watchers fired in the last 5 iterations: [] http://errors.angularjs.org/1.3.15/$rootScope/infdig?p0=10&p1=%5B%5D [ERROR - 2015-04-29T11:24:39.551Z] Session [51a8f330-ee62-11e4-b50f-c5e60b20f37e] - page.onError - stack: (anonymous function) (http://localhost:3333/assets/bundles/js/vendor-6fac01f5.js:26446) (anonymous function) (http://localhost:3333/assets/bundles/js/vendor-6fac01f5.js:26668) done (http://localhost:3333/assets/bundles/js/vendor-6fac01f5.js:21795) completeRequest (http://localhost:3333/assets/bundles/js/vendor-6fac01f5.js:21985) requestLoaded (http://localhost:3333/assets/bundles/js/vendor-6fac01f5.js:21930)

Edit

Ran the same tests using phantomjs 2.0 (from https://github.com/eugene1g/phantomjs/releases as the official release crashes on OS X Yosemite). Same results (see log below).

Apr 30, 2015 12:39:14 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFO: executable: <...>/Documents/phantomjs-2.0/phantomjs
Apr 30, 2015 12:39:14 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFO: port: 42987
Apr 30, 2015 12:39:14 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFO: arguments: [--webdriver=42987, --webdriver-logfile=<...>/phantomjsdriver.log]
Apr 30, 2015 12:39:14 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFO: environment: {}
[INFO  - 2015-04-30T10:39:15.103Z] GhostDriver - Main - running on port 42987
[INFO  - 2015-04-30T10:39:15.468Z] Session [25c7d880-ef25-11e4-a0e9-4d6ab124ffa3] - page.settings - {"XSSAuditingEnabled":false,"javascriptCanCloseWindows":true,"javascriptCanOpenWindows":true,"javascriptEnabled":true,"loadImages":true,"localToRemoteUrlAccessEnabled":false,"userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.0.0 Safari/538.1","webSecurityEnabled":true}
[INFO  - 2015-04-30T10:39:15.468Z] Session [25c7d880-ef25-11e4-a0e9-4d6ab124ffa3] - page.customHeaders:  - {}
[INFO  - 2015-04-30T10:39:15.468Z] Session [25c7d880-ef25-11e4-a0e9-4d6ab124ffa3] - Session.negotiatedCapabilities - {"browserName":"phantomjs","version":"2.0.0","driverName":"ghostdriver","driverVersion":"1.2.0","platform":"mac-10.9 (Mavericks)-64bit","javascriptEnabled":true,"takesScreenshot":true,"handlesAlerts":false,"databaseEnabled":false,"locationContextEnabled":false,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"cssSelectorsEnabled":true,"webStorageEnabled":false,"rotatable":false,"acceptSslCerts":false,"nativeEvents":true,"proxy":{"proxyType":"direct"}}
[INFO  - 2015-04-30T10:39:15.468Z] SessionManagerReqHand - _postNewSessionCommand - New Session Created: 25c7d880-ef25-11e4-a0e9-4d6ab124ffa3
Running selenium with org.openqa.selenium.phantomjs.PhantomJSDriver
[info] application - ElasticSearch at localhost:9300
[ERROR - 2015-04-30T10:39:18.825Z] Session [25c7d880-ef25-11e4-a0e9-4d6ab124ffa3] - page.onError - msg: Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: []
http://errors.angularjs.org/1.3.15/$rootScope/infdig?p0=10&p1=%5B%5D
    at $digest (http://localhost:3333/assets/bundles/js/vendor-6fac01f5.js:26446:31)
    at $apply (http://localhost:3333/assets/bundles/js/vendor-6fac01f5.js:26668:31)
    at bootstrapApply (http://localhost:3333/assets/bundles/js/vendor-6fac01f5.js:13552:21)
    at invoke (http://localhost:3333/assets/bundles/js/vendor-6fac01f5.js:16300:22)
    at doBootstrap (http://localhost:3333/assets/bundles/js/vendor-6fac01f5.js:13550:20)
    at bootstrap (http://localhost:3333/assets/bundles/js/vendor-6fac01f5.js:13570:23)
    at angularInit (http://localhost:3333/assets/bundles/js/vendor-6fac01f5.js:13464:14)
    at http://localhost:3333/assets/bundles/js/vendor-6fac01f5.js:38401:16
    at fire (http://localhost:3333/assets/bundles/js/vendor-6fac01f5.js:3048:35)
    at fireWith (http://localhost:3333/assets/bundles/js/vendor-6fac01f5.js:3160:11)
    at ready (http://localhost:3333/assets/bundles/js/vendor-6fac01f5.js:433:24)
    at completed (http://localhost:3333/assets/bundles/js/vendor-6fac01f5.js:104:16)

  :262 in error
[ERROR - 2015-04-30T10:39:18.825Z] Session [25c7d880-ef25-11e4-a0e9-4d6ab124ffa3] - page.onError - stack:
  (anonymous function) (http://localhost:3333/assets/bundles/js/vendor-6fac01f5.js:23752)

  :262 in error
[ERROR - 2015-04-30T10:39:18.832Z] Session [25c7d880-ef25-11e4-a0e9-4d6ab124ffa3] - page.onError - msg: Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: []
http://errors.angularjs.org/1.3.15/$rootScope/infdig?p0=10&p1=%5B%5D
    at $digest (http://localhost:3333/assets/bundles/js/vendor-6fac01f5.js:26446:31)
    at $apply (http://localhost:3333/assets/bundles/js/vendor-6fac01f5.js:26668:31)
    at done (http://localhost:3333/assets/bundles/js/vendor-6fac01f5.js:21795:53)
    at completeRequest (http://localhost:3333/assets/bundles/js/vendor-6fac01f5.js:21985:15)
    at requestLoaded (http://localhost:3333/assets/bundles/js/vendor-6fac01f5.js:21926:24)

  :262 in error
[ERROR - 2015-04-30T10:39:18.832Z] Session [25c7d880-ef25-11e4-a0e9-4d6ab124ffa3] - page.onError - stack:
  (anonymous function) (http://localhost:3333/assets/bundles/js/vendor-6fac01f5.js:23752)

  :262 in error
[ERROR - 2015-04-30T10:39:18.839Z] Session [25c7d880-ef25-11e4-a0e9-4d6ab124ffa3] - page.onError - msg: Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: []
http://errors.angularjs.org/1.3.15/$rootScope/infdig?p0=10&p1=%5B%5D
    at $digest (http://localhost:3333/assets/bundles/js/vendor-6fac01f5.js:26446:31)
    at $apply (http://localhost:3333/assets/bundles/js/vendor-6fac01f5.js:26668:31)
    at done (http://localhost:3333/assets/bundles/js/vendor-6fac01f5.js:21795:53)
    at completeRequest (http://localhost:3333/assets/bundles/js/vendor-6fac01f5.js:21985:15)
    at requestLoaded (http://localhost:3333/assets/bundles/js/vendor-6fac01f5.js:21926:24)

  :262 in error
[ERROR - 2015-04-30T10:39:18.839Z] Session [25c7d880-ef25-11e4-a0e9-4d6ab124ffa3] - page.onError - stack:
  (anonymous function) (http://localhost:3333/assets/bundles/js/vendor-6fac01f5.js:23752)

  :262 in error
--------------- 0
[INFO  - 2015-04-30T10:39:19.105Z] ShutdownReqHand - _handle - About to shutdown
greg
  • 41
  • 2

0 Answers0