Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extracted save_and_open_page related functionality to a module and in…
…cluded it in SeleniumSession as well as the standard webrat session. Also added save_and_open_screengrab method to SeleniumSession.
- Loading branch information
Showing
5 changed files
with
74 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
module Webrat | ||
module SaveAndOpenPage | ||
# Saves the page out to RAILS_ROOT/tmp/ and opens it in the default | ||
# web browser if on OS X. Useful for debugging. | ||
# | ||
# Example: | ||
# save_and_open_page | ||
def save_and_open_page | ||
return unless File.exist?(saved_page_dir) | ||
|
||
filename = "#{saved_page_dir}/webrat-#{Time.now.to_i}.html" | ||
|
||
File.open(filename, "w") do |f| | ||
f.write rewrite_css_and_image_references(response_body) | ||
end | ||
|
||
open_in_browser(filename) | ||
end | ||
|
||
def open_in_browser(path) # :nodoc | ||
platform = ruby_platform | ||
if platform =~ /cygwin/ || platform =~ /win32/ | ||
`rundll32 url.dll,FileProtocolHandler #{path.gsub("/", "\\\\")}` | ||
elsif platform =~ /darwin/ | ||
`open #{path}` | ||
end | ||
end | ||
|
||
def rewrite_css_and_image_references(response_html) # :nodoc: | ||
return response_html unless doc_root | ||
response_html.gsub(/"\/(stylesheets|images)/, doc_root + '/\1') | ||
end | ||
|
||
def saved_page_dir #:nodoc: | ||
File.expand_path(".") | ||
end | ||
|
||
def doc_root #:nodoc: | ||
nil | ||
end | ||
|
||
private | ||
|
||
# accessor for testing | ||
def ruby_platform | ||
RUBY_PLATFORM | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7d63aa1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome, thanks for adding it! I was just wishing for something just like this today…
7d63aa1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No prob, I have this crazy idea of being able to make a little movie from a story, perhaps with the story text as subtitles…