Class: OperaWatir::QuickWidget

Inherits:
Object
  • Object
show all
Includes:
Deprecated, DesktopContainer
Defined in:
lib/operawatir/quickwidgets/quick_widget.rb

Constant Summary collapse

ConditionTimeout =
10.0

Instance Method Summary collapse

Methods included from DesktopContainer

#quick_addressfield, #quick_button, #quick_checkbox, #quick_dialogtab, #quick_dropdown, #quick_dropdownitem, #quick_editfield, #quick_find, #quick_griditem, #quick_gridlayout, #quick_label, #quick_menu, #quick_menuitem, #quick_radiobutton, #quick_searchfield, #quick_tab, #quick_thumbnail, #quick_toolbar, #quick_treeitem, #quick_treeview, #quick_window

Instance Method Details

#click_with_condition(&condition) ⇒ Object

click_with_condition { block } → res

Clicks widget and waits until block evaluates to true or timeout is hit

Examples:

browser.quick_button(:name, "[buttonname]").click_with_condition {
      browser.quick_treeview(:name, "[name]").quick_treeitems.length == 4 }.should be_true

Returns:

  • value of block, or false if no block provided



384
385
386
# File 'lib/operawatir/quickwidgets/quick_widget.rb', line 384

def click_with_condition(&condition)
  click_with_condition_internal(:left, 1, &condition)
end

#double_click_with_condition(&condition) ⇒ Object

double_click_with_condition { block } → res

Doubleclicks widget and waits until block evaluates to true or timeout is hit

Returns:

  • value of block, or false if no block provided



344
345
346
# File 'lib/operawatir/quickwidgets/quick_widget.rb', line 344

def double_click_with_condition(&condition)
  click_with_condition_internal(:left, 2, &condition)
end

#enabled?Boolean

Checks if a widget is enabled or not

Returns:

  • (Boolean)

    true if enabled otherwise false

Raises:



77
78
79
# File 'lib/operawatir/quickwidgets/quick_widget.rb', line 77

def enabled?
  element.isEnabled
end

#exist?Boolean Also known as: exists?

Checks whether a widget exists or not

Returns:

  • (Boolean)

    true if the widget exists otherwise false



62
63
64
65
66
# File 'lib/operawatir/quickwidgets/quick_widget.rb', line 62

def exist?
  !!element
  rescue Exceptions::UnknownObjectException
    false
end

#focus_with_clickObject

Focus a widget with a click



321
322
323
324
325
# File 'lib/operawatir/quickwidgets/quick_widget.rb', line 321

def focus_with_click
  click
  # No event yet so just cheat and sleep
  sleep(0.1)
end

#focus_with_hoverObject

Focus a widget by moving the mouse over it



330
331
332
333
334
# File 'lib/operawatir/quickwidgets/quick_widget.rb', line 330

def focus_with_hover
  element.hover
  #No event yet so just cheat and sleep
  sleep(0.1)
end

#has_ui_string?Boolean

Checks that the text in the widget matches the text as loaded from the current language file in Opera using the string_id (Strips &‘s from the string before comparing)

Parameters:

  • string_id (String)

    String ID to use to load the string from the current language file (e.g. “D_NEW_PREFERENCES_GENERAL”)

Returns:

  • (Boolean)

    true if the text matches, otherwise false

Raises:



168
169
170
171
172
173
174
175
176
177
# File 'lib/operawatir/quickwidgets/quick_widget.rb', line 168

def verify_text(string_id)
  text = driver.getString(string_id, true) #true => stripAmpersands from string
  if text.include? "%"
    text.gsub!(/%[csduoxefg0-9]/, ".*")
    res = /#{text}/ =~ element.getText()
    res == nil ? false: true
  else
    element.verifyText(string_id)
  end
end

#heightObject

Returns height of widget.

Returns:

  • height of widget



263
264
265
# File 'lib/operawatir/quickwidgets/quick_widget.rb', line 263

def height
  element.getRect().height
end

#middle_click_with_condition(&condition) ⇒ Object

middle_click_with_condition { block } → res

Middleclicks widget and waits until block evaluates to true or timeout is hit

Returns:

  • value of block, or false if no block provided



368
369
370
# File 'lib/operawatir/quickwidgets/quick_widget.rb', line 368

def middle_click_with_condition(&condition)
  click_with_condition_internal(:middle, 1, &condition)
end

#nameString

Gets the name of the widget (as it appears in dialog.ini or code)

Returns:

  • (String)

    name of the widget

Raises:



128
129
130
# File 'lib/operawatir/quickwidgets/quick_widget.rb', line 128

def name
  element.getName
end

#open_menu_with_rightclick(menu_name) ⇒ String

Rightclicks the widget, and waits for the menu with name menu_name to be shown

Parameters:

  • menu (String)

    name (from standard_menu.ini)

Returns:

  • (String)

    name of menu opened if it matches parameter menu_name otherwise empty string

Raises:



51
52
53
54
55
# File 'lib/operawatir/quickwidgets/quick_widget.rb', line 51

def open_menu_with_rightclick(menu_name)
  wait_start
  click(:right)
  wait_for_menu_shown(menu_name)
end

#open_window_with_hover(win_name = "") ⇒ Object

Hovers widget and waits for window to be shown



33
34
35
36
37
# File 'lib/operawatir/quickwidgets/quick_widget.rb', line 33

def open_window_with_hover(win_name = "")
  wait_start
  element.hover
  wait_for_window_shown(win_name)
end

#parent_nameObject

Gets parent widget name



