Skip to content

Commit 720be7c

Browse files
fix: allow passing extra options to Selenium::WebDriver (#431)
No QA required. --------- Co-authored-by: Stéphane Maniaci <stephane.maniaci@gmail.com>
1 parent 7eca494 commit 720be7c

File tree

4 files changed

+31
-11
lines changed

4 files changed

+31
-11
lines changed

.circleci/config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ defaults: &defaults
77
resource_class: large
88

99
orbs:
10-
browser-tools: circleci/browser-tools@1.5.3
11-
node: circleci/node@5.0.3
10+
browser-tools: circleci/browser-tools@1.5.2
11+
node: circleci/node@5.0.0
1212

1313
commands:
1414
bootstrap:

packages/axe-core-selenium/README.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,34 @@ require 'axe-selenium'
2020
# configure `AxeSelenium`
2121

2222
driver = AxeSelenium.configure(:firefox) do |c|
23-
# see below for a full list of configuration
23+
# see below for a full list of configuration
2424
c.jslib_path = "next-version/axe.js"
2525
end
2626

2727
# use the driver configuration instance
2828
driver.page.navigate.to 'https://www.deque.com/'
2929
```
3030

31-
### API
31+
Custom options can be passed to the underlying driver:
32+
33+
```rb
34+
require 'axe-selenium'
35+
36+
options = Selenium::WebDriver::Options.firefox
37+
options.args << '-headless'
38+
39+
driver = AxeSelenium.configure(:firefox, options) {}
40+
```
41+
42+
### API
3243

3344
#### `AxeSelenium.configure`
3445

3546
The configure method takes 1 optional argument as a [symbol][] and a configuration block object: `configure(*arg, &block)`
3647

3748
The optional argument is a browser name for `selenium-webdriver`. The valid browser names are:
3849
- `:firefox` (default)
39-
- `:chrome`
50+
- `:chrome`
4051
- `:safari`
4152

4253
> Note: Please ensure respective drivers (eg: [`geckodriver`][]) are installed in your machine.
@@ -67,4 +78,4 @@ bundle exec rspec
6778
[axe API]: https://github.com/dequelabs/axe-core/blob/develop/doc/API.md
6879
[Selenium Webdriver]: https://rubygems.org/gems/selenium-webdriver
6980
[`geckodriver`]: https://github.com/mozilla/geckodriver/releases
70-
[symbol]: https://ruby-doc.org/core-2.5.0/Symbol.html
81+
[symbol]: https://ruby-doc.org/core-2.5.0/Symbol.html

packages/axe-core-selenium/lib/axe-selenium.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@
44
module AxeSelenium
55
# configure method
66
# - which takes an optional argument browser
7+
# - an optional options (sic) object to configure the underlying driver
78
# - and a configuration block optional for Axe
8-
def self.configure(browser = :firefox)
9-
# instantiate axe configuration (singleton) with defaults or given config
9+
def self.configure(browser = :firefox, opts = nil)
10+
# instantiate axe configuration (singleton) with defaults or given config: opts
1011
if !block_given?
1112
raise Exception.new "Please provide a configure block for AxeSelenium"
1213
end
1314

1415
config = Axe::Configuration.instance
1516

1617
# provide a selenium webdriver page object
17-
config.page = get_driver(browser)
18+
config.page = get_driver(browser, opts)
1819

1920
# await and return
2021
yield config
@@ -23,7 +24,7 @@ def self.configure(browser = :firefox)
2324

2425
private
2526

26-
def self.get_driver(browserSymbol)
27-
Selenium::WebDriver.for browserSymbol
27+
def self.get_driver(browserSymbol, opts)
28+
Selenium::WebDriver.for browserSymbol, options: opts
2829
end
2930
end

packages/axe-core-selenium/spec/axe-selenium_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@
1717
expect(driver).to respond_to :jslib
1818
expect(driver.jslib).to include("axe.run=") # has axe injected
1919
end
20+
21+
it "gets passed configuration options" do
22+
options = Selenium::WebDriver::Options.firefox
23+
options.args << '-headless'
24+
expect(Selenium::WebDriver).to receive(:for).with(:firefox, {options: options})
25+
driver = AxeSelenium.configure(:firefox, options) do
26+
end
27+
end
2028
end
2129

2230
describe "#configure" do

0 commit comments

Comments
 (0)