Module: CucumberScreenshot::World
- Defined in:
- lib/cucumber_screenshot/world.rb
Instance Attribute Summary collapse
-
#current_feature_segment ⇒ Object
Returns the value of attribute current_feature_segment.
-
#current_scenario_segment ⇒ Object
Returns the value of attribute current_scenario_segment.
-
#response_body_for_last_screenshot ⇒ Object
Returns the value of attribute response_body_for_last_screenshot.
-
#screenshot_directory ⇒ Object
Returns the value of attribute screenshot_directory.
-
#screenshot_index ⇒ Object
Returns the value of attribute screenshot_index.
Instance Method Summary collapse
- #base_screenshot_directory_name ⇒ Object
- #screenshot(directory_name = base_screenshot_directory_name, file_name = "screenshot-#{(Time.now.to_f * 100).to_i}") ⇒ Object
- #screenshot_due? ⇒ Boolean
Instance Attribute Details
#current_feature_segment ⇒ Object
Returns the value of attribute current_feature_segment.
4 5 6 |
# File 'lib/cucumber_screenshot/world.rb', line 4 def current_feature_segment @current_feature_segment end |
#current_scenario_segment ⇒ Object
Returns the value of attribute current_scenario_segment.
4 5 6 |
# File 'lib/cucumber_screenshot/world.rb', line 4 def current_scenario_segment @current_scenario_segment end |
#response_body_for_last_screenshot ⇒ Object
Returns the value of attribute response_body_for_last_screenshot.
4 5 6 |
# File 'lib/cucumber_screenshot/world.rb', line 4 def response_body_for_last_screenshot @response_body_for_last_screenshot end |
#screenshot_directory ⇒ Object
Returns the value of attribute screenshot_directory.
4 5 6 |
# File 'lib/cucumber_screenshot/world.rb', line 4 def screenshot_directory @screenshot_directory end |
#screenshot_index ⇒ Object
Returns the value of attribute screenshot_index.
4 5 6 |
# File 'lib/cucumber_screenshot/world.rb', line 4 def screenshot_index @screenshot_index end |
Instance Method Details
#base_screenshot_directory_name ⇒ Object
6 7 8 9 10 |
# File 'lib/cucumber_screenshot/world.rb', line 6 def base_screenshot_directory_name # TODO: Make this configurable # TODO: Make this work for other frameworks e.g. sinatra "#{RAILS_ROOT}/features/screenshots" end |
#screenshot(directory_name = base_screenshot_directory_name, file_name = "screenshot-#{(Time.now.to_f * 100).to_i}") ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/cucumber_screenshot/world.rb', line 12 def screenshot(directory_name = base_screenshot_directory_name, file_name = "screenshot-#{(Time.now.to_f * 100).to_i}") if current_response_body FileUtils.mkdir_p("#{directory_name}/html") html_file_name = "#{directory_name}/html/#{file_name}.html" File.open(html_file_name, "w") do |f| f.write rewrite_local_urls(current_response_body) end if CucumberScreenshot.snap_url_present? command = "snapurl file://#{html_file_name} --no-thumbnail --no-clip --filename #{file_name} --output-dir #{directory_name}" `#{command}` if $? == 0 "#{directory_name}/#{file_name}.png", 'image/png' self.response_body_for_last_screenshot = current_response_body true else report_error_running_screenshot_command(command) false end else self.response_body_for_last_screenshot = current_response_body true end end end |
#screenshot_due? ⇒ Boolean
39 40 41 |
# File 'lib/cucumber_screenshot/world.rb', line 39 def screenshot_due? current_response_body && current_response_body != response_body_for_last_screenshot && !webrat_session.redirect? end |