lib/red-glass/red_glass.rb in red-glass-0.1.1 vs lib/red-glass/red_glass.rb in red-glass-0.1.2

- old
+ new

@@ -42,10 +42,11 @@ def take_snapshot capture_page_metadata create_page_archive_directory take_screenshot capture_page_source + load_js serialize_dom write_metadata end private @@ -79,45 +80,23 @@ @port = @opts[:red_glass_port].nil? ? '4567' : @opts[:red_glass_port].to_s ENV['red_glass_port'] = @port end def load_js - load_jQuery - load_json2 - load_get_path - load_red_glass_js + load_red_glass_carryall unless has_red_glass_js? end - def load_jQuery - has_jQuery = @driver.execute_script "var hasJQuery = typeof jQuery == 'function' ? true : false; return hasJQuery" - raw_js = File.open(File.expand_path("#{PROJ_ROOT}/red-glass-app/public/scripts/jquery-1.8.0.min.js"), 'rb').read - @driver.execute_script raw_js if !has_jQuery - end - - def load_json2 - has_old_json = @driver.execute_script "var hasOldJSON = typeof JSON.license == 'undefined' ? false : true; return hasOldJSON" - @driver.execute_script "delete JSON" if has_old_json - raw_js = File.open(File.expand_path("#{PROJ_ROOT}/red-glass-js/json2.js"), 'rb').read + def load_red_glass_carryall + raw_js = File.open(File.expand_path("#{PROJ_ROOT}/red-glass-js/redglass.carryall.js"), 'rb').read @driver.execute_script raw_js + @driver.execute_script("jQuery(document).redGlass('#{@test_id}', '#{@port}')") end - def load_get_path - raw_js = File.open(File.expand_path("#{PROJ_ROOT}/red-glass-js/jquery.getpath.js"), 'rb').read - @driver.execute_script raw_js - end - def has_red_glass_js? - @driver.execute_script "var hasRedGlass = typeof jQuery().redGlass == 'function' ? true : false; return hasRedGlass" + @driver.execute_script "var hasRedGlass = (typeof jQuery == 'function' && typeof jQuery().redGlass == 'function') ? true : false; return hasRedGlass" end - def load_red_glass_js - raw_js = File.open(File.expand_path("#{PROJ_ROOT}/red-glass-js/jquery.red-glass-0.1.0.js"), 'rb').read - @driver.execute_script raw_js if !has_red_glass_js? - @driver.execute_script("jQuery(document).redGlass('#{@test_id}', '#{@port}')") - #@driver.execute_script "jQuery.noConflict(true)" - end - def create_page_archive_directory detect_archive_location unless @archive_dir @archive_dir = "#{@opts[:archive_location].chomp('/')}/#{@test_id}" Dir::mkdir @archive_dir unless File.directory? @archive_dir @@ -163,13 +142,13 @@ def serialize_dom dom_json_string = "{\n\t\"browser\":" + "\"" + @page_metadata[:browser][:name] + "\"," dom_json_string += "\n\t\"elements\":\n\t[\n\t" serialize_dom_js_string = stringify_serialize_dom_js - dom_json_string += @driver.execute_script(serialize_dom_js_string + " return RecurseDomJSON(domgun.query('*'),'')") + dom_json_string += @driver.execute_script(serialize_dom_js_string + " return RecurseDomJSON(rgUtils.query('*'),'')") dom_json_string = dom_json_string[0, (dom_json_string.length - 3)] + "\n\t]\n}" - @page_metadata[:doc_width] = @driver.execute_script(serialize_dom_js_string + " return domgun.query(document).width()") - @page_metadata[:doc_height] = @driver.execute_script(serialize_dom_js_string + " return domgun.query(document).height()") + @page_metadata[:doc_width] = @driver.execute_script(serialize_dom_js_string + " return rgUtils.query(document).width()") + @page_metadata[:doc_height] = @driver.execute_script(serialize_dom_js_string + " return rgUtils.query(document).height()") write_serialized_dom dom_json_string end def stringify_serialize_dom_js domgun_recurse_dom_file = File.open("#{PROJ_ROOT}/red-glass-js/serialize-dom.js", 'rb') \ No newline at end of file