From 0056c9b977a4cd61334909ff950de9358ec84d74 Mon Sep 17 00:00:00 2001 From: eileencodes Date: Fri, 5 Aug 2016 12:02:56 -0400 Subject: [PATCH] Add ForHelper's for system tests These FormHelpers are selectors that aren't a capybara default but are considered useful for Rails applications. --- actionpack/lib/system_testing/test_helper.rb | 2 ++ actionpack/lib/system_testing/test_helpers.rb | 7 +++++ .../test_helpers/form_helper.rb | 30 +++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 actionpack/lib/system_testing/test_helpers.rb create mode 100644 actionpack/lib/system_testing/test_helpers/form_helper.rb diff --git a/actionpack/lib/system_testing/test_helper.rb b/actionpack/lib/system_testing/test_helper.rb index 68b187ed7a..9ac2e02f01 100644 --- a/actionpack/lib/system_testing/test_helper.rb +++ b/actionpack/lib/system_testing/test_helper.rb @@ -1,8 +1,10 @@ require 'capybara/rails' +require 'system_testing/test_helpers' module SystemTesting module TestHelper include Capybara::DSL + include TestHelpers::FormHelper def after_teardown Capybara.reset_sessions! diff --git a/actionpack/lib/system_testing/test_helpers.rb b/actionpack/lib/system_testing/test_helpers.rb new file mode 100644 index 0000000000..add9596463 --- /dev/null +++ b/actionpack/lib/system_testing/test_helpers.rb @@ -0,0 +1,7 @@ +module SystemTesting + module TestHelpers + extend ActiveSupport::Autoload + + autoload :FormHelper + end +end diff --git a/actionpack/lib/system_testing/test_helpers/form_helper.rb b/actionpack/lib/system_testing/test_helpers/form_helper.rb new file mode 100644 index 0000000000..6ce5c54864 --- /dev/null +++ b/actionpack/lib/system_testing/test_helpers/form_helper.rb @@ -0,0 +1,30 @@ +module SystemTesting + module TestHelpers + module FormHelper + def fill_in_all_fields(fields) + fields.each do |name, value| + fill_in name, with: value + end + end + + def click_checkbox_label(name, checked: false) + field = find_checkbox(name, checked) + label = find_label_wrapper(field) + label.click + end + + def press_enter + page.driver.browser.action.send_keys(:enter).perform + end + + private + def find_checkbox(name, checked) + find(:field, name, visible: :all, checked: checked) + end + + def find_label_wrapper(field, location: './ancestor::label') + field.find :xpath, location + end + end + end +end -- GitLab