2

当我们使用 webdriverjs 运行 phantomjs(ghost 驱动程序)但徒劳无功时,我一直试图弄清楚如何禁用烦人的控制台日志。

[INFO  - 2016-10-09T14:57:15.039Z] GhostDriver - Main - running on port 62381
[INFO  - 2016-10-09T14:57:15.084Z] Session [aa75cc80-8e30-11e6-8da5-a561819d4151] - 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.1.1 Safari/538.1","webSecurityEnabled":true}
[INFO  - 2016-10-09T14:57:15.084Z] Session [aa75cc80-8e30-11e6-8da5-a561819d4151] - page.customHeaders:  - {}
[INFO  - 2016-10-09T14:57:15.084Z] Session [aa75cc80-8e30-11e6-8da5-a561819d4151] - Session.negotiatedCapabilities - {"browserName":"phantomjs","version":"2.1.1","driverName":"ghostdriver","driverVersion":"1.2.0","platform":"mac-10.10 (Yosemite)-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  - 2016-10-09T14:57:15.084Z] SessionManagerReqHand - _postNewSessionCommand - New Session Created: aa75cc80-8e30-11e6-8da5-a561819d4151

以下是我的配置:

var webdriver = require('selenium-webdriver');
var phantomjs_exe = require('phantomjs-prebuilt').path;
var customPhantom = webdriver.Capabilities.phantomjs();
customPhantom.set("phantomjs.binary.path", phantomjs_exe);

//build custom phantomJS driver
var driver = new webdriver.Builder().
             withCapabilities(customPhantom).
             build();

从我身边做的事情-

  • 经历了各种 SO 线程,但它们都有 java api bindings 中的解决方案/方法。我正在寻找 nodejs 解决方案。以下是建议的事情:

  • Logger.getLogger(PhantomJSDriverService.class.getName()).setLevel(Level.OFF)

  • 沉默ghostdriver.log

    import os
    driver = webdriver.PhantomJS(service_log_path=os.path.devnull);
    
  • 使用所需的功能:

    DesiredCapabilities dcap = new DesiredCapabilities();
    String[] phantomArgs = new  String[] {"--webdriver-loglevel=NONE"};
    dcap.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, phantomArgs);
    PhantomJSDriver phantomDriver = new PhantomJSDriver(dcap);
    

如何在nodejs webdriver api 绑定中执行它们?任何人都可以指导正确的方向吗?我发现很少有无用的 api 文档示例!

4

0 回答 0