Module: Awetestlib::Regression::UserInput

Included in:
Runner
Defined in:
lib/awetestlib/regression/user_input.rb

Overview

Methods covering user interactions with the browser.

Instance Method Summary collapse

Instance Method Details

#clear(browser, element, how, what, value = nil, desc = '') ⇒ Boolean

Clear (unset) radio, checkbox or text field as identified by the attribute specified in how with value what. It’s :value attribute can also be used when needed by specifying value (Ignored for text_field). In the case of text_field this is the string to be entered in the field.

Parameters:

  • browser (Watir::Browser)

    A reference to the browser window or container element to be tested.

  • element (Symbol)

    The kind of element to clear. Must be :radio, :checkbox or :text_field.

  • how (Symbol)

    The element attribute used to identify the specific checkbox. Valid values depend on the kind of element. Common values: :text, :id, :title, :name, :class.

  • what (String, Regexp)

    A string or a regular expression to be found in the specified attribute that uniquely identifies the element.

  • value (String, Regexp) (defaults to: nil)

    A string or a regular expression to be found in the :value attribute of the element.

  • desc (String) (defaults to: '')

    Contains a message or description intended to appear in the log and/or report output

Returns:

  • (Boolean)

    True if the Watir or Watir-webdriver function does not throw an exception.



377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
# File 'lib/awetestlib/regression/user_input.rb', line 377

def clear(browser, element, how, what, value = nil, desc = '')
  msg = "Clear #{element} #{how}=>'#{what}' "
  msg << ", value=>#{value} " if value
  msg << " '#{desc}' " if desc.length > 0
  case element
    when :radio
      browser.radio(how, what).clear
    when :checkbox
      browser.checkbox(how, what).clear
    when :text_field
      browser.text_field(how, what).set('')
    else
      failed_to_log("#{__method__}: #{element} not supported")
  end
  passed_to_log(msg)
  true
rescue
  failed_to_log("#{msg} '#{$!}'")
end

#clear_textfield(browser, how, what, skip_value_check = false) ⇒ Boolean

