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

Axe implementation #95

Merged
merged 4 commits into from
May 28, 2024
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
3 changes: 3 additions & 0 deletions .reek.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ detectors:
exclude:
- initialize
max_statements: 10

exclude_paths:
- 'lib/commands/open_ai_commands.rb'
6 changes: 5 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
require:
- rubocop-rspec

AllCops:
Exclude:
- 'lib/commands/open_ai_commands.rb'

# Layout
Layout/CaseIndentation:
Enabled: false
Expand Down Expand Up @@ -87,4 +91,4 @@ Style/SafeNavigation:

Style/SingleLineBlockParams:
Description: 'Enforces the names of some block params.'
Enabled: false
Enabled: false
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Login < Page
password_field.send_keys password
login_button.click
end
alias log_as login

private

Expand Down
7 changes: 6 additions & 1 deletion lib/generators/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -46,7 +47,7 @@ def selenium?
end

def visual?
initializer.first.last
args[3]
end

def watir?
Expand All @@ -57,6 +58,10 @@ def web?
(args & (%w[selenium watir])).count.positive?
end

def axe?
args.last
end

private

def _initializer
Expand Down
6 changes: 4 additions & 2 deletions lib/generators/invoke_generators.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
27 changes: 21 additions & 6 deletions lib/generators/menu_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"
Expand Down Expand Up @@ -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 },
Expand Down
6 changes: 6 additions & 0 deletions lib/generators/rspec/rspec_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
29 changes: 29 additions & 0 deletions lib/generators/rspec/templates/spec.tt
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down Expand Up @@ -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'
Expand Down
4 changes: 4 additions & 0 deletions lib/generators/templates/common/gemfile.tt
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
9 changes: 8 additions & 1 deletion lib/generators/templates/helpers/driver_helper.tt
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand Down
10 changes: 8 additions & 2 deletions lib/generators/templates/helpers/partials/driver_and_options.tt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions lib/generators/templates/helpers/spec_helper.tt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ end
<%- else -%>
# frozen_string_literal: true

<%- if axe? %>
require 'axe-rspec'
<%- end -%>
require 'rspec'
require 'tmpdir'
require_relative 'allure_helper'
Expand Down
2 changes: 1 addition & 1 deletion lib/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.8.6
0.8.7
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading