Permalink
Browse files

Add ForHelper's for system tests

These FormHelpers are selectors that aren't a capybara default but are
considered useful for Rails applications.
  • Loading branch information...
eileencodes committed Aug 5, 2016
1 parent 4f08bc0 commit 0056c9b977a4cd61334909ff950de9358ec84d74
@@ -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!
@@ -0,0 +1,7 @@
+module SystemTesting
+ module TestHelpers
+ extend ActiveSupport::Autoload
+
+ autoload :FormHelper
+ end
+end
@@ -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

0 comments on commit 0056c9b

Please sign in to comment.