Search code examples
poltergeist

How can I use "includeJs" function of phantomjs with poltergeist?


Is there a bridge between native phantomjs functions and the one available with poltergeist ? I would like to use the phantomjs "includeJs"


Solution

  • Poltergeist doesn't provide any access to PhantomJS' includeJS, but its extensions feature is implemented via injectJS which provides similar functionality, allowing you to specify JS files that get loaded at page creation time, allowing you to polyfill missing features, etc. http://www.rubydoc.info/gems/capybara/Capybara/Node/Actions#attach_file-instance_method . You can specify the files at driver registration time.

    Capybara.register_driver :poltergeist do |app|
      Capybara::Poltergeist::Driver.new(app, extensions: ['file1.js', 'file2.js'])
    end