 |
Forums |
Admin Discussion Forums: help Start New Thread
By: Matthew Bretherton
RE: How to download a binary file in Celerity [ reply ] 2011-11-29 07:30
|
I ran into a similar sort of problem when accessing JSON responses . . .
The response you have looks grim and it would be great if you could splice pageHandlers into the mic on the fly.
But I expect you are so conecrned about system archectecture and need to get your tests working. So here are some hints
First the UnexpectedPageException is not terminal - it just means you will not have access to all the Watir functions and DOm obejcts in the page . . . but you won't need them to handle an image
below is untested code . . . reefed from my archives and assembled in this message. Please excuse any ruby errors
First handle the Exception
begin
browser.button(:name, 'button1').click
rescue UnexpectedPageException
end
Now get the data out of the browser
image_data = browser.io.read
But maybe you don;t want it in memory and can use the io to serialize more conveniently
That should work. The io seemed the lowest level way of extracting data, bypassing all Celerity or HTMLunit interpretation. This even worked to extract possibly broken xml
In this maner, we handled the json calls and testing the Citysearch site these became very reliable. To simplify the code I overloaded the Celerity.Browser::Page method, and removed the exception so that the ruby code remained free of exception handling . . .
Hope this helps
Matthew
|
By: Julian Tree
How to download a binary file in Celerity [ reply ] 2011-10-15 19:49
|
The web page submits a form and return a application/binary file in return.
I get this error in Celerity. Is there a way to just download the file and save to a location?
browser.button(:name, 'button1').click
Celerity::Exception::UnexpectedPageException: application/binary
page= at /Library/Frameworks/JRuby.framework/Gems/1.8/gems/celerity-0.9.0/lib/celerity/browser.rb:753
enable_event_listener at /Library/Frameworks/JRuby.framework/Gems/1.8/gems/celerity-0.9.0/lib/celerity/browser.rb:789
call at org/jruby/RubyProc.java:274
call at org/jruby/RubyProc.java:229
webWindowClosed at /Library/Frameworks/JRuby.framework/Gems/1.8/gems/celerity-0.9.0/lib/celerity/listener.rb:120
each at org/jruby/RubyArray.java:1603
webWindowClosed at /Library/Frameworks/JRuby.framework/Gems/1.8/gems/celerity-0.9.0/lib/celerity/listener.rb:120
click at /Library/Frameworks/JRuby.framework/Gems/1.8/gems/celerity-0.9.0/lib/celerity/clickable_element.rb:10
rescue_status_code_exception at /Library/Frameworks/JRuby.framework/Gems/1.8/gems/celerity-0.9.0/lib/celerity/container.rb:796
click at /Library/Frameworks/JRuby.framework/Gems/1.8/gems/celerity-0.9.0/lib/celerity/clickable_element.rb:10
(root) at tmp/sagepf.rb:28
|
|
 |