Skip to content

Commit

Permalink
fix: allow passing extra options to Selenium::WebDriver
Browse files Browse the repository at this point in the history
Some environments like Docker require special options (-headless for
example) which is impossible to specify in the current setup. Add an
ommitable `opts` parameter for it.
  • Loading branch information
freesteph committed Jan 9, 2025
1 parent 5294583 commit 703ee19
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
19 changes: 15 additions & 4 deletions packages/axe-core-selenium/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,34 @@ require 'axe-selenium'
# configure `AxeSelenium`

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

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

### API
Custom options can be passed to the underlying driver:

```rb
require 'axe-selenium'

options = Selenium::WebDriver::Options.firefox
options.args << '-headless'

driver = AxeSelenium.configure(:firefox, options) {}
```

### API

#### `AxeSelenium.configure`

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

The optional argument is a browser name for `selenium-webdriver`. The valid browser names are:
- `:firefox` (default)
- `:chrome`
- `:chrome`
- `:safari`

> Note: Please ensure respective drivers (eg: [`geckodriver`][]) are installed in your machine.
Expand Down Expand Up @@ -67,4 +78,4 @@ bundle exec rspec
[axe API]: https://github.com/dequelabs/axe-core/blob/develop/doc/API.md
[Selenium Webdriver]: https://rubygems.org/gems/selenium-webdriver
[`geckodriver`]: https://github.com/mozilla/geckodriver/releases
[symbol]: https://ruby-doc.org/core-2.5.0/Symbol.html
[symbol]: https://ruby-doc.org/core-2.5.0/Symbol.html
9 changes: 5 additions & 4 deletions packages/axe-core-selenium/lib/axe-selenium.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
module AxeSelenium
# configure method
# - which takes an optional argument browser
# - an optional options (sic) object to configure the underlying driver
# - and a configuration block optional for Axe
def self.configure(browser = :firefox)
def self.configure(browser = :firefox, opts = {})
# instantiate axe configuration (singleton) with defaults or given config
if !block_given?
raise Exception.new "Please provide a configure block for AxeSelenium"
Expand All @@ -14,7 +15,7 @@ def self.configure(browser = :firefox)
config = Axe::Configuration.instance

# provide a selenium webdriver page object
config.page = get_driver(browser)
config.page = get_driver(browser, opts)

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

private

def self.get_driver(browserSymbol)
Selenium::WebDriver.for browserSymbol
def self.get_driver(browserSymbol, opts)
Selenium::WebDriver.for browserSymbol, options: opts
end
end

0 comments on commit 703ee19

Please sign in to comment.