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.

+3


source to share


1 answer


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:

phantomjs_with_images.png

And a screenshot without uploaded images:

phantomjs_without_images.png '

Note that the Google page image is not loading in the second screenshot (as expected since loading images are set to false).

+8


source







All Articles