Class Headless
In: lib/headless/video/video_recorder.rb
lib/headless/cli_util.rb
lib/headless.rb
Parent: Object

A class incapsulating the creation and usage of a headless X server

Prerequisites

  • X Window System
  • Xvfb

Usage

Block mode:

  require 'rubygems'
  require 'headless'
  require 'selenium-webdriver'

  Headless.ly do
    driver = Selenium::WebDriver.for :firefox
    driver.navigate.to 'http://google.com'
    puts driver.title
  end

Object mode:

  require 'rubygems'
  require 'headless'
  require 'selenium-webdriver'

  headless = Headless.new
  headless.start

  driver = Selenium::WebDriver.for :firefox
  driver.navigate.to 'http://google.com'
  puts driver.title

  headless.destroy

Methods

Classes and Modules

Class Headless::CliUtil
Class Headless::Exception
Class Headless::VideoRecorder

Constants

DEFAULT_DISPLAY_NUMBER = 99
MAX_DISPLAY_NUMBER = 10_000
DEFAULT_DISPLAY_DIMENSIONS = '1280x1024x24'
DEFAULT_XVFB_LAUNCH_TIMEOUT = 10

External Aliases

run -> ly

Attributes

dimensions  [R]  The display dimensions
display  [R]  The display number
xvfb_launch_timeout  [R] 

Public Class methods

Creates a new headless server, but does NOT switch to it immediately. Call start for that

List of available options:

  • display (default 99) - what display number to listen to;
  • reuse (default true) - if given display server already exists, should we use it or try another?
  • autopick (default true if display number isn‘t explicitly set) - if Headless should automatically pick a display, or fail if the given one is not available.
  • dimensions (default 1280x1024x24) - display dimensions and depth. Not all combinations are possible, refer to +man Xvfb+.
  • destroy_at_exit - if a display is started but not stopped, should it be destroyed when the script finishes? (default true unless reuse is true and a server is already running)
  • xvfb_launch_timeout - how long should we wait for Xvfb to open a display, before assuming that it is frozen (in seconds, default is 10)
  • video - options to be passed to the ffmpeg video recorder. See Headless::VideoRecorder#initialize for documentation

Block syntax:

  Headless.run do
    # perform operations in headless mode
  end

See new for options

Public Instance methods

Switches back from the headless server and terminates the headless session while waiting for Xvfb process to terminate.

Whether the headless display will be destroyed when the script finishes.

Deprecated. Same as destroy. Kept for backward compatibility in June 2015.

Same as the old destroy function — doesn‘t wait for Xvfb to die. Can cause zombies: stackoverflow.com/a/31003621/1651458

Switches to the headless server

Switches back from the headless server

[Validate]