Configuring Vapir

vapir edited this page Sep 27, 2011 · 2 revisions

Configuring Vapir

Vapir has a configuration framework which allows a variety of ways to specify options, and a high level of granularity.

Configurable module; Configuration object

Objects that are configurable in Vapir are extended by the Configurable module, which defines the method #config. That method returns a Configuration object particular to the object in question. See the rdoc for Configuration for more details on how to interact with this object, or a couple examples below.

  # updating
  some_configurable.config.highlight_color = 'green'
  some_configurable.config['highlight_color'] = 'green'
  some_configurable.config.update('highlight_color', 'green')
  # reading
  some_configurable.config.highlight_color
  some_configurable.config['highlight_color']
  some_configurable.config.read('highlight_color')

Where some_configurable may be anything extended by the Configurable module – examples including the Vapir module, a browser-specific class (Vapir::IE or Vapir::Firefox), a browser instance, or an Element instance.

Sources

Built-in defaults

Vapir has built-in defaults for most of its settings which aim for a sensible value that only needs to be overridden in unusual circumstances. The values of these are documented below.

YAML files

Vapir looks for YAML files containing configuration in a number of places:

  • ~/.vapir_config.yaml – dot-file in the home directory
  • ./vapir_config.yaml – regular file in the pwd
  • A location specified in the environment variable VAPIR_CONFIG_YAML

The YAML file should be a simple YAML hash of config keys and config values. For example:

highlight_color: green
default_browser: firefox

Environment Variables

Vapir checks for environment variables starting with the prefix “vapir_” for any recognized configuration keys.

VAPIR_HIGHLIGHT_COLOR=green irb -r vapir
>> Vapir.config.highlight_color
=> "green"

Although environment variables are case sensitive, Vapir’s configuration keys are not. Vapir will pick up any environment variables regardless of case. VAPIR_HIGHLIGHT_COLOR, vapir_highlight_color, and Vapir_Highlight_CoLoR all work fine.

Ruby

Configuration can be set, overriding any of the previous, on configuration objects in ruby.

Heirarchy

Configuration options are inherited hierarchically.

  • Built-in defaults
  • YAML configuration file – the first one found in the following order:
    • referred to by the VAPIR_CONFIG_YAML env variable
    • found in the present working directory at “./vapir_config.yaml”
    • found in your home directory at “~/.vapir_config.yaml”
  • Environment variables with ‘vapir_’ prefix
  • Vapir module (Vapir.config)
  • Browser-specific classes (Vapir::Firefox.config, Vapir::IE.config)
  • Browser instance
  • Element instance (parent is the element’s container, which may be the browser)

Configuration options

Key What is it Default Value Notes since version
attach_timeout time in seconds to wait for a browser or popup window to be located to attach to 30 1.8.0
default_browser the name of the library that Vapir::Browser will delegate to no default This has no default when you require 'vapir', but if you require 'vapir-firefox' or require 'vapir-ie' then the default will be set to whatever browser library you require first 1.8.0
highlight_color the color elements are highlighted with when they are being used yellow 1.8.0
wait whether to call the #wait method when performing actions true not yet fully implemented – only has effect when instantiating a browser object 1.8.0
type_keys whether or not to simulate every keypress when entering text into a field false When this is off, at least one keypress is still simulated, which is usually enough for javascript stuff that observes text fields 1.8.0
typing_interval the number of seconds to pause between typing each key when entering text into a field. this is called ‘typingspeed’ in watir, rather counterintuitively. this has no effect if type_keys is false. 0 1.8.0
firefox_profile the name of the firefox profile that should be used when launching a new instance of firefox no default vapir-firefox only 1.8.0
firefox_binary_path the location of the firefox binary which vapir will execute when launching a new instance of firefox no default by default vapir looks in a default place (or places) particular to the platform being run on, where firefox usually lives 1.8.0
firefox_extension The Firefox extension Vapir-Firefox will try to connect to. Either 'jssh' or 'mozrepl'. 'jssh' Vapir-Firefox only

Default will probably become mozrepl soon.

1.9.0
firefox_mozrepl_port The port on which Vapir-Firefox will attempt to connect to the Mozrepl extension 42421 Only for Vapir-Firefox when firefox_extension is mozrepl 1.9.0
firefox_mozrepl_host The host to which Vapir-Firefox will attempt to connect to the Mozrepl extension 'localhost'1 Only for Vapir-Firefox when firefox_extension is mozrepl 1.9.0
firefox_jssh_port The port on which Vapir-Firefox will attempt to connect to the JSSH extension 99971 Only for Vapir-Firefox when firefox_extension is jssh 1.9.0
firefox_jssh_host The host to which Vapir-Firefox will attempt to connect to the JSSH extension 'localhost'1 Only for Vapir-Firefox when firefox_extension is jssh 1.9.0
ie_launch_new_process whether creating a new IE browser instance should have that browser run in its own process false Vapir-IE only 1.8.0
browser_visible whether launched windows will be made visible true Vapir-IE only 1.8.0
close_timeout How long Vapir will wait for a browser window to close (seconds) 16 1.9.0
quit_timeout How long Vapir will wait for a browser process to quit (seconds) 8 1.9.0
wait_timeout How long Vapir will wait for a page to be ready (seconds) 120 1.9.0

1 These are a bit unusual, because Vapir doesn’t actually define a default value, but defers that to the semi-independent FirefoxSocket library. So if you do Vapir::Firefox.config.firefox_mozrepl_port, by default it is undefined. But if you set it, it’ll be respected. And if you don’t, FirefoxSocket applies the defaults stated here.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.