How to pass browser parameter to Watir
I am using Ruby and I am using the latest Warri. I am planning on using a non-browser browser like PhantomJS. How can the paramater be passed to the Phantom JS browser when it's done.
My goal is so that Phantom JS doesn't need to load images.
As described in the PhantomJS command line page , it is possible to control the loading of images:
- load-images = [true | false] loads all inline images (this is true by default). Also accepted: [yes | not].
During Watir :: Browser initialization, these parameters can be specified as an array in :args
. For example:
args = %w{--load-images=false}
browser = Watir::Browser.new(:phantomjs, :args => args)
Working example:
require 'watir-webdriver'
# Capture screenshot with --load-images=true
browser = Watir::Browser.new(:phantomjs)
browser.goto 'https://www.google.com'
browser.screenshot.save('phantomjs_with_images.png')
# Capture screenshot with --load-images=false
args = %w{--load-images=false}
browser = Watir::Browser.new(:phantomjs, :args => args)
browser.goto 'https://www.google.com'
browser.screenshot.save('phantomjs_without_images.png')
Which gives a screenshot with uploaded images:
And a screenshot without uploaded images:
Note that the Google page image is not loading in the second screenshot (as expected since loading images are set to false).