Class: OnlyofficeWebdriverWrapper::HeadlessHelper
- Inherits:
-
Object
- Object
- OnlyofficeWebdriverWrapper::HeadlessHelper
- Includes:
- RealDisplayTools, RubyHelper
- Defined in:
- lib/onlyoffice_webdriver_wrapper/helpers/headless_helper.rb
Overview
Class for using headless gem
Instance Attribute Summary collapse
-
#headless_instance ⇒ Object
Returns the value of attribute headless_instance.
-
#resolution_x ⇒ Object
Returns the value of attribute resolution_x.
-
#resolution_y ⇒ Object
Returns the value of attribute resolution_y.
Instance Method Summary collapse
-
#initialize(resolution_x = 1680, resolution_y = 1050) ⇒ HeadlessHelper
constructor
A new instance of HeadlessHelper.
- #running? ⇒ Boolean
-
#should_start? ⇒ True, False
Check if should start headless.
- #start ⇒ Object
- #stop ⇒ Object
- #take_screenshot(scr_path = '/tmp/screenshot.png') ⇒ Object
Methods included from RubyHelper
Methods included from RealDisplayTools
#real_display_connected?, #xrandr_result
Constructor Details
#initialize(resolution_x = 1680, resolution_y = 1050) ⇒ HeadlessHelper
Returns a new instance of HeadlessHelper.
14 15 16 17 |
# File 'lib/onlyoffice_webdriver_wrapper/helpers/headless_helper.rb', line 14 def initialize(resolution_x = 1680, resolution_y = 1050) @resolution_x = resolution_x @resolution_y = resolution_y end |
Instance Attribute Details
#headless_instance ⇒ Object
Returns the value of attribute headless_instance.
10 11 12 |
# File 'lib/onlyoffice_webdriver_wrapper/helpers/headless_helper.rb', line 10 def headless_instance @headless_instance end |
#resolution_x ⇒ Object
Returns the value of attribute resolution_x.
11 12 13 |
# File 'lib/onlyoffice_webdriver_wrapper/helpers/headless_helper.rb', line 11 def resolution_x @resolution_x end |
#resolution_y ⇒ Object
Returns the value of attribute resolution_y.
12 13 14 |
# File 'lib/onlyoffice_webdriver_wrapper/helpers/headless_helper.rb', line 12 def resolution_y @resolution_y end |
Instance Method Details
#running? ⇒ Boolean
58 59 60 |
# File 'lib/onlyoffice_webdriver_wrapper/helpers/headless_helper.rb', line 58 def running? !headless_instance.nil? end |
#should_start? ⇒ True, False
Check if should start headless
21 22 23 24 25 26 |
# File 'lib/onlyoffice_webdriver_wrapper/helpers/headless_helper.rb', line 21 def should_start? return false if debug? return false if OSHelper.mac? true end |
#start ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/onlyoffice_webdriver_wrapper/helpers/headless_helper.rb', line 28 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") rescue Exception => e OnlyofficeLoggerHelper.log("xvfb not started with problem #{e}") RspecHelper.clean_up(true) @headless_instance = Headless.new(reuse: false, destroy_at_exit: true, dimensions: "#{@resolution_x + 1}x#{@resolution_y + 1}x24") end headless_instance.start end |
#stop ⇒ Object
51 52 53 54 55 56 |
# File 'lib/onlyoffice_webdriver_wrapper/helpers/headless_helper.rb', line 51 def stop return unless running? OnlyofficeLoggerHelper.log('Stopping Headless Session') headless_instance.destroy end |
#take_screenshot(scr_path = '/tmp/screenshot.png') ⇒ Object
62 63 64 65 66 67 |
# File 'lib/onlyoffice_webdriver_wrapper/helpers/headless_helper.rb', line 62 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 |