Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(capybara): respect browser choice #307

Merged
merged 2 commits into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions packages/axe-core-capybara/lib/axe-capybara.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ def self.configure(browser = :firefox)

config = Axe::Configuration.instance

# provide a capybara webdriver page object
config.page = get_driver(browser)
config.page = set_driver(browser)

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

private

def self.get_driver(browserSymbol)
Capybara::Selenium::Driver.new(nil, browser: browserSymbol)
def self.set_driver(browserSymbol)
if browserSymbol == :chrome
Capybara.default_driver = :selenium_chrome
Capybara.javascript_driver = :selenium_chrome
else
Capybara.default_driver = :selenium
Capybara.javascript_driver = :selenium
end
Capybara::Selenium::Driver.new(nil, :browser => browserSymbol)
end
end
3 changes: 3 additions & 0 deletions packages/axe-core-capybara/spec/axe-capybara_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,22 @@
end
is_chrome = driver.page.execute_script "return !!window.chrome"
expect(is_chrome).to be true
expect(Capybara.default_driver).to be :selenium_chrome
end

it "defaults to firefox" do
driver = AxeCapybara.configure() do
end
browser = driver.page.options[:browser]
expect(browser).to be :firefox
expect(Capybara.default_driver).to be :selenium
end
it "sets browser correctly" do
driver = AxeCapybara.configure(:chrome) do
end
browser = driver.page.options[:browser]
expect(browser).to be :chrome
expect(Capybara.default_driver).to be :selenium_chrome
end

it "should yield configuration with specified jslib path" do
Expand Down
4 changes: 2 additions & 2 deletions packages/axe-core-rspec/e2e/capybara/spec/a11y_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

# Typical example using standard RSpec dsl
describe "ABCD CompuTech (RSpec DSL)",
:type => :feature, :driver => :selenium do
:type => :feature do
before :each do
visit "http://abcdcomputech.dequecloud.com/"
page.visit "http://abcdcomputech.dequecloud.com/"
end

it "is known to be inaccessible, should fail" do
Expand Down
2 changes: 1 addition & 1 deletion packages/axe-core-rspec/e2e/capybara/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require "axe-rspec"
require "axe-capybara"

@page = AxeCapybara.configure(:firefox) do |c|
AxeCapybara.configure(:chrome) do |c|
end

RSpec.configure do |config|
Expand Down