From 7fb303d5b2545b9f37b19c499569bbda2b549d91 Mon Sep 17 00:00:00 2001 From: Jonathan Bryan Date: Mon, 18 Feb 2013 22:40:34 -0500 Subject: [PATCH] Was getting this error in Ruby 1.9.3-p327 'cannot load such file -- jcode'. Also fixing a unicode issue for 1.9. Still getting an error though... --- .../core/navigation/agents/firewatir.rb | 54 +++++++++---------- lib/scrubyt/utils/simple_example_lookup.rb | 2 +- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/lib/scrubyt/core/navigation/agents/firewatir.rb b/lib/scrubyt/core/navigation/agents/firewatir.rb index d421bd3..054daa9 100644 --- a/lib/scrubyt/core/navigation/agents/firewatir.rb +++ b/lib/scrubyt/core/navigation/agents/firewatir.rb @@ -49,7 +49,7 @@ def self.fetch(doc_url, *args) handle_relative_url(doc_url, resolve) Scrubyt.log :ACTION, "fetching document: #{@@current_doc_url}" case @@current_doc_protocol - when 'file': @@agent.goto("file://"+ @@current_doc_url) + when 'file' then @@agent.goto("file://"+ @@current_doc_url) else @@agent.goto(@@current_doc_url) end @@mechanize_doc = "#{@@agent.html}" @@ -59,12 +59,12 @@ def self.fetch(doc_url, *args) @@hpricot_doc = Hpricot(PreFilterDocument.br_to_newline(@@mechanize_doc)) store_host_name(@@agent.url) # in case we're on a new host end - + def self.use_current_page @@mechanize_doc = "#{@@agent.html}" @@hpricot_doc = Hpricot(PreFilterDocument.br_to_newline(@@mechanize_doc)) end - + def self.frame(attribute, value) if @@current_frame @@current_frame.frame(attribute, value) @@ -78,14 +78,14 @@ def self.frame(attribute, value) def self.submit(current_form, sleep_time=nil, button=nil, type=nil) if @@current_frame #BRUTAL hax but FW is such a shitty piece of software - #this sucks FAIL omg + #this sucks FAIL omg @@current_frame.locate form = Document.new(@@current_frame).all.find{|t| t.tagName=="FORM"} form.submit else @@agent.element_by_xpath(@@current_form).submit - end - + end + if sleep_time sleep sleep_time @@agent.wait @@ -101,56 +101,56 @@ def self.submit(current_form, sleep_time=nil, button=nil, type=nil) def self.click_link(link_spec,index = 0,wait_secs=0) Scrubyt.log :ACTION, "Clicking link specified by: %p" % link_spec if link_spec.is_a?(Hash) - elem = XPathUtils.generate_XPath(CompoundExampleLookup.find_node_from_compund_example(@@hpricot_doc, link_spec, false, index), nil, true) + elem = XPathUtils.generate_XPath(CompoundExampleLookup.find_node_from_compund_example(@@hpricot_doc, link_spec, false, index), nil, true) result_page = @@agent.element_by_xpath(elem).click else @@agent.link(:innerHTML, Regexp.escape(link_spec)).click - end + end sleep(wait_secs) if wait_secs > 0 @@agent.wait - + # evaluate the results extractor.evaluate_extractor - + @@current_doc_url = @@agent.url @@mechanize_doc = "#{@@agent.html}" @@hpricot_doc = Hpricot(PreFilterDocument.br_to_newline(@@mechanize_doc)) Scrubyt.log :ACTION, "Fetching #{@@current_doc_url}" - end - + end + def self.click_by_xpath_if_exists(xpath, wait_secs=0) begin result_page = @@agent.element_by_xpath(xpath).click sleep(wait_secs) if wait_secs > 0 @@agent.wait - + extractor.evaluate_extractor - + @@current_doc_url = @@agent.url @@mechanize_doc = "#{@@agent.html}" @@hpricot_doc = Hpricot(PreFilterDocument.br_to_newline(@@mechanize_doc)) - Scrubyt.log :ACTION, "Fetching #{@@current_doc_url}" + Scrubyt.log :ACTION, "Fetching #{@@current_doc_url}" rescue Watir::Exception::UnknownObjectException Scrubyt.log :INFO, "XPath #{xpath} doesn't exist in this document" end - end + end def self.click_by_xpath(xpath, wait_secs=0) - Scrubyt.log :ACTION, "Clicking by XPath : %p" % xpath + Scrubyt.log :ACTION, "Clicking by XPath : %p" % xpath @@agent.element_by_xpath(xpath).click Scrubyt.log :INFO, "sleeping #{wait_secs}..." sleep(wait_secs) if wait_secs > 0 @@agent.wait - + # evaluate the results extractor.evaluate_extractor - + @@current_doc_url = @@agent.url @@mechanize_doc = "#{@@agent.html}" @@hpricot_doc = Hpricot(PreFilterDocument.br_to_newline(@@mechanize_doc)) - Scrubyt.log :ACTION, "Fetching #{@@current_doc_url}" + Scrubyt.log :ACTION, "Fetching #{@@current_doc_url}" end - + def self.click_image_map(index = 0) Scrubyt.log :ACTION, "Clicking image map at index: %p" % index uri = @@mechanize_doc.search("//area")[index]['href'] @@ -227,19 +227,19 @@ def self.handle_relative_url(doc_url, resolve) @@current_doc_url = resolve + doc_url end end - + def self.fill_textfield(textfield_name, query_string, wait_secs, useValue) @@current_form = "//input[@name='#{textfield_name}']/ancestor::form" target = @@current_frame || @@agent if useValue - target.text_field(:name,textfield_name).value = query_string + target.text_field(:name,textfield_name).value = query_string else target.text_field(:name,textfield_name).set(query_string) end sleep(wait_secs) if wait_secs > 0 @@mechanize_doc = "#{@@agent.html}" @@hpricot_doc = Hpricot(PreFilterDocument.br_to_newline(@@mechanize_doc)) - + end ## @@ -269,17 +269,17 @@ def self.check_radiobutton(checkbox_name, index=0) def self.click_image_map(index=0) raise 'NotImplemented' end - + def self.wait(time=1) sleep(time) @@agent.wait end - + def self.close_firefox @@agent.close end end - end + end end end end diff --git a/lib/scrubyt/utils/simple_example_lookup.rb b/lib/scrubyt/utils/simple_example_lookup.rb index f36990d..e8035bf 100644 --- a/lib/scrubyt/utils/simple_example_lookup.rb +++ b/lib/scrubyt/utils/simple_example_lookup.rb @@ -15,7 +15,7 @@ class SimpleExampleLookup # #In this case, 's text is considered to be "Bon nuit, monsieur" def self.find_node_from_text(doc, text, next_link=false, index = 0) - text.gsub!('ยป', '»') + text.gsub!("\u00BB", '»') #Process immediate attribute extraction (like "go to google.com/@href") if text =~ /.+\/@.+$/ text = text.scan(/^(.+?)\/@.+$/)[0][0]