Skip to content

Commit a2a7634

Browse files
franzliedkep0deje
authored andcommitted
Add shortcut for enabling Firefox' headless mode
Signed-off-by: Alex Rodionov <[email protected]>
1 parent ade027b commit a2a7634

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

rb/lib/selenium/webdriver/firefox/options.rb

+12
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,18 @@ def add_preference(name, value)
9393
prefs[name] = value
9494
end
9595

96+
#
97+
# Run Firefox in headless mode.
98+
#
99+
# @example Enable headless mode
100+
# options = Selenium::WebDriver::Firefox::Options.new
101+
# options.headless!
102+
#
103+
104+
def headless!
105+
add_argument '-headless'
106+
end
107+
96108
#
97109
# Sets Firefox profile.
98110
#

rb/spec/unit/selenium/webdriver/firefox/options_spec.rb

+7
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ module Firefox
7575
end
7676
end
7777

78+
describe '#headless!' do
79+
it 'adds the -headless command-line flag' do
80+
subject.headless!
81+
expect(subject.as_json['moz:firefoxOptions'][:args]).to include('-headless')
82+
end
83+
end
84+
7885
describe '#add_argument' do
7986
it 'adds a command-line argument' do
8087
subject.add_argument('foo')

0 commit comments

Comments
 (0)