How can I change logfile path of phantomjs with se

2020-07-18 05:51发布

问题:

When using phantomjs with selenium, I would like to change the default --webdriver-logfile parameter, that selenium passes to phantomjs. How can I do it?

The corresponding line in selenium log:

11:06:06.960 INFO - arguments: [--webdriver=14380, --webdriver-logfile=<ROOT PATH DELETED HERE>/phantomjsdriver.log]

Firing up phantomjs in coffeescript:

webdriverio = require 'webdriverio'

module.exports.World = World = (next) ->
  @browser = webdriverio.remote({ desiredCapabilities: {
    browserName: 'phantomjs'
    "phantomjs.binary.path": "node_modules/phantomjs/bin/phantomjs"
  }})
  .init()

next()

回答1:

I was looking for few hours and could not find the answer, therefore I have hacked it in the phantomjs file that is called by selenium. This is not a proper solution but does the job.

args = args.map(function(str) {
 if(str.search('-webdriver-logfile') != -1 ) {
    console.log('Replacing default webdriver log with null in phantomjs');
    return str.replace(/--webdriver-logfile=.*$/i,"--webdriver-logfile=/dev/null")
 }
 return str;
 });