rspecphantomjscapybarapoltergeist

Poltergeist: phantomjs_logger option ignored


In this setup:

require 'capybara/poltergeist'
Capybara.register_driver :poltergeist do |app|
  Capybara::Poltergeist::Driver.new(app, {
    phantomjs_options: ['--ignore-ssl-errors=yes', '--ssl-protocol=any', '--load-images=no'], debug: false, timeout: 500, screen_size: [1600, 1200], js_errors: false,.
    logger: File.open( Rails.root.join("./log/test.poltergeist.log").to_s, "a" ),
    phantomjs_logger: File.open( Rails.root.join("./log/test.phantomjs_console.log").to_s, "a" )
  })
end

Phantomjs ignores the phantomjs_logger option and dumps everything the application outputs to the console to STDOUT, so I get shown a load of garbage when running my specs.

I have tried with no luck setting phantomjs_logger to Logger.new(...), to File.open("/dev/null",...), to nil, false and pretty much everything you can think of, it just doesn't do anything.

Ideally I'd want errors to fail the test and other .info .log whatever messages just piped to the log file. But I can live with having it all sent to the log file as well.

Later edit: seems this is happening with chrome headless as well. It just dumps console.log into stdout :(

What am I doing wrong?


Solution

  • After a few hours wasted on this I managed to get it to work by opening the log into $stdout. Not sure why it couldn't work as per docs but oh well.

    $stdout = File.open( Rails.root.join("./log/test.phantomjs_console.log").to_s )
    
    require 'capybara/poltergeist'
    Capybara.register_driver :poltergeist do |app|
      Capybara::Poltergeist::Driver.new(app, {
        phantomjs: "/usr/local/bin/phantomjs", # '>> ./log/test.phantomjs_console.log 2>&1'
        phantomjs_options: [ '--ignore-ssl-errors=yes', '--ssl-protocol=any', '--load-images=no', '--debug=false' ], debug: false, timeout: 500, window_size: [1600, 1200], js_errors: false,.
        logger: File.open( Rails.root.join("./log/test.poltergeist.log").to_s, "a" ),
        phantomjs_logger: $stdout
      })
    end
    

    Later edit: managed to set up chrome in the meanwhile. Poltergeist is outdated. If you run into this q/a and you're trying to get poltergeist to work, stop and switch to chrome.