headless 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/CHANGELOG +3 -0
  2. data/README.md +1 -0
  3. data/lib/headless.rb +20 -10
  4. metadata +5 -4
data/CHANGELOG ADDED
@@ -0,0 +1,3 @@
1
+ ## 0.1.0
2
+ * introduced options
3
+ * make it possible to change virtual screen dimensions and pixel depth
data/README.md CHANGED
@@ -3,6 +3,7 @@
3
3
  Headless is a Ruby interface for Xvfb. It allows you to create a headless display straight from Ruby code, hiding some low-level action.
4
4
 
5
5
  I created it so I can run Selenium tests in Cucumber without any shell scripting. Even more, you can go headless only when you run tests against Selenium.
6
+ Other possible uses include pdf generation with `wkhtmltopdf`, or screenshotting.
6
7
 
7
8
  ## Installation
8
9
 
data/lib/headless.rb CHANGED
@@ -35,8 +35,6 @@
35
35
  # headless.destroy
36
36
  #--
37
37
  # TODO test that reuse actually works with an existing xvfb session
38
- # TODO maybe write a command-line wrapper like
39
- # headlessly firefox
40
38
  #++
41
39
  class Headless
42
40
 
@@ -46,20 +44,27 @@ class Headless
46
44
  # The display number
47
45
  attr_reader :display
48
46
 
49
- # Creates a new headless server, but NOT switches to it immediately. Call #start for that
47
+ # The display dimensions
48
+ attr_reader :dimensions
49
+
50
+ # Creates a new headless server, but does NOT switch to it immediately. Call #start for that
51
+ #
52
+ # List of available options:
53
+ # * +display+ (default 99) - what display number to listen to;
54
+ # * +reuse+ (default true) - if given display server already exists, should we use it or fail miserably?
55
+ # * +dimensions+ (default 1280x1024x24) - display dimensions and depth. Not all combinations are possible, refer to +man Xvfb+.
50
56
  def initialize(options = {})
51
- @xvfb = `which Xvfb`.strip
52
- raise Exception.new('Xvfb not found on your system') if @xvfb == ''
57
+ find_xvfb
53
58
 
54
- # TODO more options, like display dimensions and depth; set up default dimensions and depth
55
59
  @display = options.fetch(:display, 99).to_i
56
60
  @reuse_display = options.fetch(:reuse, true)
61
+ @dimensions = options.fetch(:dimensions, '1280x1024x24')
57
62
 
58
63
  #TODO more logic here, autopicking the display number
59
64
  if @reuse_display
60
65
  launch_xvfb unless read_pid
61
66
  elsif read_pid
62
- raise Exception.neW("Display :#{display} is already taken and reuse=false")
67
+ raise Exception.new("Display :#{display} is already taken and reuse=false")
63
68
  else
64
69
  launch_xvfb
65
70
  end
@@ -89,8 +94,7 @@ class Headless
89
94
  # Headless.run do
90
95
  # # perform operations in headless mode
91
96
  # end
92
- #
93
- # Alias: #ly (Headless.ly)
97
+ # See #new for options
94
98
  def self.run(options={}, &block)
95
99
  headless = Headless.new(options)
96
100
  headless.start
@@ -103,8 +107,14 @@ class Headless
103
107
  private
104
108
  attr_reader :xvfb_pid
105
109
 
110
+ def find_xvfb
111
+ @xvfb = `which Xvfb`.strip
112
+ raise Exception.new('Xvfb not found on your system') if @xvfb == ''
113
+ end
114
+
106
115
  def launch_xvfb
107
- system "#{@xvfb} :#{display} -ac >/dev/null 2>&1 &"
116
+ #TODO error reporting
117
+ system "#{@xvfb} :#{display} -screen 0 #{dimensions} -ac >/dev/null 2>&1 &"
108
118
  sleep 1
109
119
  end
110
120
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: headless
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 0
9
8
  - 1
10
- version: 0.0.1
9
+ - 0
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Leonid Shevtsov
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-06 00:00:00 +03:00
18
+ date: 2010-08-16 00:00:00 +03:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -29,6 +29,7 @@ extra_rdoc_files: []
29
29
 
30
30
  files:
31
31
  - lib/headless.rb
32
+ - CHANGELOG
32
33
  - README.md
33
34
  - LICENSE
34
35
  has_rdoc: true