Class: LookbookVisualTester::ScreenshotTaker
- Defined in:
- lib/lookbook_visual_tester/screenshot_taker.rb
Constant Summary collapse
- CLIPBOARD =
'clipboard'
Instance Attribute Summary collapse
-
#crop ⇒ Object
readonly
Returns the value of attribute crop.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#scenario_run ⇒ Object
readonly
Returns the value of attribute scenario_run.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(scenario_run:, path: nil, crop: true, logger: Rails.logger) ⇒ ScreenshotTaker
constructor
A new instance of ScreenshotTaker.
- #save_to_clipboard(path = @path) ⇒ Object
- #session ⇒ Object
Methods inherited from Service
Constructor Details
#initialize(scenario_run:, path: nil, crop: true, logger: Rails.logger) ⇒ ScreenshotTaker
Returns a new instance of ScreenshotTaker.
14 15 16 17 18 19 20 21 22 |
# File 'lib/lookbook_visual_tester/screenshot_taker.rb', line 14 def initialize(scenario_run:, path: nil, crop: true, logger: Rails.logger) @scenario_run = scenario_run @path = path || File.join(LookbookVisualTester.config.current_dir, scenario_run.filename) @crop = crop @logger = logger end |
Instance Attribute Details
#crop ⇒ Object (readonly)
Returns the value of attribute crop.
8 9 10 |
# File 'lib/lookbook_visual_tester/screenshot_taker.rb', line 8 def crop @crop end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
8 9 10 |
# File 'lib/lookbook_visual_tester/screenshot_taker.rb', line 8 def logger @logger end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
8 9 10 |
# File 'lib/lookbook_visual_tester/screenshot_taker.rb', line 8 def path @path end |
#scenario_run ⇒ Object (readonly)
Returns the value of attribute scenario_run.
8 9 10 |
# File 'lib/lookbook_visual_tester/screenshot_taker.rb', line 8 def scenario_run @scenario_run end |
Instance Method Details
#call ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/lookbook_visual_tester/screenshot_taker.rb', line 28 def call FileUtils.mkdir_p(File.dirname(path)) session.visit(preview_url) # Wait for network requests to complete # session.driver.network_idle? # # Wait for any loading indicators to disappear # begin # session.has_no_css?(".loading", wait: 10) # rescue StandardError # nil # end if path == CLIPBOARD print_and_save_to_clipboard else save_printscreen end # Additional wait for any JavaScript animations sleep 1 rescue StandardError => e logger.info "Error capturing screenshot for #{preview_url}: #{e.}" raise e end |
#save_to_clipboard(path = @path) ⇒ Object
54 55 56 |
# File 'lib/lookbook_visual_tester/screenshot_taker.rb', line 54 def save_to_clipboard(path = @path) system("xclip -selection clipboard -t image/png -i #{path}") end |
#session ⇒ Object
24 25 26 |
# File 'lib/lookbook_visual_tester/screenshot_taker.rb', line 24 def session @session ||= SessionManager.instance.session end |