使用phantomjs驱动程序

时间:2015-04-29 11:38:33

标签: javascript selenium logging phantomjs ghostdriver

在我的Selenium测试用例中,我添加了一个特殊的断言,以确保测试中的代码不会在浏览器控制台中生成错误。 为了实现这样的功能,我正在捕获浏览器日志并查看是否有任何日志条目的日志级别>资讯

我可以在运行selenium测试时使用Chrome或Firefox获取浏览器日志,当测试配置如下(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);

然而,当使用PhantomJS时,我没有得到任何日志,即以下表达式返回0:

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

配置:

  • selenium:2.45.0
  • phantomjs:1.9.8
  • OS:mac-10.10(Yosemite)-32bit
  • phantomjs驱动程序:1.2.1(使用“com.codeborne”%“phantomjsdriver”%“1.2.1”)
  • ghostdriver 1.1.0

查询可用的日志类型时,请通过:

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

我得到:[har,浏览器,客户端],'har'和'客户'确实得到了logentries。

执行测试时输出的下方。您会注意到确实有一些page.onError(我试图通过日志捕获的内容)应该是捕获的浏览器日志的一部分。

你能看到驱动程序设置有什么问题吗?

查看单元测试:https://github.com/detro/ghostdriver/blob/master/test/java/src/test/java/ghostdriver/LogTest.java,它应该正常工作,所以在我的设置(代码或库)中一定有问题,但我无法发现它。

谢谢!

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)

修改

使用phantomjs 2.0进行相同的测试(来自https://github.com/eugene1g/phantomjs/releases,正式版本在OS X Yosemite上崩溃)。 相同的结果(见下面的日志)。

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

0 个答案:

没有答案