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
-
#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.
-
#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.
-
#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).
-
#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.
-
#click_no_wait(browser, element, how, what, desc = '') ⇒ Boolean
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.
-
#click_popup_button(title, button, wait = 9, user_input = nil) ⇒ Boolean
Click a specifific button on a popup window.
-
#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.
-
#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.
-
#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.
-
#select_option(browser, how, what, which, option, desc = '', nofail = false) ⇒ Boolean
Select option from select list identified by how and what.
-
#select_option_from_list(list, how, what, desc = '', nofail = false) ⇒ Boolean
Select option from select list (dropdown) already identified and passed to the method.
-
#set(browser, element, how, what, value = nil, desc = '') ⇒ Boolean
Set radio button or checkbox to selected.
-
#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.
-
#set_radio_two_attributes(browser, how1, what1, how2, what2, desc = '') ⇒ Boolean
Set radio button as selected using two element attributes.
-
#set_text_field(browser, how, what, value, desc = '', skip_value_check = false) ⇒ Boolean
(also: #set_textfield)
Set text field as identified by the attribute specified in how with value in what to the string specified in value.
-
#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.
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.
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()
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 = ("#{__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).
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 = ("#{__method__.to_s.humanize} :#{element} :#{how}=>'#{what}'", desc) case element when :link browser.link(how, what).click when :button browser.(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.
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
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.
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 = ("#{__method__.to_s.humanize} :#{element} :#{how}=>'#{what}'", desc) begin case element when :link browser.link(how, what).click_no_wait when :button browser.(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)
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 (title, , wait= 9, user_input=nil) #TODO: is winclicker still viable/available? wc = WinClicker.new if wc.clickWindowsButton(title, , wait) passed_to_log("Window '#{title}' button '#{}' found and clicked.") true else failed_to_log("Window '#{title}' 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.
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 = ("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.
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 = ("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.
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 = ("#{element.to_s.titlecase}: #{how}=>'#{what}' event:'#{event}'", desc) begin case element when :link browser.link(how, what).fire_event(event) when :button browser.(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
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 = ("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.
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 = ("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.
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.
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 = ("#{__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.
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 = ("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()
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 = ("#{__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.
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 |