Class: OperaWatir::Browser

Inherits:
Object show all
Includes:
Deprecated
Defined in:
lib/operawatir/browser.rb

Direct Known Subclasses

DesktopBrowser

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeObject

Constructs a new OperaDriver::Browser object.

Examples:

browser = OperaWatir::Browser.new


22
23
24
25
26
27
28
29
30
31
# File 'lib/operawatir/browser.rb', line 22

def initialize
  OperaWatir.compatibility! unless OperaWatir.api >= 3

  self.driver        = OperaDriver.new(self.class.desired_capabilities)
  self.active_window = OperaWatir::Window.new(self)
  self.preferences   = OperaWatir::Preferences.new(self)
  self.keys          = OperaWatir::Keys.new(self)
  self.spatnav       = OperaWatir::Spatnav.new(self)
  self.utils         = OperaWatir::Utils.new(self)
end

Instance Attribute Details

#active_windowObject Also known as: window

Returns the value of attribute active_window.



5
6
7
# File 'lib/operawatir/browser.rb', line 5

def active_window
  @active_window
end

#driverObject

Returns the value of attribute driver.



5
6
7
# File 'lib/operawatir/browser.rb', line 5

def driver
  @driver
end

#keysObject

Returns the value of attribute keys.



5
6
7
# File 'lib/operawatir/browser.rb', line 5

def keys
  @keys
end

#preferencesObject

Returns the value of attribute preferences.



5
6
7
# File 'lib/operawatir/browser.rb', line 5

def preferences
  @preferences
end

#spatnavObject

Returns the value of attribute spatnav.



5
6
7
# File 'lib/operawatir/browser.rb', line 5

def spatnav
  @spatnav
end

#utilsObject

Returns the value of attribute utils.



5
6
7
# File 'lib/operawatir/browser.rb', line 5

def utils
  @utils
end

Class Method Details

.settingsObject



12
13
14
# File 'lib/operawatir/browser.rb', line 12

def self.settings
  @settings || self.settings = {}
end

.settings=(settings = {}) ⇒ Object



7
8
9
10
# File 'lib/operawatir/browser.rb', line 7

def self.settings=(settings={})
  @desired_capabilities = nil  # Bust cache
  @settings = settings
end

Instance Method Details

#actionsObject

actions



196
197
198
# File 'lib/operawatir/browser.rb', line 196

def actions
  OperaWatir::Actions.new(browser)
end

#copyObject

Copies the currently selected content to the clipboard. Equivalent to pressing C-c in a desktop browser.



129
130
131
132
133
134
135
136
137
138
139
# File 'lib/operawatir/browser.rb', line 129

def copy

  # FIXME: #copy, #cut and #paste really shouldn't use platform-
  # dependent keypresses like this.  But until DSK-327491 is fixed,
  # this will have to do.
  if OperaWatir::Platform.os == :macosx
    keys.send [:command, 'c']
  else
    keys.send [:control, 'c']
  end
end

#cutObject

Cuts the currently selected content to the clipboard. Equivalent to pressing C-x in a desktop browser.



143
144
145
146
147
148
149
150
151
# File 'lib/operawatir/browser.rb', line 143

def cut

  # FIXME
  if OperaWatir::Platform.os == :macosx
    keys.send [:command, 'x']
  else
    keys.send [:control, 'x']
  end
end

#desktop?Boolean

Is attached browser instance of type internal build or public desktop?

Returns:

  • (Boolean)

    True if browser attached is of type desktop, false otherwise.



92
93
94
# File 'lib/operawatir/browser.rb', line 92

def desktop?
  false  # FIXME
end

#key(key) ⇒ Object

Keyboard



170
171
172
# File 'lib/operawatir/browser.rb', line 170

def key(key)
  driver.key(key)
end

#key_down(key) ⇒ Object



176
177
178
# File 'lib/operawatir/browser.rb', line 176

def key_down(key)
  driver.keyDown(key)
end

#key_up(key) ⇒ Object



182
183
184
# File 'lib/operawatir/browser.rb', line 182

def key_up(key)
  driver.keyUp(key)
end

#nameString

Get the name of the browser currently being run.

Returns:

  • (String)

    Name of browser currently used.



38
39
40
# File 'lib/operawatir/browser.rb', line 38

def name
  'Opera'
end

#opera_action(name, *args) ⇒ String

Sends an Opera action to the browser.

Parameters:

  • Name (String)

    of the action.

Returns:

  • (String)

    Optional return from the performed action.



100
101
102
# File 'lib/operawatir/browser.rb', line 100

def opera_action(name, *args)
  driver.operaAction(name, args.to_java(:string))
end

#opera_action_listString

Full list of available Opera actions in the Opera build you’re using. Note that this list varies from configuration to configuration, and from build to build. The Opera actions available to devices-type builds will vary greatly from those available to desktop-types.

Returns:

  • (String)

    List of available Opera actions.



113
114
115
# File 'lib/operawatir/browser.rb', line 113

def opera_action_list
  driver.getOperaActionList.to_a
end

#pasteObject

Pastes content from the clipboard into the currently focused element. Equivalent to pressing C-v in a desktop browser. To paste content into textarea or input fields, remember to click it first.



157
158
159
160
161
162
163
164
165
# File 'lib/operawatir/browser.rb', line 157

def paste

  # FIXME
  if OperaWatir::Platform.os == :macosx
    keys.send [:command, 'v']
  else
    keys.send [:control, 'v']
  end
end

#pathString

Get the full path to the attached browser binary.

Returns:

  • (String)

    Path to the attached browser’s binary.



76
77
78
# File 'lib/operawatir/browser.rb', line 76

def path
  driver.getPath
end

#platformString

Get the target device’s platform. This is not equivalent of the platform the OperaWatir server might be running on.

Returns:

  • (String)

    Operating system flavour of the device we’re testing on.



69
70
71
# File 'lib/operawatir/browser.rb', line 69

def platform
  window.execute_script('navigator.platform')
end

#quitObject

Instruct the browser instance to quit and shut down.



51
52
53
# File 'lib/operawatir/browser.rb', line 51

def quit
  driver.quit
end

#select_allObject

Selects all content in the currently focused element. Equivalent to pressing C-a in a desktop browser. To select content in a <textarea> or an <input> field, remember to click it first.



122
123
124
125
# File 'lib/operawatir/browser.rb', line 122

def select_all
  # FIXME
  driver.operaAction('Select all')
end

#type(text) ⇒ Object



188
189
190
# File 'lib/operawatir/browser.rb', line 188

def type(text)
  driver.type(text)
end

#ua_stringString

Fetches the user agent (UA) string the browser currently uses.

Returns:

  • (String)

    User agent string.



83
84
85
# File 'lib/operawatir/browser.rb', line 83

def ua_string
  window.execute_script('navigator.userAgent')
end

#url=(url) ⇒ Object

Navigate to a new URL and return a Window object.

Parameters:

  • url (String)

    The URL you wish to go to.

Returns:

  • (Object)

    A Window object.



46
47
48
# File 'lib/operawatir/browser.rb', line 46

def url=(url)
  active_window.url = url
end

#versionString

Get the version number of the driver. This _is not_ the same as the version number for OperaWatir, which can be retrieved using OperaWatir.version instead.

Returns:

  • (String)

    Driver version.



60
61
62
# File 'lib/operawatir/browser.rb', line 60

def version
  driver.getVersion
end