Class: OnlyofficeWebdriverWrapper::HeadlessHelper
- Inherits:
-
Object
- Object
- OnlyofficeWebdriverWrapper::HeadlessHelper
- Includes:
- HeadlessVideoRecorder, RealDisplayTools, RubyHelper
- Defined in:
- lib/onlyoffice_webdriver_wrapper/helpers/headless_helper.rb
Overview
Class for using headless gem
Instance Attribute Summary collapse
-
#headless_instance ⇒ Headless
Instance of headless object.
-
#record_video ⇒ True, False
readonly
Is video should be recorded.
-
#resolution_x ⇒ Integer
X resolution of virtual screen.
-
#resolution_y ⇒ Integer
Y resolution of virtual screen.
Instance Method Summary collapse
-
#initialize(resolution_x: 1680, resolution_y: 1050, record_video: true) ⇒ HeadlessHelper
constructor
A new instance of HeadlessHelper.
-
#running? ⇒ Boolean
Check if headless session currently running.
-
#should_start? ⇒ True, False
Check if should start headless.
-
#start ⇒ void
Start headless session.
-
#stop ⇒ void
Stop current headless session.
-
#take_screenshot(scr_path = '/tmp/screenshot.png') ⇒ void
Take a screenshot of current headless session.
Methods included from RubyHelper
Methods included from RealDisplayTools
#real_display_connected?, #xrandr_result
Methods included from HeadlessVideoRecorder
#recorded_video_file, #start_capture, #stop_capture
Constructor Details
#initialize(resolution_x: 1680, resolution_y: 1050, record_video: true) ⇒ HeadlessHelper
Returns a new instance of HeadlessHelper.
24 25 26 27 28 29 30 |
# File 'lib/onlyoffice_webdriver_wrapper/helpers/headless_helper.rb', line 24 def initialize(resolution_x: 1680, resolution_y: 1050, record_video: true) @resolution_x = resolution_x @resolution_y = resolution_y @record_video = record_video end |
Instance Attribute Details
#headless_instance ⇒ Headless
Returns instance of headless object.
16 17 18 |
# File 'lib/onlyoffice_webdriver_wrapper/helpers/headless_helper.rb', line 16 def headless_instance @headless_instance end |
#record_video ⇒ True, False (readonly)
Returns is video should be recorded.
22 23 24 |
# File 'lib/onlyoffice_webdriver_wrapper/helpers/headless_helper.rb', line 22 def record_video @record_video end |
#resolution_x ⇒ Integer
Returns x resolution of virtual screen.
18 19 20 |
# File 'lib/onlyoffice_webdriver_wrapper/helpers/headless_helper.rb', line 18 def resolution_x @resolution_x end |
#resolution_y ⇒ Integer
Returns y resolution of virtual screen.
20 21 22 |
# File 'lib/onlyoffice_webdriver_wrapper/helpers/headless_helper.rb', line 20 def resolution_y @resolution_y end |
Instance Method Details
#running? ⇒ Boolean
Check if headless session currently running
81 82 83 |
# File 'lib/onlyoffice_webdriver_wrapper/helpers/headless_helper.rb', line 81 def running? !headless_instance.nil? end |
#should_start? ⇒ True, False
Check if should start headless
34 35 36 37 38 39 |
# File 'lib/onlyoffice_webdriver_wrapper/helpers/headless_helper.rb', line 34 def should_start? return false if debug? return false if OSHelper.mac? true end |
#start ⇒ void
This method returns an undefined value.
Start headless session
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/onlyoffice_webdriver_wrapper/helpers/headless_helper.rb', line 43 def start create_session = if real_display_connected? should_start? else true end return unless create_session OnlyofficeLoggerHelper.log('Starting Headless Session') begin @headless_instance = Headless.new(reuse: false, destroy_at_exit: true, dimensions: "#{@resolution_x + 1}x#{@resolution_y + 1}x24", video: { provider: :ffmpeg }) rescue StandardError => e OnlyofficeLoggerHelper.log("xvfb not started with problem #{e}") WebDriver.clean_up(true) @headless_instance = Headless.new(reuse: false, destroy_at_exit: true, dimensions: "#{@resolution_x + 1}x#{@resolution_y + 1}x24", video: { provider: :ffmpeg }) end headless_instance.start start_capture end |
#stop ⇒ void
This method returns an undefined value.
Stop current headless session
71 72 73 74 75 76 77 |
# File 'lib/onlyoffice_webdriver_wrapper/helpers/headless_helper.rb', line 71 def stop return unless running? OnlyofficeLoggerHelper.log('Stopping Headless Session') stop_capture headless_instance.destroy end |
#take_screenshot(scr_path = '/tmp/screenshot.png') ⇒ void
This method returns an undefined value.
Take a screenshot of current headless session
88 89 90 91 92 93 |
# File 'lib/onlyoffice_webdriver_wrapper/helpers/headless_helper.rb', line 88 def take_screenshot(scr_path = '/tmp/screenshot.png') return unless running? headless_instance.take_screenshot(scr_path) OnlyofficeLoggerHelper.log("Took Screenshot to file: #{scr_path}") end |