Module: Kookaburra::UIDriver::HasFields::InstanceMethods
- Defined in:
- lib/kookaburra/ui_driver/mixins/has_fields.rb
Instance Method Summary collapse
- #build_input_xpath(attribute) ⇒ Object
- #build_radio_input_xpath(attribute, value = nil) ⇒ Object
- #build_select_input_xpath(attribute, value = nil) ⇒ Object
- #build_textual_input_xpath(attribute, value = nil) ⇒ Object
- #fill_in_fields(hash, idx = 0) ⇒ Object
-
#find_input(attribute, value = nil, nth = 1, msg = nil) ⇒ Object
Find the specified input by its field name.
- #no_tag_visible?(css) ⇒ Boolean
- #submit! ⇒ Object
- #submit_button_locator ⇒ Object
- #tag_visible?(css) ⇒ Boolean
Instance Method Details
#build_input_xpath(attribute) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/kookaburra/ui_driver/mixins/has_fields.rb', line 33 def build_input_xpath(attribute) "(" + "(.//textarea)|" + "(.//select)|" + "(.//input[(not(@type='button')) and (not(@type='reset')) and (not(@type='submit'))])" + ")[contains(@id,'_#{attribute}')]" # TODO: Avoid false positives by matching to the end of the id # string for everything but radio buttons and checkboxes # ... or something better than that. end |
#build_radio_input_xpath(attribute, value = nil) ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/kookaburra/ui_driver/mixins/has_fields.rb', line 59 def build_radio_input_xpath(attribute, value=nil) # The id will be the attribute suffixed by something representative of # the button value, with an underscore in between, but we don't necessarily # know the correct suffix, so ensure that the "_" is in the id, and then # find the correct match using the value attribute. xpath = ".//input[@type='radio'][contains(@id, #{attribute}_)]" xpath = "(#{xpath})[@value='#{value}']" end |
#build_select_input_xpath(attribute, value = nil) ⇒ Object
68 69 70 |
# File 'lib/kookaburra/ui_driver/mixins/has_fields.rb', line 68 def build_select_input_xpath(attribute, value=nil) xpath = ".//select[contains(@id, #{attribute})]/option[text()='#{value}']" end |
#build_textual_input_xpath(attribute, value = nil) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/kookaburra/ui_driver/mixins/has_fields.rb', line 44 def build_textual_input_xpath(attribute, value=nil) # Since the type attribute might not be present or might contain # just about any value, check for and exclude nodes with type # containing a non-textual value. "(" + "(.//textarea)|" + "(.//input[" + "(not(@type='button')) and (not(@type='checkbox')) and (not(@type='radio')) and " + "(not(@type='reset')) and (not(@type='submit'))" + "])" + ")[" + "substring(@id,string-length(@id)-#{attribute.length-1},#{attribute.length})='#{attribute}'" + "]" end |
#fill_in_fields(hash, idx = 0) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/kookaburra/ui_driver/mixins/has_fields.rb', line 96 def fill_in_fields(hash, idx = 0) @body = nil # If not explicitly ordered, then we must think the fill-in order doesn't # matter, so make the order more assuredly arbitrary to find out sooner # if that's not a correct thought. hash = hash.map.shuffle if Hash === hash && ! ActiveSupport::OrderedHash === hash hash.each do |field, value| fill_in_form_element(field, value, idx) end end |
#find_input(attribute, value = nil, nth = 1, msg = nil) ⇒ Object
Find the specified input by its field name. The value argument is used to find the correct input if (as in the case of a radio button) there might be a separate input element for each value the field might contain. Otherwise, it is ignored. When the name value will be used, its #to_s value must be valid as an xpath string body expression.
77 78 79 80 81 82 83 84 85 |
# File 'lib/kookaburra/ui_driver/mixins/has_fields.rb', line 77 def find_input(attribute, value=nil, nth=1, msg=nil) method = self.class.input_xpath_builder_names[attribute] #TODO: Build a qualified attribute name, and pass that to the xpath builder # to handle forms with multiple models that may have common attribute # names. xpath = send(method, attribute.to_s, value.to_s) xpath = "(#{xpath})[#{nth}]" if nth > 1 browser.find(:xpath, xpath, :message => msg) end |
#no_tag_visible?(css) ⇒ Boolean
128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/kookaburra/ui_driver/mixins/has_fields.rb', line 128 def no_tag_visible?(css) # use of wait_until is supposed to be redundant with #has_no_css?, but # getting intermittent Selenium::WebDriver::Error::StaleElementReferenceError. # Just wrapping in an explicit wait_until did not capture the exception, # so apparently that one is explicitly passed through rather than being # retried. browser.wait_until do begin browser.has_no_css?(css, :visible => true) rescue Selenium::WebDriver::Error::StaleElementReferenceError next false # Keep trying if not yet timed out. end end end |
#submit! ⇒ Object
91 92 93 94 |
# File 'lib/kookaburra/ui_driver/mixins/has_fields.rb', line 91 def submit! click_on no_500_error! end |
#submit_button_locator ⇒ Object
87 88 89 |
# File 'lib/kookaburra/ui_driver/mixins/has_fields.rb', line 87 def raise "Subclass responsibility!" end |
#tag_visible?(css) ⇒ Boolean
124 125 126 |
# File 'lib/kookaburra/ui_driver/mixins/has_fields.rb', line 124 def tag_visible?(css) browser.has_css?(css, :visible => true) end |