314
315
316
# File 'lib/operawatir/quickwidgets/quick_widget.rb', line 314

def parent_name
  element.getParentName()
end

#positionObject

Returns position for elements that have a position, else false.

Returns:

  • position for elements that have a position, else false



239
240
241
242
243
244
245
246
247
248
249
# File 'lib/operawatir/quickwidgets/quick_widget.rb', line 239

def position
  case type
    when :treeitem then [row, col]
    when :tabbutton, :button then col
    else false
  end
  #return [row, col] if type == :treeitem
  #return col if type == :tabbutton
  #return col if type == :button
  #false
end

#quick_tabsObject



416
417
418
# File 'lib/operawatir/quickwidgets/quick_widget.rb', line 416

def quick_tabs
  quick_tabbuttons
end

#quick_widgetsObject

Note:

you can also specify the widgets by type to retrieve only a specific type of widgets

Returns all widgets inside this widget.

Examples:

browser.quick_treeview(:name, "Mail View").quick_widgets
browser.quick_treeview(:name, "Mail View").quick_treeitems

Returns:

  • all widgets inside this widget



412
413
414
# File 'lib/operawatir/quickwidgets/quick_widget.rb', line 412

def quick_widgets
  widgets(window_id).select { | w | w.parent_name == name }
end

#right_click_with_condition(&condition) ⇒ Object

right_click_with_condition { block } → res

Rightclicks widget and waits until block evaluates to true or timeout is hit

Returns:

  • value of block, or false if no block provided



356
357
358
# File 'lib/operawatir/quickwidgets/quick_widget.rb', line 356

def right_click_with_condition(&condition)
  click_with_condition_internal(:right, 1, &condition)
end

#textString

Note:

This method should not be used to check the text in a widget if the text is in the Opera language file. Use verify_text instead

Gets the text of the widget

Returns:

  • (String)

    text of the widget

Raises:



104
105
106
# File 'lib/operawatir/quickwidgets/quick_widget.rb', line 104

def text
  element.getText
end

#to_sString

Gets a string representation of the widget

Returns:

  • (String)

    representation of the widget

Raises:



140
141
142
# File 'lib/operawatir/quickwidgets/quick_widget.rb', line 140

def to_s
  "#{type.to_s.capitalize} #{name}, text=#{text}, parentName=#{parent_name}, visible=#{visible?}, enabled=#{enabled?}, position=#{row},#{col}"
end

#typeSymbol

Gets the type of a widget

Returns:

  • (Symbol)

    type of the widget (e.g. :dropdown, :button)

Raises:



116
117
118
# File 'lib/operawatir/quickwidgets/quick_widget.rb', line 116

def type
  WIDGET_ENUM_MAP.invert[element.getType]
end

#valueObject



393
394
395
# File 'lib/operawatir/quickwidgets/quick_widget.rb', line 393

def value
  return element.getValue
end

#verify_includes_text(string_id) ⇒ Boolean Also known as: includes_text?

Checks that the text in the widget includes the text as loaded from the current language file in Opera using the string_id

Parameters:

  • string_id (String)

    String ID to use to load the string from the current language file (e.g. “D_NEW_PREFERENCES_GENERAL”)

Returns:

  • (Boolean)

    true if the text is included, otherwise false

Raises:



201
202
203
# File 'lib/operawatir/quickwidgets/quick_widget.rb', line 201

def verify_includes_text(string_id)
  element.verifyContainsText(string_id)
end

#verify_text(string_id, *params) ⇒ Boolean

Checks that the text in the widget matches the text as loaded from the current language file in Opera using the string_id (Strips &‘s from the string before comparing)

Parameters:

  • string_id (String)

    String ID to use to load the string from the current language file (e.g. “D_NEW_PREFERENCES_GENERAL”)

Returns:

  • (Boolean)

    true if the text matches, otherwise false

Raises:



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

def verify_text(string_id)
  text = driver.getString(string_id, true) #true => stripAmpersands from string
  if text.include? "%"
    text.gsub!(/%[csduoxefg0-9]/, ".*")
    res = /#{text}/ =~ element.getText()
    res == nil ? false: true
  else
    element.verifyText(string_id)
  end
end

#visible?Boolean

Checks if a widget is visible or not

Returns:

  • (Boolean)

    true if visible otherwise false

Raises:



89
90
91
# File 'lib/operawatir/quickwidgets/quick_widget.rb', line 89

def visible?
  element.isVisible
end

#widget_info_stringObject

Returns a string of all of the internal information about the widget. Used to discover the names of widgets and windows to use in the tests

Raises:



295
296
297
298
299
300
301
302
303
304
305
306
# File 'lib/operawatir/quickwidgets/quick_widget.rb', line 295

def widget_info_string
  "   Name: " + name +
  "\n   Text: " + text +
  "\n   Type: " + type.to_s +
  "\n Parent: " + element.getParentName() +
  "\nVisible: " + visible?.to_s +
  "\nEnabled: " + enabled?.to_s +
  "\n    Pos: x=" + element.getRect().x.to_s + ", y=" + element.getRect().y.to_s +
  "\n   Size: width=" + element.getRect().width.to_s + ", height=" + element.getRect().height.to_s +
  "\n    Ref: row=" + element.getRow().to_s + ", col=" + element.getColumn().to_s +
  "\nselected: " + element.isSelected().to_s + "\n"
end

#widthObject

Returns width of widget.

Returns:

  • width of widget



255
256
257
# File 'lib/operawatir/quickwidgets/quick_widget.rb', line 255

def width
  element.getRect().width
end