Class: Watir::Select

Inherits:
Object
  • Object
show all
Defined in:
lib/test-factory/gem_ext.rb

Instance Method Summary collapse

Instance Method Details

#fit(str_or_rx) ⇒ Object

Extends Watir’s methods. Use when the argument you are passing to a text field may be nil, in which case you don’t want to do anything with the page element.

Examples:

page.select_list.fit @my_selection


156
157
158
# File 'lib/test-factory/gem_ext.rb', line 156

def fit(str_or_rx)
  select_by :text, str_or_rx unless str_or_rx==nil
end

#pick(item) ⇒ Object

Same as #pick!, except it does not change the value of ‘item’



187
188
189
190
191
192
193
# File 'lib/test-factory/gem_ext.rb', line 187

def pick(item)
  if item=='::random::'
    select_at_random
  else
    fit item
  end
end

#pick!(item) ⇒ Object

Allows you to select a specific item in a select list, or, if desired, it will pick an item from the list at random.

If you pass this method the string ‘::random::’ then it will select an item at random from the select list and, assuming what you passed it was a class instance variable, it will be updated to contain the selected value (hence the ! in the method name). Note that this method will be slow with large selection lists.

Examples:

@my_selection='::random::'
page.select_list.pick! @my_selection
puts @my_selection # => <Value of randomly selected item from list>


176
177
178
179
180
181
182
# File 'lib/test-factory/gem_ext.rb', line 176

def pick!(item)
  if item=='::random::'
    item.replace(select_at_random)
  else
    fit item
  end
end