From 9e116d7b38fef5a77efbc503be8bc69c8ac0d9ff Mon Sep 17 00:00:00 2001 From: Jey Date: Mon, 13 Jul 2020 14:29:05 -0400 Subject: [PATCH] refactor: allow to configure browser as a Symbol argument for webdrivers (#109) --- packages/axe-core-capybara/README.md | 13 ++++++------ packages/axe-core-capybara/Rakefile | 14 +++++++++++++ .../axe-core-capybara/lib/axe-capybara.rb | 16 +++------------ .../spec/axe-capybara_spec.rb | 4 ++-- packages/axe-core-selenium/README.md | 13 ++++++------ packages/axe-core-selenium/Rakefile | 14 +++++++++++++ .../axe-core-selenium/lib/axe-selenium.rb | 16 +++------------ .../spec/axe-selenium_spec.rb | 6 +++--- packages/axe-core-watir/README.md | 14 ++++++------- packages/axe-core-watir/Rakefile | 14 +++++++++++++ packages/axe-core-watir/lib/axe-watir.rb | 20 +++---------------- .../axe-core-watir/spec/axe-watir_spec.rb | 6 +++--- 12 files changed, 80 insertions(+), 70 deletions(-) diff --git a/packages/axe-core-capybara/README.md b/packages/axe-core-capybara/README.md index 31122dd4..f1776ed4 100644 --- a/packages/axe-core-capybara/README.md +++ b/packages/axe-core-capybara/README.md @@ -9,7 +9,7 @@ require 'axe-core-capybara' # configure `AxeCapybara` -driver = AxeCapybara.configure("firefox") do |c| +driver = AxeCapybara.configure(:firefox) do |c| # see below for a full list of configuration c.jslib_path = "next-version/axe.js" end @@ -22,12 +22,12 @@ driver.page.navigate.to 'https://www.deque.com/' #### `AxeCapybara.configure` -The configure method takes 1 optional argument and a configuration block object: `configure(*arg, &block)` +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 `capybara`. The valid browser names are: -- `firefox` (default) -- `chrome` -- `safari` +- `:firefox` (default) +- `:chrome` +- `:safari` > Note: Please ensure respective drivers (eg: [`geckodriver`][]) are installed in your machine. @@ -56,4 +56,5 @@ bundle exec rspec [axe API]: https://github.com/dequelabs/axe-core/blob/develop/doc/API.md [Capybara Webdriver]: https://github.com/teamcapybara/capybara/ -[`geckodriver`]: https://github.com/mozilla/geckodriver/releases \ No newline at end of file +[`geckodriver`]: https://github.com/mozilla/geckodriver/releases +[symbol]: https://ruby-doc.org/core-2.5.0/Symbol.html \ No newline at end of file diff --git a/packages/axe-core-capybara/Rakefile b/packages/axe-core-capybara/Rakefile index cc01a3fa..42d4f76f 100644 --- a/packages/axe-core-capybara/Rakefile +++ b/packages/axe-core-capybara/Rakefile @@ -2,4 +2,18 @@ require "rspec/core/rake_task" RSpec::Core::RakeTask.new(:spec) +# default task task :default => :spec + +# unit tests +desc "Tests Unit" +task :test_unit do + sh "bundle install && bundle exec rake" +end + +# all tests +desc "Tests all" +task :test_all => [ + "test_unit", + ] do +end diff --git a/packages/axe-core-capybara/lib/axe-capybara.rb b/packages/axe-core-capybara/lib/axe-capybara.rb index 974502b6..e43f1f08 100644 --- a/packages/axe-core-capybara/lib/axe-capybara.rb +++ b/packages/axe-core-capybara/lib/axe-capybara.rb @@ -7,7 +7,7 @@ module AxeCapybara # configure method # - which takes an optional argument browser # - and a configuration block optional for Axe - def self.configure(browser = "firefox") + def self.configure(browser = :firefox) # instantiate axe configuration (singleton) with defaults or given config if !block_given? @@ -26,17 +26,7 @@ def self.configure(browser = "firefox") private - # todo: allow to pass driver options (this option does not exist today - create a feature issue) - def self.get_driver(browserName) - case browserName - when "chrome" - Capybara::Selenium::Driver.new(:chrome) - when "safari" - Capybara::Selenium::Driver.new(:safari) - when "firefox" - Capybara::Selenium::Driver.new(:firefox) - else - Capybara::Selenium::Driver.new(:firefox) - end + def self.get_driver(browserSymbol) + Capybara::Selenium::Driver.new(browserSymbol) end end diff --git a/packages/axe-core-capybara/spec/axe-capybara_spec.rb b/packages/axe-core-capybara/spec/axe-capybara_spec.rb index 73e7f351..2488d55d 100644 --- a/packages/axe-core-capybara/spec/axe-capybara_spec.rb +++ b/packages/axe-core-capybara/spec/axe-capybara_spec.rb @@ -8,7 +8,7 @@ describe "driver" do it "validate yielded configuration" do - driver = AxeCapybara.configure("firefox") do + driver = AxeCapybara.configure(:firefox) do end expect(driver).not_to be_nil @@ -43,7 +43,7 @@ end it "should yield configuration with Safari driver" do - AxeCapybara.configure("safari") do + AxeCapybara.configure(:safari) do end actual = Axe::Configuration.instance diff --git a/packages/axe-core-selenium/README.md b/packages/axe-core-selenium/README.md index 33938ca5..8be078f0 100644 --- a/packages/axe-core-selenium/README.md +++ b/packages/axe-core-selenium/README.md @@ -9,7 +9,7 @@ require 'axe-core-selenium' # configure `AxeSelenium` -driver = AxeSelenium.configure("firefox") do |c| +driver = AxeSelenium.configure(:firefox) do |c| # see below for a full list of configuration c.jslib_path = "next-version/axe.js" end @@ -22,12 +22,12 @@ driver.page.navigate.to 'https://www.deque.com/' #### `AxeSelenium.configure` -The configure method takes 1 optional argument and a configuration block object: `configure(*arg, &block)` +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` -- `safari` +- `:firefox` (default) +- `:chrome` +- `:safari` > Note: Please ensure respective drivers (eg: [`geckodriver`][]) are installed in your machine. @@ -56,4 +56,5 @@ 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 \ No newline at end of file +[`geckodriver`]: https://github.com/mozilla/geckodriver/releases +[symbol]: https://ruby-doc.org/core-2.5.0/Symbol.html \ No newline at end of file diff --git a/packages/axe-core-selenium/Rakefile b/packages/axe-core-selenium/Rakefile index cc01a3fa..42d4f76f 100644 --- a/packages/axe-core-selenium/Rakefile +++ b/packages/axe-core-selenium/Rakefile @@ -2,4 +2,18 @@ require "rspec/core/rake_task" RSpec::Core::RakeTask.new(:spec) +# default task task :default => :spec + +# unit tests +desc "Tests Unit" +task :test_unit do + sh "bundle install && bundle exec rake" +end + +# all tests +desc "Tests all" +task :test_all => [ + "test_unit", + ] do +end diff --git a/packages/axe-core-selenium/lib/axe-selenium.rb b/packages/axe-core-selenium/lib/axe-selenium.rb index dd729ebd..b60bbb8b 100644 --- a/packages/axe-core-selenium/lib/axe-selenium.rb +++ b/packages/axe-core-selenium/lib/axe-selenium.rb @@ -6,7 +6,7 @@ module AxeSelenium # configure method # - which takes an optional argument browser # - and a configuration block optional for Axe - def self.configure(browser = "firefox") + def self.configure(browser = :firefox) # instantiate axe configuration (singleton) with defaults or given config if !block_given? @@ -25,17 +25,7 @@ def self.configure(browser = "firefox") private - # todo: allow to pass driver options (this option does not exist today - create a feature issue) - def self.get_driver(browserName) - case browserName - when "chrome" - Selenium::WebDriver.for :chrome - when "safari" - Selenium::WebDriver.for :safari - when "firefox" - Selenium::WebDriver.for :firefox - else - Selenium::WebDriver.for :firefox - end + def self.get_driver(browserSymbol) + Selenium::WebDriver.for browserSymbol end end diff --git a/packages/axe-core-selenium/spec/axe-selenium_spec.rb b/packages/axe-core-selenium/spec/axe-selenium_spec.rb index d769e219..4c54aec5 100644 --- a/packages/axe-core-selenium/spec/axe-selenium_spec.rb +++ b/packages/axe-core-selenium/spec/axe-selenium_spec.rb @@ -8,7 +8,7 @@ describe "driver" do it "validate yielded configuration" do - driver = AxeSelenium.configure("firefox") do + driver = AxeSelenium.configure(:firefox) do end expect(driver).not_to be_nil @@ -43,7 +43,7 @@ end it "should yield configuration with Safari driver" do - AxeSelenium.configure("safari") do + AxeSelenium.configure(:safari) do end actual = Axe::Configuration.instance @@ -52,7 +52,7 @@ end it "should yield configuration with Firefox driver" do - AxeSelenium.configure("firefox") do + AxeSelenium.configure(:firefox) do end actual = Axe::Configuration.instance diff --git a/packages/axe-core-watir/README.md b/packages/axe-core-watir/README.md index 31e271e3..3a7df59d 100644 --- a/packages/axe-core-watir/README.md +++ b/packages/axe-core-watir/README.md @@ -9,7 +9,7 @@ require 'axe-core-watir' # configure `AxeWatir` -driver = AxeWatir.configure("firefox") do |c| +driver = AxeWatir.configure(:firefox) do |c| # see below for a full list of configuration c.jslib_path = "next-version/axe.js" end @@ -22,14 +22,14 @@ driver.page.goto 'https://www.deque.com/' #### `AxeWatir.configure` -The configure method takes 1 optional argument and a configuration block object: `configure(*arg, &block)` +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 `watir`. The valid browser names are: -- `firefox` -- `chrome` (default) -- `safari` -- `internet_explorer` -- `edge` +- `:firefox` +- `:chrome` (default) +- `:safari` +- `:internet_explorer` +- `:edge` A detailed configuration option for each of the browsers are available in the [Watir documenation/ guide](http://watir.com/guides/) diff --git a/packages/axe-core-watir/Rakefile b/packages/axe-core-watir/Rakefile index cc01a3fa..42d4f76f 100644 --- a/packages/axe-core-watir/Rakefile +++ b/packages/axe-core-watir/Rakefile @@ -2,4 +2,18 @@ require "rspec/core/rake_task" RSpec::Core::RakeTask.new(:spec) +# default task task :default => :spec + +# unit tests +desc "Tests Unit" +task :test_unit do + sh "bundle install && bundle exec rake" +end + +# all tests +desc "Tests all" +task :test_all => [ + "test_unit", + ] do +end diff --git a/packages/axe-core-watir/lib/axe-watir.rb b/packages/axe-core-watir/lib/axe-watir.rb index 4f28e660..f872dede 100644 --- a/packages/axe-core-watir/lib/axe-watir.rb +++ b/packages/axe-core-watir/lib/axe-watir.rb @@ -6,7 +6,7 @@ module AxeWatir # configure method # - which takes an optional argument browser # - and a configuration block optional for Axe - def self.configure(browser = "firefox") + def self.configure(browser = :firefox) # instantiate axe configuration (singleton) with defaults or given config if !block_given? @@ -25,21 +25,7 @@ def self.configure(browser = "firefox") private - # todo: allow to pass driver options (this option does not exist today - create a feature issue) - def self.get_driver(browserName) - case browserName - when "chrome" - Watir::Browser.new :chrome - when "safari" - Watir::Browser.new :safari - when "internet_explorer" - Watir::Browser.new :internet_explorer - when "edge" - Watir::Browser.new :edge - when "firefox" - Watir::Browser.new :firefox - else - Watir::Browser.new :firefox - end + def self.get_driver(browserSymbol) + Watir::Browser.new browserSymbol end end diff --git a/packages/axe-core-watir/spec/axe-watir_spec.rb b/packages/axe-core-watir/spec/axe-watir_spec.rb index c8cdea6b..e4fda7cf 100644 --- a/packages/axe-core-watir/spec/axe-watir_spec.rb +++ b/packages/axe-core-watir/spec/axe-watir_spec.rb @@ -6,7 +6,7 @@ describe "driver" do it "validate yielded configuration" do - driver = AxeWatir.configure("firefox") do + driver = AxeWatir.configure(:firefox) do end expect(driver).not_to be_nil @@ -41,7 +41,7 @@ end it "should yield configuration with Safari driver" do - AxeWatir.configure("safari") do + AxeWatir.configure(:safari) do end actual = Axe::Configuration.instance @@ -51,7 +51,7 @@ end it "should yield configuration with Firefox driver" do - AxeWatir.configure("firefox") do + AxeWatir.configure(:firefox) do end actual = Axe::Configuration.instance