diff --git a/.reek.yml b/.reek.yml index 59adb39..26b21b1 100644 --- a/.reek.yml +++ b/.reek.yml @@ -7,3 +7,6 @@ detectors: exclude: - initialize max_statements: 10 + +exclude_paths: + - 'lib/commands/open_ai_commands.rb' diff --git a/.rubocop.yml b/.rubocop.yml index 0ec4179..7fe39bb 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,6 +1,10 @@ require: - rubocop-rspec +AllCops: + Exclude: + - 'lib/commands/open_ai_commands.rb' + # Layout Layout/CaseIndentation: Enabled: false @@ -87,4 +91,4 @@ Style/SafeNavigation: Style/SingleLineBlockParams: Description: 'Enforces the names of some block params.' - Enabled: false + Enabled: false \ No newline at end of file diff --git a/lib/generators/automation/templates/partials/initialize_selector.tt b/lib/generators/automation/templates/partials/initialize_selector.tt index 299f5ff..b4112c4 100644 --- a/lib/generators/automation/templates/partials/initialize_selector.tt +++ b/lib/generators/automation/templates/partials/initialize_selector.tt @@ -4,6 +4,13 @@ def initialize(browser) @browser = browser end +<% elsif axe? %> + attr_reader :driver + alias page driver + + def initialize(driver) + @driver = driver + end <% else %> attr_reader :driver diff --git a/lib/generators/automation/templates/partials/selenium_login.tt b/lib/generators/automation/templates/partials/selenium_login.tt index 3040dcc..7e4bbb5 100644 --- a/lib/generators/automation/templates/partials/selenium_login.tt +++ b/lib/generators/automation/templates/partials/selenium_login.tt @@ -14,6 +14,7 @@ class Login < Page password_field.send_keys password login_button.click end + alias log_as login private diff --git a/lib/generators/generator.rb b/lib/generators/generator.rb index 023971f..0e1fb58 100644 --- a/lib/generators/generator.rb +++ b/lib/generators/generator.rb @@ -9,6 +9,7 @@ class Generator < Thor::Group argument :framework argument :name argument :visual_automation, optional: true + argument :axe_support, optional: true def self.source_paths base_path = File.dirname(__FILE__) @@ -46,7 +47,7 @@ def selenium? end def visual? - initializer.first.last + args[3] end def watir? @@ -57,6 +58,10 @@ def web? (args & (%w[selenium watir])).count.positive? end + def axe? + args.last + end + private def _initializer diff --git a/lib/generators/invoke_generators.rb b/lib/generators/invoke_generators.rb index 425719e..32a6212 100644 --- a/lib/generators/invoke_generators.rb +++ b/lib/generators/invoke_generators.rb @@ -18,7 +18,8 @@ def generate_framework(structure = {}) framework: framework, generator: generator, name: structure[:name], - visual: structure[:visual] + visual: structure[:visual], + axe_support: structure[:axe_support] }) end end @@ -32,6 +33,7 @@ def invoke_generator(structure = {}) .new([structure[:automation], structure[:framework], structure[:name], - structure[:visual]]).invoke_all + structure[:visual], + structure[:axe_support]]).invoke_all end end diff --git a/lib/generators/menu_generator.rb b/lib/generators/menu_generator.rb index a597f03..50669d6 100644 --- a/lib/generators/menu_generator.rb +++ b/lib/generators/menu_generator.rb @@ -22,7 +22,11 @@ def generate_choice_menu end def choose_visual_automation - prompt.select('Do you want to add visual automation with applitools?', visual_automation_menu_choices) + prompt.select('Do you want to add visual automation with Applitools?', yes_no_menu_choices) + end + + def choose_axe_support + prompt.select('Do you want to add Axe accessibility testing tool?', yes_no_menu_choices) end def choose_test_framework(automation) @@ -37,7 +41,8 @@ def set_up_framework(options) automation: options[:automation], framework: options[:framework], name: @name, - visual: options[:visual_automation] + visual: options[:visual_automation], + axe_support: options[:axe_support] } generate_framework(structure) system "cd #{name} && gem install bundler && bundle install" @@ -69,22 +74,32 @@ def select_test_framework(automation) end end - FrameworkOptions = Struct.new(:automation, :framework, :visual_automation) + FrameworkOptions = Struct.new(:automation, :framework, :visual_automation, :axe_support) def create_framework_options(params) - FrameworkOptions.new(params[:automation], params[:framework], params[:visual_automation]) + FrameworkOptions.new(params[:automation], params[:framework], params[:visual_automation], params[:axe_support]) end def create_framework(framework, automation_type) visual_automation = choose_visual_automation if %w[selenium].include?(automation_type) + axe = choose_axe_support if automation_type == 'selenium' && framework == 'Rspec' && visual_automation == false options = create_framework_options(automation: automation_type, framework: framework.downcase, - visual_automation: visual_automation) + visual_automation: visual_automation, + axe_support: axe) + + # Print the chosen options + puts 'Chosen Options:' + puts " Automation Type: #{options[:automation]}" + puts " Framework: #{options[:framework]}" + puts " Visual Automation: #{options[:visual_automation]}" + puts " Axe Support: #{options[:axe_support]}" + set_up_framework(options) prompt.say("You have chosen to use #{framework} with #{automation_type}") end - def visual_automation_menu_choices + def yes_no_menu_choices { Yes: -> { true }, No: -> { false }, diff --git a/lib/generators/rspec/rspec_generator.rb b/lib/generators/rspec/rspec_generator.rb index f744632..f0ac06f 100644 --- a/lib/generators/rspec/rspec_generator.rb +++ b/lib/generators/rspec/rspec_generator.rb @@ -14,4 +14,10 @@ def generate_pdp_spec template('spec.tt', "#{name}/spec/pdp_page_spec.rb") end + + def generate_account_spec + return unless visual? + + template('spec.tt', "#{name}/spec/account_page_spec.rb") + end end diff --git a/lib/generators/rspec/templates/spec.tt b/lib/generators/rspec/templates/spec.tt index dc8485c..f16884d 100644 --- a/lib/generators/rspec/templates/spec.tt +++ b/lib/generators/rspec/templates/spec.tt @@ -6,6 +6,34 @@ require_relative '../models/model_factory' require_relative '../page_objects/pages/account' require_relative '../page_objects/pages/login' +<%- if axe? %> +describe 'Login' do + let(:login) { Login.new(driver) } + let(:account) { Account.new(driver) } + let(:user) { ModelFactory.for('users')['registered user'] } + + before do + login.visit + login.log_as(user['username'], user['password']) + end + + context 'with a login user on the account page' do + it 'no accessibility errors are present on the page' do + expect(account.page).to be_axe_clean + end + + it 'no accessibility errors are present on the transaction history' do + transaction_history = '.dash-tile.dash-tile-balloon.clearfix' + expect(account.page).to be_axe_clean.within transaction_history + end + + it 'no accessibility errors are present on the heading' do + heading = '.maintext' + expect(account.page).to be_axe_clean.within heading + end + end +end +<%- elsif %w[selenium watir].include? automation -%> describe 'Login' do subject(:header) { account_page.header.customer_name } @@ -42,6 +70,7 @@ describe 'Login' do end end end +<%- end -%> <%- elsif automation == 'sparkling_ios' -%> require_relative '../helpers/spec_helper' require_relative '../page_objects/pages/home' diff --git a/lib/generators/templates/common/gemfile.tt b/lib/generators/templates/common/gemfile.tt index 955a5be..15422ca 100644 --- a/lib/generators/templates/common/gemfile.tt +++ b/lib/generators/templates/common/gemfile.tt @@ -7,6 +7,10 @@ gem 'allure-cucumber' gem 'allure-rspec' gem 'allure-ruby-commons' <% end -%> +<% if axe? -%> +gem 'axe-core-rspec' +gem 'axe-core-selenium' +<% end -%> <% if visual_automation -%> gem 'eyes_selenium', '~> 4.6', '>= 4.6.1' gem 'eyes_universal', '~> 3.3', '>= 3.3.1' diff --git a/lib/generators/templates/helpers/driver_helper.tt b/lib/generators/templates/helpers/driver_helper.tt index 4d0842a..38adb6c 100644 --- a/lib/generators/templates/helpers/driver_helper.tt +++ b/lib/generators/templates/helpers/driver_helper.tt @@ -21,6 +21,9 @@ module DriverHelper end <%- else -%> # frozen_string_literal: true +<% if axe? -%> +require 'axe-selenium' +<% end -%> require 'yaml' <% if automation == 'selenium' -%> require 'active_support/inflector' @@ -30,10 +33,14 @@ require 'appium_lib' <% end -%> module DriverHelper - <% if automation == 'selenium' -%> + <% if automation == 'selenium' && axe? == false -%> def driver(*opts) @driver ||= create_driver(*opts) end + <% elsif axe? == true -%> + def driver(browser = :chrome, js_path = nil, skip_iframes = nil) + @driver ||= create_driver(browser, js_path, skip_iframes) + end <% else -%> def driver @driver ||= create_driver diff --git a/lib/generators/templates/helpers/partials/driver_and_options.tt b/lib/generators/templates/helpers/partials/driver_and_options.tt index 81d6cf8..32f2515 100644 --- a/lib/generators/templates/helpers/partials/driver_and_options.tt +++ b/lib/generators/templates/helpers/partials/driver_and_options.tt @@ -1,4 +1,11 @@ -<% if automation == 'selenium' -%> +<% if automation == 'selenium' && axe? == true -%> + def create_driver(browser, js_path, skip_iframes) + AxeSelenium.configure(browser) do |config| + config.jslib_path = js_path if js_path + config.skip_iframes = skip_iframes if skip_iframes + end.page + end +<% elsif automation == 'selenium' -%> def create_driver(*opts) @config = YAML.load_file('config/config.yml') browser = @config['browser'].to_sym @@ -22,7 +29,6 @@ driver_options.each { |opt| options.add_option(opt.first, opt.last) } options end - <% elsif automation == 'cross_platform' -%> def create_driver platform = config['platform'].to_s diff --git a/lib/generators/templates/helpers/spec_helper.tt b/lib/generators/templates/helpers/spec_helper.tt index 81d968b..0d52740 100644 --- a/lib/generators/templates/helpers/spec_helper.tt +++ b/lib/generators/templates/helpers/spec_helper.tt @@ -30,6 +30,9 @@ end <%- else -%> # frozen_string_literal: true +<%- if axe? %> +require 'axe-rspec' +<%- end -%> require 'rspec' require 'tmpdir' require_relative 'allure_helper' diff --git a/lib/version b/lib/version index 120f532..35864a9 100644 --- a/lib/version +++ b/lib/version @@ -1 +1 @@ -0.8.6 \ No newline at end of file +0.8.7 \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 7920c3e..2c18273 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -15,7 +15,7 @@ FRAMEWORKS.each do |framework| AUTOMATION_TYPES.each do |automation| [true, false].each do |visual| - settings = create_settings(framework: framework, automation: automation, visual: visual) + settings = create_settings(framework: framework, automation: automation, visual: visual, axe: axe_support) generate_framework(settings) end end