lib/gatling/capture_element.rb in gatling-1.0.6 vs lib/gatling/capture_element.rb in gatling-1.0.7
- old
+ new
@@ -1,52 +1,31 @@
+require_relative 'image_wrangler'
+
module Gatling
class CaptureElement
- def initialize element_to_capture
+ def initialize element_to_capture, *element_to_exclude
@reference_image_path = Gatling::Configuration.reference_image_path
- @element = element_to_capture
+ @element_to_capture = element_to_capture
+ @element_to_exclude = element_to_exclude.first
+
end
def capture
- temp_dir = "#{@reference_image_path}/temp"
- begin
- FileUtils::mkdir_p(temp_dir)
- rescue
- puts "Could not create directory #{temp_dir}. Please make sure you have permission"
- end
+ screenshot = self.take_screenshot
+ screenshot = exclude(screenshot, @element_to_exclude) if @element_to_exclude
+ Gatling::ImageWrangler.crop_element(screenshot, @element_to_capture)
+ end
+ def take_screenshot
+ temp_dir = "#{@reference_image_path}/temp"
#captures the uncropped full screen
begin
-
Capybara.page.driver.browser.save_screenshot("#{temp_dir}/temp.png")
temp_screenshot = Magick::Image.read("#{temp_dir}/temp.png").first
rescue
raise "Could not save screenshot to #{temp_dir}. Please make sure you have permission"
end
end
-
- def crop
- element = @element.native
- location = element.location
- size = element.size
- @cropped_element = self.capture.crop(location.x, location.y, size.width, size.height)
- end
-
- def save_element(element, element_name, path)
- begin
- FileUtils::mkdir_p(path)
- rescue
- puts "Could not create directory #{path}. Please make sure you have permission"
- end
-
- begin
- element.write("#{path}/#{element_name}.png")
- element = "#{path}/#{element_name}.png"
- rescue
- raise "Could not save #{element_name} to #{path}. Please make sure you have permission"
- end
- end
-
-
end
end
\ No newline at end of file