-
Notifications
You must be signed in to change notification settings - Fork 3
Browser Configuration
WatirCraft automatically starts a browser for your tests. In your tests, you access the current browser as browser.
browser.title.should == 'Delivery Status'
There are a number of configuration options that you can set to control browser initialization.
- browser: ie or firefox (and others, as support for them arrives)
- attach: true or false – Reuse an existing browser?
- visible: true or false – Hide the browser?
- bring_to_front: true or false – Make sure the browser is on top?
- leave_open: true or false – Close the browser after running the tests?
Only the last option currently works with Firefox. If you set the others and run with Firefox, they will simply be ignored.
Like all configuration options, these can be defined in config\config.yml or as environment variables, or as command line arguments to rake tasks.
What if these options aren’t enough? What if your application has a complex initialization/login process?
You can customize the initialization by writing your own initialize_browser method for your site.
class Depot < ::Taza::Site
# Sets @browser to be a browser initialized for testing your site.
def initialize_browser
super # configure the browser based on the configuration settings
end
end
As written here (and as generated when you create a new project), this method will initialize a browser according to all the configuration settings described above. There are two approaches you can take to customizing this. The first is to extend the method, but adding additional code after super. The second is to override the standard initialization code.
You can access any of the configuration information via the config hash. E.g. the browser setting:
config[:browser]
An example of a customized initialization for a application with a complex login process.