lib/scoutui/appmodel/q_model.rb in scoutui-2.0.3.39.pre vs lib/scoutui/appmodel/q_model.rb in scoutui-2.0.3.40.pre

- old
+ new

@@ -179,10 +179,149 @@ result=nil if result.empty? puts __FILE__ + (__LINE__).to_s + " result : #{result}" result end + def flattenPageObject(h, path="") + rc=iterate(h, path) + if rc.is_a?(Array) + return rc[0] + end + nil + end + + def iterate(h, path="") + rc=true + assertions=[] + + Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " ===== iterate(#{h}, #{path}) =====" + + if h.is_a?(String) + Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " => process #{h}" + if h.match(/^\s*(page)\s*\(.*\)\s*$/i) + Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " => process Page #{h}" + page_elt = getPageElement(h) + Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " => #{page_elt}" + assertions << iterate(page_elt, path) + else + Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " UNKNOWN: #{h}" + assertions << "#{h} : unknown" + end + + elsif h.is_a?(Hash) && h.has_key?('locator') + + Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " == add #{h} ==" + assertions << { :path => path, :data => h } + + elsif h.is_a?(Hash) + + Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + "Keys.size: #{h.keys[0]}" + + if h.keys.size==1 && h[h.keys[0]].is_a?(Hash) && h[h.keys[0]].has_key?('locator') + + Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " add assertion #{h}" + assertions << { :path => path, :data => h } + + elsif h.keys.size==1 && h[h.keys[0]].is_a?(Hash) + + # "id": { + # } + + _id = h.keys[0] + Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " LocatorID : #{_id}" + + if true + h[_id].each_pair { |_k, _h| + + Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " | id(#{_id}) => #{_k}, #{_h}" + + if _h.keys.size==1 && _h[_h.keys[0]].is_a?(Hash) && !_h[_h.keys[0]].has_key?('locator') + Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " id(#{_id}) => #{_h}" + _a = iterate(_h, "#{path}.#{_id}") + _a.each do |_e| + assertions << _e + end + elsif _h.keys.size==1 && _h[_h.keys[0]].is_a?(Hash) && _h[_h.keys[0]].has_key?('locator') + assertions << { :path => "#{path}.#{_id}", :data => h[_h.keys[0]] } + elsif _h.is_a?(Hash) && _h.has_key?('locator') + assertions << { :path => "#{path}.#{_id}.#{_k}", :data => _h } + else + Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " | id(#{path}.#{_id}.#{_k}) - #{_h}" + + _h.each do |k, v| +# puts __FILE__ + (__LINE__).to_s + " processing #{_id}.#{k}, #{v}" + if v.is_a?(Hash) && v.has_key?('locator') + Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " processing #{_id}.#{_k}.#{k}" + elsif v.is_a?(Hash) || v.is_a?(Array) + Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " processing #{_id}.#{k} - #{v}" + _a = iterate(v, "#{path}.#{_id}.#{k}") + _a.each do |_e| + assertions << _e + end + else + Scoutui::Logger::LogMgr.instance.debug("Assert => k is #{k}, value is #{v}") + # assertions << "#{k} #{v}" + rc=rc && true + end + end + + Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " adding assertions id(#{_id}.#{_k}) - #{_h}" + assertions << "id(#{_id}.#{_k}) - #{_h}" + end + + } + end + + + + else + + Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " ** process #{h} **" + _list=Array.new + h.each do |k, v| + if v.is_a?(Hash) && v.has_key?('locator') + + Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " add to assertion #{k} => #{v}" + _list.push({ :path => "#{path}.get(#{k})", :dat => v }) + + Scoutui::Logger::LogMgr.instance.debug " _list ==> #{_list}" + elsif v.is_a?(Hash) || v.is_a?(Array) + + # login_form => {"userid"=>{"locator"=>"#userid"}, "password"=>{"locator"=>"#pass"}} + + + Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " >>>> #{k} => #{v} <<<<<" + + + _a = iterate(v, "#{path}.get(#{k})") + _a.each do |_e| + assertions << _e + end + else + Scoutui::Logger::LogMgr.instance.debug(__FILE__ + (__LINE__).to_s + " k is #{k}, value is #{v}") + assertions << "#{k} #{v}" + end + end + + # assertions << _list.flatten + if !_list.empty? + _list.each do |_e| + assertions << _e + end + end + + end + + else + Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " Huh?" + assertions << nil + end + + Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " assertions => #{assertions}" + assertions + + end end