Module: Awetestlib::Regression::PageData
- Included in:
- Runner
- Defined in:
- lib/awetestlib/regression/page_data.rb
Instance Method Summary collapse
-
#capture_page_data(browser, types = [:text, :textarea, :select_list, :span, :hidden, :checkbox, :radio]) ⇒ Object
:category: Page Data :tags: data, DOM, page.
- #compare_page_data(before, after, how, desc = '') ⇒ Object
-
#fetch_page_data(data, how, what, type, get_text = true) ⇒ Object
:category: Page Data :tags:data, DOM.
- #get_element_text(browser, element, how, what, desc = '') ⇒ Object
- #get_textfield_value(browser, how, what, desc = '') ⇒ Object
- #get_textfield_value_by_id(browser, strg) ⇒ Object
- #get_textfield_value_by_name(browser, strg, desc = '') ⇒ Object
-
#parse_elements(browser, type) ⇒ Object
:category: Page Data :tags:data, DOM.
Instance Method Details
#capture_page_data(browser, types = [:text, :textarea, :select_list, :span, :hidden, :checkbox, :radio]) ⇒ Object
:category: Page Data :tags: data, DOM, page
- Parameters
-
browser is any container element, usually the browser window or a div within it. Best to use is the smallest that contains the desired data.
types is an array that defaults to all of: :text, :textarea, :select_list, :span, :hidden, :checkbox, and :radio. Set types to an array of a subset of these if fewer elements are desired.
No positive validations are reported but failure is rescued and reported.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/awetestlib/regression/page_data.rb', line 18 def capture_page_data(browser, types = [:text, :textarea, :select_list, :span, :hidden, :checkbox, :radio]) start = Time.now debug_to_log("Begin #{__method__}") data = Hash.new data[:id] = Hash.new data[:name] = Hash.new data[:index] = Hash.new types.each do |type| #debug_to_log("#{__method__}: #{type}. . .") data[:id][type], data[:name][type], data[:index][type] = parse_elements(browser, type) end data rescue failed_to_log("#{__method__}: '#{$!}'") ensure stop = Time.now passed_to_log("#{__method__.to_s.titleize} finished. (#{"%.5f" % (stop - start)} secs)") #debug_to_log("End #{__method__}") end |
#compare_page_data(before, after, how, desc = '') ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/awetestlib/regression/page_data.rb', line 38 def compare_page_data(before, after, how, desc = '') [:text, :textarea, :select_list, :span, :checkbox, :radio].each do |type| before[how][type].each_key do |what| msg = "#{desc} #{type} #{how}=#{what}: Expected '#{before[how][type][what]}'." if after[how][type][what] == before[how][type][what] passed_to_log(msg) else failed_to_log("#{msg} Found '#{after[how][type][what]}'") end end end rescue failed_to_log("Unable to compare before and after page data. '#{$!}'") end |
#fetch_page_data(data, how, what, type, get_text = true) ⇒ Object
:category: Page Data :tags:data, DOM
data is the hash returned by capture_page_data().
how is one of :id, :name, :index
what is the target value for how. It can be a string or a regular expression
type is one of :text,:textarea,:select_list,:span,:hidden,:checkbox,:radio
get_text determines whether selected option’s text or value is returned. Default is true, i.e., return the selected text. This only applies when the type is :select_list.
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/awetestlib/regression/page_data.rb', line 69 def fetch_page_data(data, how, what, type, get_text = true) rslt = data[how][type][what] if type == :select_list value, text = rslt.split('::') if get_text rslt = text else rslt = value end end rslt end |
#get_element_text(browser, element, how, what, desc = '') ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/awetestlib/regression/page_data.rb', line 172 def get_element_text(browser, element, how, what, desc = '') msg = "Return text in #{element} #{how}='#{what}'" msg << " #{desc}" if desc.length > 0 text = browser.element(how, what).text if validate(browser, @myName, __LINE__) passed_to_log("#{msg} text='#{text}'") text end rescue failed_to_log("Unable to #{msg}: '#{$!}'") end |
#get_textfield_value(browser, how, what, desc = '') ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/awetestlib/regression/page_data.rb', line 146 def get_textfield_value(browser, how, what, desc = '') msg = "Return value in textfield #{how}='#{what}'" msg << " #{desc}" if desc.length > 0 tf = browser.text_field(how, what) if validate(browser, @myName, __LINE__) if tf debug_to_log("#{tf.inspect}") vlu = tf.value passed_to_log("#{msg} Value='#{vlu}'") vlu else failed_to_log("#{msg}") end end rescue failed_to_log("Unable to #{msg}: '#{$!}'") end |
#get_textfield_value_by_id(browser, strg) ⇒ Object
168 169 170 |
# File 'lib/awetestlib/regression/page_data.rb', line 168 def get_textfield_value_by_id(browser, strg) get_textfield_value(browser, :id, strg) end |
#get_textfield_value_by_name(browser, strg, desc = '') ⇒ Object
164 165 166 |
# File 'lib/awetestlib/regression/page_data.rb', line 164 def get_textfield_value_by_name(browser, strg, desc = '') get_textfield_value(browser, :name, strg, desc) end |
#parse_elements(browser, type) ⇒ Object
:category: Page Data :tags:data, DOM
browser is any container element. best to use is the smallest that contains the desired data.
type is one of these symbols: :text,:textarea,:select_list,:span,:hidden,:checkbox,:radio
Returns three hashes: id[id] = value, name[id] = value, index[id] = value
A given element appears once in the set of hashes depending on how is is found: id first then name, then index.
Select list value is in the form ‘value::text’. parse with x.split(‘::’)
No positive validations are reported but failure is rescued and reported.
99 100 101 102 103 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 |
# File 'lib/awetestlib/regression/page_data.rb', line 99 def parse_elements(browser, type) id = Hash.new name = Hash.new index = Hash.new idx = 0 #debug_to_log("#{__method__}: #{type}") case type when :span collection = browser.spans when :select_list collection = browser.select_lists when :radio collection = browser.radios when :checkbox collection = browser.checkboxes else collection = browser.elements(:type, type.to_s) end #debug_to_log("#{__method__}: collection: #{collection.inspect}") collection.each do |e| case type when :span vlu = e.text when :select_list vlu = "#{e.value}::#{e.[0]}" when :radio vlu = e.set? when :checkbox vlu = e.set? else vlu = e.value end idx += 1 if e.id.length > 0 and not e.id =~ /^__[A-Z]/ id[e.id] = vlu elsif e.name.length > 0 and not e.name =~ /^__[A-Z]/ name[e.name] = vlu else index[idx] = vlu if not type == :hidden end end [id, name, index] rescue failed_to_log("#{__method__}: '#{$!}'") end |