Module: Awetestlib::Regression::UserInput
- Defined in:
- lib/awetestlib/regression/user_input.rb,
lib/awetestlib/regression/awetest_dsl.rb
Overview
Methods covering user interactions with the browser.
Instance Method Summary collapse
- #blur_element(element, desc = '', refs = '', how = nil, what = nil) ⇒ Object
-
#clear(container, element, how, what, value = nil, desc = '', refs = '', options = {}) ⇒ 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(container, element, how, what, desc = '', refs = '', wait = 10) ⇒ Boolean
(also: #click_js)
Click a specific DOM element identified by one of its attributes (how) and that attribute’s value (what).
- #click_as_needed(browser, target_container, target_elem, target_how, target_what, confirm_container, confirm_elem, confirm_how, confirm_what, desc = '', neg = false, alternate = false, limit = 6.0, increment = 0.5, interval = 2.0) ⇒ Object
- #click_element(element, desc = '', refs = '', how = '', what = '', value = '') ⇒ Object (also: #element_click)
-
#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.
- #element_fire_event(element, event, desc = '', refs = '', how = nil, what = nil) ⇒ Object
- #element_hover(element, desc = '', refs = '', how = nil, what = nil) ⇒ Object
- #element_set_text(element, value, desc = '', refs = '', how = '', what = '') ⇒ Object
-
#fire_event(container, element, how, what, event, desc = '', refs = '', wait = 10) ⇒ Boolean
Fire an event on a specific DOM element identified by one of its attributes and that attribute’s value.
- #focus(container, element, how, what, desc = '', refs = '', wait = 10) ⇒ Object
- #focus_element(element, desc = '', refs = '', how = nil, what = nil) ⇒ Object
- #option_selected?(container, how, what, which, option, desc = '', refs = '') ⇒ Boolean
- #option_selected_from_list?(list, which, what, desc = '', refs = '') ⇒ Boolean
- #resize_browser_window(browser, width, height, move_to_origin = true) ⇒ Object (also: #resize_window)
-
#scroll_to_bottom ⇒ Object
TODO: does this really scroll all the way to the bottom?.
-
#scroll_to_top ⇒ Object
TODO: does this really scroll all the way to the top?.
- #select_next_option_from_list(list, desc = '', refs = '') ⇒ Object
-
#select_option(browser, how, what, which, option, desc = '', refs = '', nofail = false) ⇒ Boolean
Select option from select list identified by how and what.
-
#select_option_from_list(list, how, what, desc = '', refs = '', nofail = false) ⇒ Boolean
Select option from select list (dropdown) already identified and passed to the method.
- #select_previous_option_from_list(list, desc = '', refs = '') ⇒ Object
- #send_a_key(browser, key, modifier = nil, desc = '', refs = '') ⇒ Object
- #send_down_arrow(browser, desc = '', refs = '', modifier = nil) ⇒ Object (also: #press_down_arrow)
- #send_enter(browser, desc = '', refs = '', modifier = nil) ⇒ Object (also: #press_enter)
- #send_escape(browser, desc = '', refs = '', modifier = nil) ⇒ Object (also: #press_escape)
- #send_left_arrow(browser, desc = '', refs = '', modifier = nil) ⇒ Object (also: #press_left_arrow)
-
#send_page_down(browser, desc = '', refs = '', modifier = nil) ⇒ Object
(also: #press_page_down)
TODO: does this really scroll all the way to the bottom?.
- #send_right_arrow(browser, desc = '', refs = '', modifier = nil) ⇒ Object (also: #press_right_arrow)
- #send_spacebar(browser, desc = '', refs = '', modifier = nil) ⇒ Object (also: #press_spacebar, #press_space, #send_space)
- #send_tab(browser, desc = '', refs = '', modifier = nil) ⇒ Object (also: #press_tab)
- #send_up_arrow(browser, desc = '', refs = '', modifier = nil) ⇒ Object (also: #press_up_arrow)
-
#sent_page_up(browser, desc = '', refs = '', modifier = nil) ⇒ Object
(also: #press_page_up)
TODO: does this really scroll all the way to the top?.
-
#set(container, element, how, what, value = nil, desc = '', refs = '', options = {}) ⇒ Boolean
Set radio button or checkbox to selected.
- #set_element(element, value = nil, desc = '', refs = '', how = '', what = '') ⇒ Object
-
#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 = '', refs = '', skip_value_check = false) ⇒ Boolean
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.
-
#set_textfield ⇒ Boolean
Set text field as identified by the attribute specified in how with value in what to the string specified in value.
- #tab_until_focused(container, element, how, what, class_strg = nil, desc = '', refs = '', limit = 15) ⇒ Object
- #type_in_text_field(element, strg, desc = '', refs = '') ⇒ Object
Instance Method Details
#blur_element(element, desc = '', refs = '', how = nil, what = nil) ⇒ Object
3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 |
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 3153 def blur_element(element, desc = '', refs = '', how = nil, what = nil) msg = (element, "Trigger blur", how, what, nil, desc, refs) element.fire_event('onBlur') if element.focused? passed_to_log(with_caller(msg)) true else failed_to_log(with_caller(msg)) end rescue failed_to_log(unable_to(msg)) end |
#clear(container, element, how, what, value = nil, desc = '', refs = '', options = {}) ⇒ 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.
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 |
# File 'lib/awetestlib/regression/user_input.rb', line 414 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()
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 |
# File 'lib/awetestlib/regression/user_input.rb', line 481 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(container, element, how, what, desc = '', refs = '', wait = 10) ⇒ Boolean Also known as: click_js
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 |
# File 'lib/awetestlib/regression/user_input.rb', line 25 def click(container, element, how, what, desc = '', wait = 10) msg = ("#{__method__.to_s.humanize} :#{element} :#{how}=>'#{what}'", desc, wait.to_s) code = build_webdriver_fetch(element, how, what) begin eval("#{code}.when_present(#{wait}).click") rescue => e unless rescue_me(e, __method__, rescue_me_command(element, how, what, __method__.to_s), "#{container.class}") raise e end end passed_to_log(msg) true rescue if desc =~ /second try/i passed_to_log(unable_to(msg)) else failed_to_log(unable_to(msg)) end end |
#click_as_needed(browser, target_container, target_elem, target_how, target_what, confirm_container, confirm_elem, confirm_how, confirm_what, desc = '', neg = false, alternate = false, limit = 6.0, increment = 0.5, interval = 2.0) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/awetestlib/regression/user_input.rb', line 47 def click_as_needed(browser, target_container, target_elem, target_how, target_what, confirm_container, confirm_elem, confirm_how, confirm_what, desc = '', neg = false) rtrn = true nope = neg ? 'not ' : '' debug_to_log("#{__method__.to_s.titleize}: Target: :#{target_elem} :#{target_how}=>'#{target_what}' in #{target_container}") debug_to_log("#{__method__.to_s.titleize}: Confirm: :#{confirm_elem} :#{confirm_how}=>'#{confirm_what}' in #{confirm_container}") windows_to_log(browser) click(target_container, target_elem, target_how, target_what, desc) if confirm_elem == :window query = 'current?' else query = 'present?' end if confirm_what.is_a?(Regexp) code = "#{nope}confirm_container.#{confirm_elem.to_s}(:#{confirm_how}, /#{confirm_what}/).#{query}" else code = "#{nope}confirm_container.#{confirm_elem.to_s}(:#{confirm_how}, '#{confirm_what}').#{query}" end debug_to_log("#{__method__}: code=[#{code}]") limit = 30.0 increment = 0.5 seconds = 0.0 until eval(code) do debug_to_log("#{__method__}: seconds=[#{seconds}] [#{code}]") sleep(increment) seconds += increment if seconds.modulo(3.0) == 0.0 click(target_container, target_elem, target_how, target_what, "#{desc} (#{seconds} seconds)") end if seconds > limit rtrn = false break end end rtrn rescue failed_to_log(unable_to) end |
#click_element(element, desc = '', refs = '', how = '', what = '', value = '') ⇒ Object Also known as: element_click
3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 |
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 3200 def click_element(element, desc = '', refs = '', how = '', what = '', value = '') msg = (element, 'Click', how, what, value, desc, refs) begin element.click rescue => e unless rescue_me(e, __method__, rescue_me_command(element, how, what, __method__.to_s)) raise e end 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.
156 157 158 159 160 161 162 163 164 |
# File 'lib/awetestlib/regression/user_input.rb', line 156 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
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.
Call is passed to click() if using watir-webdriver as it does not recognize click_no_wait.
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/awetestlib/regression/user_input.rb', line 104 def click_no_wait(browser, element, how, what, desc = '') if $using_webdriver click(browser, element, how, what, "#{desc} (called from click_no_wait)") # [#50300875] else 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 end 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)
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 |
# File 'lib/awetestlib/regression/user_input.rb', line 229 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.
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/awetestlib/regression/user_input.rb', line 179 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.
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/awetestlib/regression/user_input.rb', line 204 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 |
#element_fire_event(element, event, desc = '', refs = '', how = nil, what = nil) ⇒ Object
3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 |
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 3285 def element_fire_event(element, event, desc = '', refs = '', how = nil, what = nil) msg = (element, "Fire '#{event}' event on", how, what, nil, desc, refs) begin element.fire_event(event) rescue => e unless rescue_me(e, __method__, rescue_me_command(element, how, what, __method__.to_s, event)) raise e end end passed_to_log(msg) true rescue failed_to_log(unable_to(msg)) end |
#element_hover(element, desc = '', refs = '', how = nil, what = nil) ⇒ Object
3300 3301 3302 3303 3304 3305 3306 3307 |
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 3300 def element_hover(element, desc = '', refs = '', how = nil, what = nil) msg = (element, "Hover over", how, what, nil, desc, refs) element.hover passed_to_log(msg) true rescue failed_to_log(unable_to(msg)) end |
#element_set_text(element, value, desc = '', refs = '', how = '', what = '') ⇒ Object
3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 |
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 3335 def element_set_text(element, value, desc = '', refs = '', how = '', what = '') msg = (element, "Set to '#{value}':", how, what, nil, desc, refs) element.when_present.set(value) if element.value == value passed_to_log(msg) true else failed_to_log("#{msg}: Found:'#{element.value}'.") end rescue failed_to_log(unable_to(msg)) end |
#fire_event(container, element, how, what, event, desc = '', refs = '', wait = 10) ⇒ Boolean
Fire an event on a specific DOM element identified by one of its attributes and that attribute’s value.
577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 |
# File 'lib/awetestlib/regression/user_input.rb', line 577 def fire_event(container, element, how, what, event, desc = '', wait = 10) msg = ("#{element.to_s.titlecase}: #{how}=>'#{what}' event:'#{event}'", desc) code = build_webdriver_fetch(element, how, what) begin eval("#{code}.when_present(#{wait}).fire_event('#{event}')") rescue => e unless rescue_me(e, __method__, rescue_me_command(element, how, what, __method__.to_s, event), "#{container.class}") raise e end end passed_to_log(msg) true rescue failed_to_log(unable_to(msg)) end |
#focus(container, element, how, what, desc = '', refs = '', wait = 10) ⇒ Object
3132 3133 3134 3135 3136 3137 3138 |
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 3132 def focus(container, element, how, what, desc = '', refs = '', wait = 10) code = build_webdriver_fetch(element, how, what) target = eval("#{code}.when_present(#{wait})") focus_element(target, desc, refs, how, what) rescue failed_to_log(unable_to(msg)) end |
#focus_element(element, desc = '', refs = '', how = nil, what = nil) ⇒ Object
3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 |
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 3140 def focus_element(element, desc = '', refs = '', how = nil, what = nil) msg = (element, 'Set focus on', how, what, nil, desc, refs) element.focus if element.focused? passed_to_log(with_caller(msg)) true else failed_to_log(with_caller(msg)) end rescue failed_to_log(unable_to(msg)) end |
#option_selected?(container, how, what, which, option, desc = '', refs = '') ⇒ Boolean
3441 3442 3443 3444 3445 3446 3447 |
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 3441 def option_selected?(container, how, what, which, option, desc = '', refs = '') list = container.select_list(how, what).when_present msg = (desc, with_caller("from list with :#{how}='#{what}")) option_selected_from_list?(list, which, option, desc, refs) rescue failed_to_log(unable_to(msg)) end |
#option_selected_from_list?(list, which, what, desc = '', refs = '') ⇒ Boolean
3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 |
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 3449 def option_selected_from_list?(list, which, what, desc = '', refs = '') msg = (desc, "Option :#{which}='#{what}' is selected?", refs) if list.option(which, what).selected? passed_to_log(msg) true else failed_to_log(msg) end rescue failed_to_log(unable_to(msg)) end |
#resize_browser_window(browser, width, height, move_to_origin = true) ⇒ Object Also known as: resize_window
593 594 595 596 597 598 599 600 601 602 603 604 |
# File 'lib/awetestlib/regression/user_input.rb', line 593 def resize_browser_window(browser, width, height, move_to_origin = true) browser.driver.manage.window.resize_to(width, height) ("Browser window resized to (#{width}, #{height}).") sleep_for(0.5) if move_to_origin browser.driver.manage.window.move_to(0, 0) ('Browser window moved to origin (0, 0).') end scroll_to_top(browser) rescue failed_to_log(unable_to) end |
#scroll_to_bottom ⇒ Object
TODO: does this really scroll all the way to the bottom?
612 613 614 615 |
# File 'lib/awetestlib/regression/user_input.rb', line 612 def send_page_down(browser) browser.send_keys :page_down debug_to_log('Sent page down') end |
#scroll_to_top ⇒ Object
TODO: does this really scroll all the way to the top?
620 621 622 623 |
# File 'lib/awetestlib/regression/user_input.rb', line 620 def sent_page_up(browser) browser.send_keys :page_up debug_to_log('Sent page up') end |
#select_next_option_from_list(list, desc = '', refs = '') ⇒ Object
3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 |
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 3376 def select_next_option_from_list(list, desc = '', refs = '') msg = (desc, refs) = list. #This doesnt seem to account for the last option already being selected. ex. calendar with dec selected selected_index = list.[0].index if selected_index == .length - 1 new_index = 0 else new_index = [selected_index + 1] ? selected_index + 1 : 0 end select_option_from_list(list, :index, new_index, with_caller(desc), refs) rescue failed_to_log(unable_to(msg)) end |
#select_option(browser, how, what, which, option, desc = '', refs = '', nofail = false) ⇒ Boolean
Select option from select list identified by how and what. Option is identified by which and value
307 308 309 310 311 312 313 |
# File 'lib/awetestlib/regression/user_input.rb', line 307 def select_option(browser, how, what, which, option, desc = '', nofail = false) list = browser.select_list(how, what).when_present msg = ("from list with :#{how}=>'#{what}", desc) select_option_from_list(list, which, option, msg, nofail) rescue failed_to_log(unable_to) end |
#select_option_from_list(list, how, what, desc = '', refs = '', nofail = false) ⇒ Boolean
Select option from select list (dropdown) already identified and passed to the method. Selection can be by :text or :value.
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
# File 'lib/awetestlib/regression/user_input.rb', line 263 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 |
#select_previous_option_from_list(list, desc = '', refs = '') ⇒ Object
3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 |
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 3392 def select_previous_option_from_list(list, desc = '', refs = '') msg = (desc, refs) = list. #This doesnt seem to account for the last option already being selected. ex. calendar with dec selected selected_index = list.[0].index if selected_index == .length - 1 new_index = 0 else new_index = [selected_index - 1] ? selected_index - 1 : 0 end select_option_from_list(list, :index, new_index, with_caller(desc), refs) rescue failed_to_log(unable_to(msg)) end |
#send_a_key(browser, key, modifier = nil, desc = '', refs = '') ⇒ Object
3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 |
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 3522 def send_a_key(browser, key, modifier = nil, desc = '', refs = '') if modifier msg = (desc, "Sent #{modifier}+#{key}", refs) browser.send_keys [modifier, key] else msg = (desc, "Sent #{key}", refs) browser.send_keys key end (msg) end |
#send_down_arrow(browser, desc = '', refs = '', modifier = nil) ⇒ Object Also known as: press_down_arrow
3571 3572 3573 |
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 3571 def send_down_arrow(browser, desc = '', refs = '', modifier = nil) send_a_key(browser, :arrow_down, modifier, desc, refs) end |
#send_enter(browser, desc = '', refs = '', modifier = nil) ⇒ Object Also known as: press_enter
629 630 631 632 |
# File 'lib/awetestlib/regression/user_input.rb', line 629 def send_enter(browser) browser.send_keys :enter debug_to_log('Sent enter') end |
#send_escape(browser, desc = '', refs = '', modifier = nil) ⇒ Object Also known as: press_escape
653 654 655 656 |
# File 'lib/awetestlib/regression/user_input.rb', line 653 def send_escape(browser) browser.send_keys :escape debug_to_log('Sent Esc key') end |
#send_left_arrow(browser, desc = '', refs = '', modifier = nil) ⇒ Object Also known as: press_left_arrow
647 648 649 650 |
# File 'lib/awetestlib/regression/user_input.rb', line 647 def send_left_arrow(browser) browser.send_keys :arrow_left debug_to_log('Sent left arrow') end |
#send_page_down(browser, desc = '', refs = '', modifier = nil) ⇒ Object Also known as: press_page_down
TODO: does this really scroll all the way to the bottom?
608 609 610 611 |
# File 'lib/awetestlib/regression/user_input.rb', line 608 def send_page_down(browser) browser.send_keys :page_down debug_to_log('Sent page down') end |
#send_right_arrow(browser, desc = '', refs = '', modifier = nil) ⇒ Object Also known as: press_right_arrow
641 642 643 644 |
# File 'lib/awetestlib/regression/user_input.rb', line 641 def send_right_arrow(browser) browser.send_keys :arrow_right debug_to_log('Sent right arrow') end |
#send_spacebar(browser, desc = '', refs = '', modifier = nil) ⇒ Object Also known as: press_spacebar, press_space, send_space
623 624 625 626 |
# File 'lib/awetestlib/regression/user_input.rb', line 623 def (browser) browser.send_keys :space debug_to_log('Sent space') end |
#send_tab(browser, desc = '', refs = '', modifier = nil) ⇒ Object Also known as: press_tab
635 636 637 638 |
# File 'lib/awetestlib/regression/user_input.rb', line 635 def send_tab(browser) browser.send_keys :tab debug_to_log('Sent tab') end |
#send_up_arrow(browser, desc = '', refs = '', modifier = nil) ⇒ Object Also known as: press_up_arrow
3565 3566 3567 |
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 3565 def send_up_arrow(browser, desc = '', refs = '', modifier = nil) send_a_key(browser, :arrow_up, modifier, desc, refs) end |
#sent_page_up(browser, desc = '', refs = '', modifier = nil) ⇒ Object Also known as: press_page_up
TODO: does this really scroll all the way to the top?
616 617 618 619 |
# File 'lib/awetestlib/regression/user_input.rb', line 616 def sent_page_up(browser) browser.send_keys :page_up debug_to_log('Sent page up') end |
#set(container, element, how, what, value = nil, desc = '', refs = '', options = {}) ⇒ Boolean
Set radio button or checkbox to selected.
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 |
# File 'lib/awetestlib/regression/user_input.rb', line 325 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_element(element, value = nil, desc = '', refs = '', how = '', what = '') ⇒ Object
3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 |
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 3319 def set_element(element, value = nil, desc = '', refs = '', how = '', what = '') msg = (element, "Set", how, what, nil, desc, refs) case element.class.to_s when /radio/i, /checkbox/i element.set passed_to_log(msg) true when /text_field|textfield|text_area|textarea/i element_set_text(element, value, desc, refs, how, what) else failed_to_log(with_caller(desc, "#{element} not supported", refs)) end rescue failed_to_log(unable_to(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.
352 353 354 355 356 357 358 359 360 361 362 363 364 365 |
# File 'lib/awetestlib/regression/user_input.rb', line 352 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.
377 378 379 380 381 382 383 384 |
# File 'lib/awetestlib/regression/user_input.rb', line 377 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 = '', refs = '', skip_value_check = false) ⇒ Boolean
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()
447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 |
# File 'lib/awetestlib/regression/user_input.rb', line 447 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 browser.text_field(how, what).when_present.set(value) if skip_value_check passed_to_log(msg) true else if browser.text_field(how, what).value == value passed_to_log(msg) true else failed_to_log("#{msg}: Found:'#{browser.text_field(how, what).value}'.") end 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.
522 523 524 525 526 527 528 529 530 |
# File 'lib/awetestlib/regression/user_input.rb', line 522 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 |
#set_textfield ⇒ Boolean
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()
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 |
# File 'lib/awetestlib/regression/user_input.rb', line 467 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 browser.text_field(how, what).when_present.set(value) if skip_value_check passed_to_log(msg) true else if browser.text_field(how, what).value == value passed_to_log(msg) true else failed_to_log("#{msg}: Found:'#{browser.text_field(how, what).value}'.") end end rescue failed_to_log(unable_to(msg)) end |
#tab_until_focused(container, element, how, what, class_strg = nil, desc = '', refs = '', limit = 15) ⇒ Object
3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 |
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 3479 def tab_until_focused(container, element, how, what, class_strg = nil, desc = '', refs = '', limit = 15) ok = nil msg = ('Tab to set focus on', "#{element.to_s.upcase}", "#{how}='#{what}'", refs) target = get_element(container, element, how, what, nil, with_caller(desc, "(#{limit})"), refs) count = 0 (0..limit).each do |cnt| #debug_to_log("tab #{cnt}") if class_strg if target.class_name.include?(class_strg) passed_to_log(with_caller(msg, "(#{cnt} tabs)")) ok = true break end else if target.focused? passed_to_log(with_caller(msg, "(#{cnt} tabs)")) ok = true break end end container.send_keys(:tab) count = cnt #send_tab(container) end failed_to_log(unable_to(msg, "(#{count} tabs)")) unless ok ok rescue failed_to_log(unable_to) end |
#type_in_text_field(element, strg, desc = '', refs = '') ⇒ Object
3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 |
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 3509 def type_in_text_field(element, strg, desc = '', refs = '') msg = (desc, "Type (send_keys) '#{strg}' into text field :id=>'#{element.attribute_value('id')}'", refs) element.send_keys(strg) if element.value == strg passed_to_log(msg) true else failed_to_log(msg) end rescue failed_to_log(unable_to(msg)) end |