Clear text field as identified by the attribute specified in how with value in what to the string specified in value. This method differs from set() in that 1( it uses the Watir #clear method, 2( it validates that the text field has been set to the specified value. The value verification can be turned off by setting skip_value_check to true. This is useful when the text_field performs formatting on the entered string. See set_text_field_and_validate()

Parameters:

  • browser (Watir::Browser)

    A reference to the browser window or container element to be tested.

  • how (Symbol)

    The element attribute used to identify the specific checkbox. Valid values depend on the kind of element. Common values: :text, :id, :title, :name, :class.

  • what (String, Regexp)

    A string or a regular expression to be found in the specified attribute that uniquely identifies the element.

  • skip_value_check (Boolean) (defaults to: false)

    Forces verification of value in text field to pass.

Returns:

  • (Boolean)

    True if the Watir or Watir-webdriver function does not throw an exception.



449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
# File 'lib/awetestlib/regression/user_input.rb', line 449

def clear_textfield(browser, how, what, skip_value_check = false)
  msg1 = "Skip value check." if skip_value_check
  msg = build_message("#{__method__.to_s.humanize}  #{how}='#{what}'.", msg1)
  if browser.text_field(how, what).exists?
    tf = browser.text_field(how, what)
    tf.clear
    if tf.value == ''
      passed_to_log(msg)
      true
    elsif skip_value_check
      passed_to_log(msg)
      true
    else
      failed_to_log("#{msg} Found:'#{tf.value}'.")
    end
  else
    failed_to_log("#{msg} Textfield not found.")
  end
rescue
  failed_to_log("Unable to #{msg} '#{$!}'.")
end

#click(browser, element, how, what, desc = '') ⇒ Boolean

Click a specific DOM element identified by one of its attributes (how) and that attribute’s value (what).

Examples:

# html for a link element:
# <a href="http://pragmaticprogrammer.com/titles/ruby/" id="one" name="book">Pickaxe</a>

click(browser, :link, :text, 'Pickaxe')

Parameters:

  • browser (Watir::Browser)

    A reference to the browser window or container element to be tested.

  • element (Symbol)

    The kind of element to click. Must be one of the elements recognized by Watir. Some common values are :link, :button, :image, :div, :span.

  • how (Symbol)

    The element attribute used to identify the specific element. Valid values depend on the kind of element. Common values: :text, :id, :title, :name, :class, :href (:link only)

  • what (String, Regexp)

    A string or a regular expression to be found in the how attribute that uniquely identifies the element.

  • desc (String) (defaults to: '')

    Contains a message or description intended to appear in the log and/or report output

Returns:

  • (Boolean)

    True if the Watir or Watir-webdriver function does not throw an exception.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/awetestlib/regression/user_input.rb', line 25

def click(browser, element, how, what, desc = '')
  #debug_to_log("#{__method__}: #{element}, #{how}, #{what}")
  msg = build_message("#{__method__.to_s.humanize} :#{element} :#{how}=>'#{what}'", desc)
  case element
    when :link
      browser.link(how, what).click
    when :button
      browser.button(how, what).click
    when :image
      browser.image(how, what).click
    when :radio
      case how
        when :index
          set_radio_by_index(browser, what, desc)
        else
          browser.radio(how, what).set
      end
    when :span
      browser.span(how, what).click
    when :div
      browser.div(how, what).click
    when :cell
      browser.cell(how, what).click
    else
      browser.element(how, what).click
  end
  passed_to_log(msg)
  true
rescue
  failed_to_log("Unable to #{msg}. '#{$!}'")
end

#click_img_by_src_and_index(browser, what, index, desc = '') ⇒ Boolean

Click an image element identified by the value of its :src attribute and its index within the array of image elements with src containing what and within the container referred to by browser.

Parameters:

  • browser (Watir::Browser, Watir::Container)

    A reference to the browser window or container element to be tested.

  • what (String, Regexp)

    A string or a regular expression to be found in the specified attribute that uniquely identifies the element.

  • index (Fixnum)

    An integer that indicates the index of the element within the array of image elements with src containing what.

  • desc (String) (defaults to: '')

    Contains a message or description intended to appear in the log and/or report output

Returns:

  • (Boolean)

    True if the Watir or Watir-webdriver function does not throw an exception.



121
122
123
124
125
126
127
128
129
# File 'lib/awetestlib/regression/user_input.rb', line 121

def click_img_by_src_and_index(browser, what, index, desc = '')
  msg = "Click image by src='#{what}' and index=#{index}"
  msg << " #{desc}" if desc.length > 0
  browser.image(:src => what, :index => index).click
  passed_to_log(msg)
  true
rescue
  failed_to_log("Unable to #{msg} '#{$!}'")
end

#click_no_wait(browser, element, how, what, desc = '') ⇒ Boolean

TODO:

handle using Watir Webdriver which does not need no_wait.

Click a specific DOM element by one of its attributes (*how) and that attribute’s value (*what) and do not wait for the browser to finish reloading. Used when a modal popup or alert is expected. Allows the script to keep running so the popup can be handled.

Examples:

# html for a link element:
# <a href="http://pragmaticprogrammer.com/titles/ruby/" id="one" name="book">Pickaxe</a>

click_no_wait(browser, :link, :text, 'Pickaxe')

Parameters:

  • browser (Watir::Browser)

    A reference to the browser window or container element to be tested.

  • element (Symbol)

    The kind of element to click. Must be one of the elements recognized by Watir. Some common values are :link, :button, :image, :div, :span.

  • how (Symbol)

    The element attribute used to identify the specific element. Valid values depend on the kind of element. Common values: :text, :id, :title, :name, :class, :href (:link only)

  • what (String, Regexp)

    A string or a regular expression to be found in the how attribute that uniquely identifies the element.

  • desc (String) (defaults to: '')

    Contains a message or description intended to appear in the log and/or report output

Returns:

  • (Boolean)

    True if the Watir or Watir-webdriver function does not throw an exception.

See Also:



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/awetestlib/regression/user_input.rb', line 73

def click_no_wait(browser, element, how, what, desc = '')
  msg = build_message("#{__method__.to_s.humanize} :#{element} :#{how}=>'#{what}'", desc)
  begin
    case element
      when :link
        browser.link(how, what).click_no_wait
      when :button
        browser.button(how, what).click_no_wait
      when :image
        browser.image(how, what).click_no_wait
      when :radio
        case how
          when :index
            set_radio_no_wait_by_index(browser, what, desc)
          else
            browser.radio(how, what).click_no_wait
        end
      when :span
        browser.span(how, what).click_no_wait
      when :div
        browser.div(how, what).click_no_wait
      when :checkbox
        browser.checkbox(how, what).click_no_wait
      when :cell
        browser.cell(how, what).click_no_wait
      else
        browser.element(how, what).click_no_wait
    end
  rescue => e
    unless rescue_me(e, __method__, rescue_me_command(element, how, what, :click_no_wait), "#{browser.class}")
      raise e
    end
  end
  passed_to_log(msg)
  true
rescue
  failed_to_log("Unable to #{msg}  '#{$!}'")
  sleep_for(1)
end

#click_popup_button(title, button, wait = 9, user_input = nil) ⇒ Boolean

Click a specifific button on a popup window. (Windows only)

Parameters:

  • title (String)

    A string starting at the beginning of the title which uniquely identifies the popup window.

  • button (String)

    The value displayed for the button (e.g. OK, Yes, Cancel, etc)

  • wait (Fixnum) (defaults to: 9)

    Integer indicating the number of seconds to wait for the popup window to appear.

Returns:

  • (Boolean)

    True if the Watir or Watir-webdriver function does not throw an exception.



194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/awetestlib/regression/user_input.rb', line 194

def click_popup_button(title, button, wait= 9, user_input=nil)
  #TODO: is winclicker still viable/available?
  wc = WinClicker.new
  if wc.clickWindowsButton(title, button, wait)
    passed_to_log("Window '#{title}' button '#{button}' found and clicked.")
    true
  else
    failed_to_log("Window '#{title}' button '#{button}' not found. (#{__LINE__})")
  end
  wc = nil
  # get a handle if one exists
  #    hwnd = $ie.enabled_popup(wait)
  #    if (hwnd)  # yes there is a popup
  #      w = WinClicker.new
  #      if ( user_input )
  #        w.setTextValueForFileNameField( hwnd, "#{user_input}" )
  #      end
  #      # I put this in to see the text being input it is not necessary to work
  #      sleep 3
  #      # "OK" or whatever the name on the button is
  #      w.clickWindowsButton_hwnd( hwnd, "#{button}" )
  #      #
  #      # this is just cleanup
  #      w=nil
  #    end
end

#click_table_row_with_text(browser, how, what, text, desc = '', column = nil) ⇒ Boolean

Click the first row which contains a particular string in a table identified by attribute and value. A specific column in the table can also be specified. If not supplied all columns will be checked.

Parameters:

  • browser (Watir::Browser)

    A reference to the browser window or container element to be tested.

  • how (Symbol)

    The element attribute used to identify the specific element. Valid values depend on the kind of element. Common values: :text, :id, :title, :name, :class, :href (:link only)

  • what (String, Regexp)

    A string or a regular expression to be found in the how attribute that uniquely identifies the element.

  • text (String)

    Full text string to be found in the table row.

  • desc (String) (defaults to: '')

    Contains a message or description intended to appear in the log and/or report output

  • column (Fixnum) (defaults to: nil)

    Integer indicating the column to search for the text string.

Returns:

  • (Boolean)

    True if the Watir or Watir-webdriver function does not throw an exception.



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/awetestlib/regression/user_input.rb', line 144

def click_table_row_with_text(browser, how, what, text, desc = '', column = nil)
  msg   = build_message("Click row with text #{text} in table :#{how}=>'#{what}.", desc)
  table = get_table(browser, how, what, desc)
  if table
    index = get_index_of_row_with_text(table, text, column)
    if index
      table[index].click
      passed_to_log(msg)
      index
    else
      failed_to_log("#{msg} Row not found.")
    end
  else
    failed_to_log("#{msg} Table not found.")
  end
rescue
  failed_to_log("Unable to #{msg}: '#{$!}'")
end

#double_click_table_row_with_text(browser, how, what, text, desc = '', column = nil) ⇒ Boolean

Double click the first row which contains a particular string in a table identified by attribute and value. A specific column in the table can also be specified. Uses fire_event method in Watir to send ‘onDblClick’ event.

Parameters:

  • browser (Watir::Browser)

    A reference to the browser window or container element to be tested.

  • how (Symbol)

    The element attribute used to identify the specific element. Valid values depend on the kind of element. Common values: :text, :id, :title, :name, :class, :href (:link only)

  • what (String, Regexp)

    A string or a regular expression to be found in the how attribute that uniquely identifies the element.

  • text (String)

    Full text string to be found in the table row.

  • desc (String) (defaults to: '')

    Contains a message or description intended to appear in the log and/or report output

  • column (Fixnum) (defaults to: nil)

    Integer indicating the column to search for the text string.

Returns:

  • (Boolean)

    True if the Watir or Watir-webdriver function does not throw an exception.



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/awetestlib/regression/user_input.rb', line 169

def double_click_table_row_with_text(browser, how, what, text, desc = '', column = nil)
  msg   = build_message("Double click row with text #{text} in table :#{how}=>'#{what}.", desc)
  table = get_table(browser, how, what, desc)
  if table
    index = get_index_of_row_with_text(table, text, column)
    if index
      table[index].fire_event('ondblclick')
      passed_to_log(msg)
      index
    else
      failed_to_log("#{msg} Row not found.")
    end
  else
    failed_to_log("#{msg} Table not found.")
  end
rescue
  failed_to_log("Unable to #{msg}: '#{$!}'")
end

#fire_event(browser, element, how, what, event, desc = '') ⇒ Boolean

Fire an event on a specific DOM element identified by one of its attributes and that attribute’s value.

Examples:

# html for a link element:
# <a href="http://pragmaticprogrammer.com/titles/ruby/" id="one" name="book">Pickaxe</a>

fire_event(browser, :link, :text, 'Pickaxe', 'onMouseOver')

Parameters:

  • browser (Watir::Browser)

    A reference to the browser window or container element to be tested.

  • element (Symbol)

    The kind of element to click. Must be one of the elements recognized by Watir. Some common values are :link, :button, :image, :div, :span.

  • how (Symbol)

    The element attribute used to identify the specific element. Valid values depend on the kind of element. Common values: :text, :id, :title, :name, :class, :href (:link only)

  • what (String, Regexp)

    A string or a regular expression to be found in the how attribute that uniquely identifies the element.

  • event (String)

    A string identifying the event to be fired.

  • desc (String) (defaults to: '')

    Contains a message or description intended to appear in the log and/or report output

Returns:

  • (Boolean)

    True if the Watir or Watir-webdriver function does not throw an exception.



545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
# File 'lib/awetestlib/regression/user_input.rb', line 545

def fire_event(browser, element, how, what, event, desc = '')
  msg = build_message("#{element.to_s.titlecase}: #{how}=>'#{what}' event:'#{event}'", desc)
  begin
    case element
      when :link
        browser.link(how, what).fire_event(event)
      when :button
        browser.button(how, what).fire_event(event)
      when :image
        browser.image(how, what).fire_event(event)
      when :span
        browser.span(how, what).fire_event(event)
      when :div
        browser.div(how, what).fire_event(event)
      else
        browser.element(how, what).fire_event(event)
    end
  rescue => e
    unless rescue_me(e, __method__, rescue_me_command(element, how, what, __method__.to_s, event), "#{browser.class}")
      raise e
    end
  end
  passed_to_log("Fire event: #{msg}. #{desc}")
  true
rescue
  failed_to_log("Unable to fire event: #{msg}. '#{$!}' #{desc}")
end

#select_option(browser, how, what, which, option, desc = '', nofail = false) ⇒ Boolean

Select option from select list identified by how and what. Option is identified by which and value

Parameters:

  • browser (Watir::Browser)

    A reference to the browser window or container element to be tested.

  • how (Symbol)

    The element attribute used to identify the specific element. Valid values depend on the kind of element. Common values: :text, :id, :title, :name, :class, :href (:link only)

  • what (String, Regexp)

    A string or a regular expression to be found in the specified attribute that uniquely identifies the element.

  • which (Symbol)

    Either :text or :value.

  • option (String/Rexexp)

    A string or regular expression that will uniquely identify the option to select.

  • desc (String) (defaults to: '')

    Contains a message or description intended to appear in the log and/or report output

  • nofail (Boolean) (defaults to: false)

    If true do not log a failed message if the option is not found in the select list.

Returns:

  • (Boolean)

    True if the Watir or Watir-webdriver function does not throw an exception.



272
273
274
275
276
# File 'lib/awetestlib/regression/user_input.rb', line 272

def select_option(browser, how, what, which, option, desc = '', nofail = false)
  list = browser.select_list(how, what)
  msg  = build_message("from list with :#{how}=>'#{what}", desc)
  select_option_from_list(list, which, option, msg, nofail)
end

#select_option_from_list(list, how, what, desc = '', nofail = false) ⇒ Boolean

Select option from select list (dropdown) already identified and passed to the method. Selection can be by :text or :value.

Parameters:

  • list (Watir::SelectList)

    A reference to the specific select list object.

  • how (Symbol)

    Either :text or :value.

  • what (String/Rexexp)

    A string or regular expression that will uniquely identify the option to select.

  • desc (String) (defaults to: '')

    Contains a message or description intended to appear in the log and/or report output

  • nofail (Boolean) (defaults to: false)

    If true do not log a failed message if the option is not found in the select list.

Returns:

  • (Boolean)

    True if the Watir or Watir-webdriver function does not throw an exception.



228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
# File 'lib/awetestlib/regression/user_input.rb', line 228

def select_option_from_list(list, how, what, desc = '', nofail = false)
  msg = build_message("Select :#{how}=>'#{what}'", desc)
  ok  = true
  if list
    case how
      when :text
        list.select(what) #TODO: regex?
      when :value
        list.select_value(what) #TODO: regex?
      when :index
        list.select(list.getAllContents[what.to_i])
      else
        failed_to_log("#{msg}  Select by #{how} not supported.")
        ok = false
    end
    if ok
      passed_to_log(msg)
      true
    else
      if nofail
        passed_to_log("#{msg} Option not found. No Fail specified.")
        true
      else
        failed_to_log("#{msg} Option not found.")
      end
    end
  else
    failed_to_log("#{msg} Select list not found.")
  end
rescue
  failed_to_log("Unable to #{msg} '#{$!}'")
end

#set(browser, element, how, what, value = nil, desc = '') ⇒ Boolean

Set radio button or checkbox to selected.

Parameters:

  • browser (Watir::Browser)

    A reference to the browser window or container element to be tested.

  • element (Symbol)

    The kind of element to click. Must be either :radio or :checkbox.

  • how (Symbol)

    The element attribute used to identify the specific element. Valid values depend on the kind of element. Common values: :text, :id, :title, :name, :class, :href (:link only)

  • what (String, Regexp)

    A string or a regular expression to be found in the specified attribute that uniquely identifies the element.

  • value (String, Regexp) (defaults to: nil)

    A string or a regular expression to be found in the :value attribute of the radio or checkbox.

  • desc (String) (defaults to: '')

    Contains a message or description intended to appear in the log and/or report output

Returns:

  • (Boolean)

    True if the Watir or Watir-webdriver function does not throw an exception.



288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
# File 'lib/awetestlib/regression/user_input.rb', line 288

def set(browser, element, how, what, value = nil, desc = '')
  msg = "Set #{element} #{how}=>'#{what}' "
  msg << ", :value=>#{value} " if value
  msg << " '#{desc}' " if desc.length > 0
  case element
    when :radio
      browser.radio(how, what).set
    when :checkbox
      browser.checkbox(how, what).set
    else
      failed_to_log("#{__method__}: #{element} not supported")
  end
  passed_to_log(msg)
  true
rescue
  failed_to_log("#{msg} '#{$!}'")
end

#set_file_field(browser, how, what, filespec, desc = '') ⇒ Boolean

Set file field element, identified by how and what, to a specified file path and name.

Parameters:

  • browser (Watir::Browser)

    A reference to the browser window or container element to be tested.

  • how (Symbol)

    The element attribute used to identify the specific element. Valid values depend on the kind of element. Common values: :text, :id, :title, :name, :class, :href (:link only)

  • what (String, Regexp)

    A string or a regular expression to be found in the specified attribute that uniquely identifies the element.

  • filespec (String)

    The full path and name of the target file.

  • desc (String) (defaults to: '')

    Contains a message or description intended to appear in the log and/or report output

Returns:

  • (Boolean)

    True if the Watir or Watir-webdriver function does not throw an exception.



315
316
317
318
319
320
321
322
323
324
325
326
327
328
# File 'lib/awetestlib/regression/user_input.rb', line 315

def set_file_field(browser, how, what, filespec, desc = '')
  msg = build_message("#{__method__.to_s.humanize} #{how}=>#{what} to '#{filespec}.", desc)
  ff  = browser.file_field(how, what)
  if ff
    ff.set filespec
    sleep_for(8)
    passed_to_log(msg)
    true
  else
    failed_to_log("#{msg} File field not found.")
  end
rescue
  failed_to_log("Unable to #{msg} '#{$!}'")
end

#set_radio_two_attributes(browser, how1, what1, how2, what2, desc = '') ⇒ Boolean

Set radio button as selected using two element attributes.

Parameters:

  • browser (Watir::Browser)

    A reference to the browser window or container element to be tested.

  • how1 (Symbol)

    The first element attribute used to identify the specific element. Valid values depend on the kind of element. Common values: :text, :id, :title, :name, :class, :href (:link only)

  • what1 (String, Regexp)

    A string or a regular expression to be found in the specified attribute that uniquely identifies the element.

  • how2 (Symbol)

    The second element attribute used to identify the specific element.

  • what2 (String, Regexp)

    A string or a regular expression to be found in the specified attribute that uniquely identifies the element.

  • desc (String) (defaults to: '')

    Contains a message or description intended to appear in the log and/or report output

Returns:

  • (Boolean)

    True if the Watir or Watir-webdriver function does not throw an exception.



340
341
342
343
344
345
346
347
# File 'lib/awetestlib/regression/user_input.rb', line 340

def set_radio_two_attributes(browser, how1, what1, how2, what2, desc = '')
  msg = build_message("Set radio #{how1}='#{what1}', #{how2}= #{what2}", desc)
  browser.radio(how1 => what1, how2 => what2).set
  passed_to_log(msg)
  true
rescue
  failed_to_log("#{msg} '#{$!}'")
end

#set_text_field(browser, how, what, value, desc = '', skip_value_check = false) ⇒ Boolean Also known as: set_textfield

Set text field as identified by the attribute specified in how with value in what to the string specified in value. This method differs from set() in that it validates that the text field has been set to the specified value. The value verification can be turned off by setting skip_value_check to true. This is useful when the text_field performs formatting on the entered string. See set_text_field_and_validate()

Parameters:

  • browser (Watir::Browser)

    A reference to the browser window or container element to be tested.

  • how (Symbol)

    The element attribute used to identify the specific checkbox. Valid values depend on the kind of element. Common values: :text, :id, :title, :name, :class.

  • what (String, Regexp)

    A string or a regular expression to be found in the specified attribute that uniquely identifies the element.

  • value (String)

    A string to enter into the text field.

  • desc (String) (defaults to: '')

    Contains a message or description intended to appear in the log and/or report output

  • skip_value_check (Boolean) (defaults to: false)

    Forces verification of value in text field to pass.

Returns:

  • (Boolean)

    True if the Watir or Watir-webdriver function does not throw an exception.



410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
# File 'lib/awetestlib/regression/user_input.rb', line 410

def set_text_field(browser, how, what, value, desc = '', skip_value_check = false)
  #TODO: fix this to handle Safari password field
  msg = build_message("#{__method__.to_s.humanize} #{how}='#{what}' to '#{value}'", desc)
  msg << " (Skip value check)" if skip_value_check
  if browser.text_field(how, what).exists?
    tf = browser.text_field(how, what)
    tf.set(value)
    if skip_value_check
      passed_to_log(msg)
      true
    else
      if tf.value == value
        passed_to_log(msg)
        true
      else
        failed_to_log("#{msg}: Found:'#{tf.value}'.")
      end
    end
  else
    failed_to_log("#{msg}: Textfield not found")
  end
rescue
  failed_to_log("Unable to '#{msg}': '#{$!}'")
end

#set_text_field_and_validate(browser, how, what, value, valid_value = nil, desc = '') ⇒ Boolean

Set text field as identified by the attribute specified in how with value in what to the string specified in value. and verify that the text field is set to the string in valid_value.

Examples:

set_text_field_and_validate(browser, :id, 'text field id', '99999', 'Dollar format', '$99,999.00')

Parameters:

  • browser (Watir::Browser)

    A reference to the browser window or container element to be tested.

  • how (Symbol)

    The element attribute used to identify the specific checkbox. Valid values depend on the kind of element. Common values: :text, :id, :title, :name, :class.

  • what (String, Regexp)

    A string or a regular expression to be found in the specified attribute that uniquely identifies the element.

  • value (String)

    A string to enter into the text field.

  • desc (String) (defaults to: '')

    Contains a message or description intended to appear in the log and/or report output. Required in this method.

  • valid_value (String) (defaults to: nil)

    The expected value of the text field, e.g., following reformatting.

Returns:

  • (Boolean)

    True if the Watir or Watir-webdriver function does not throw an exception.



490
491
492
493
494
495
496
497
498
# File 'lib/awetestlib/regression/user_input.rb', line 490

def set_text_field_and_validate(browser, how, what, value, valid_value = nil, desc ='')
  #NOTE: use when value and valid_value differ as with dollar reformatting
  if set_text_field(browser, how, what, value, desc, true)
    expected = valid_value ? valid_value : value
    validate_textfield_value(browser, how, what, expected, desc)
  end
rescue
  failed_to_log("Unable to '#{msg}': '#{$!}'")
end