Class: Watir::Browser

Inherits:
Object
  • Object
show all
Defined in:
lib/watir-classic/browser.rb

Overview

Watir is a family of open-source drivers for automating web browsers. You can use it to write tests that are easy to read and maintain.

Watir drives browsers the same way people do. It clicks links, fills in forms, presses buttons. Watir also checks results, such as whether expected text appears on a page.

The Watir Classic is a driver for Internet Explorer (on Windows).

Project Homepage: watir.com

Examples:

usage


require 'watir-classic'
browser = Watir::Browser.new
browser.goto 'http://google.com'
browser.text_field(:name => 'q').set 'pickaxe'  
browser.button(:name => 'btnG').click
if browser.text.include? 'Programming Ruby'
  puts 'Text was found'
else
  puts 'Text was not found'
end

Class Method Summary collapse

Class Method Details

.attach(how, what) ⇒ Object

Attach to an existing IE Watir::Browser.

Examples:

Attach with full title:

Watir::Browser.attach(:title, "Full title of IE")

Attach with part of the title using Regexp:

Watir::Browser.attach(:title, /part of the title of IE/)

Attach with part of the url:

Watir::Browser.attach(:url, /google/)

Attach with window handle:

Watir::Browser.attach(:hwnd, 123456)

Parameters:

  • how (Symbol)

    type of the locator. Can be :title, :url or :hwnd.

  • what (Symbol)

    value of the locator. Can be String, Regexp or Fixnum depending of the type parameter.



77
78
79
80
# File 'lib/watir-classic/browser.rb', line 77

def attach(how, what)
  set_sub_options
  klass.attach(how, what)
end

.klassObject



94
95
96
97
# File 'lib/watir-classic/browser.rb', line 94

def klass
  key = Watir.options[:browser]
  eval @@browser_classes[key] # this triggers the autoload
end

.new(ignored = nil) ⇒ Object

Create a new instance of the Watir::Browser object

Parameters:

  • ignored (Object) (defaults to: nil)

    Argument is only needed to make watir-classic more compatible with watir-webdriver and is really ignored.



47
48
49
50
# File 'lib/watir-classic/browser.rb', line 47

def new(ignored=nil)
  set_sub_options
  klass.new
end

.optionsHash

Returns options of the Watir::Browser.

Returns:



89
90
91
92
# File 'lib/watir-classic/browser.rb', line 89

def options
  return {} unless klass.respond_to?(:options)
  klass.options
end

.set_options(options) ⇒ Object

Set options for the Watir::Browser.



83
84
85
86
# File 'lib/watir-classic/browser.rb', line 83

def set_options(options)
  return unless klass.respond_to?(:set_options)
  klass.set_options options
end

.start(url) ⇒ Object

Create a new Watir::Browser instance as with new and start the browser on the specified url.

Parameters:

  • url (String)

    Url to start the browser at.



55
56
57
58
# File 'lib/watir-classic/browser.rb', line 55

def start(url)
  set_sub_options
  klass.start url
end