diff options
author | eileencodes <eileencodes@gmail.com> | 2016-08-05 12:02:56 -0400 |
---|---|---|
committer | eileencodes <eileencodes@gmail.com> | 2017-02-20 15:07:31 -0500 |
commit | 0056c9b977a4cd61334909ff950de9358ec84d74 (patch) | |
tree | e9256aa6a6b2a517e06fc400c8de05fa0bb7ac03 /actionpack/lib | |
parent | 4f08bc0808ab93f70a029f15ac094d61fc5ba121 (diff) | |
download | rails-0056c9b977a4cd61334909ff950de9358ec84d74.tar.gz rails-0056c9b977a4cd61334909ff950de9358ec84d74.tar.bz2 rails-0056c9b977a4cd61334909ff950de9358ec84d74.zip |
Add ForHelper's for system tests
These FormHelpers are selectors that aren't a capybara default but are
considered useful for Rails applications.
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/system_testing/test_helper.rb | 2 | ||||
-rw-r--r-- | actionpack/lib/system_testing/test_helpers.rb | 7 | ||||
-rw-r--r-- | actionpack/lib/system_testing/test_helpers/form_helper.rb | 30 |
3 files changed, 39 insertions, 0 deletions
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 |