diff options
Diffstat (limited to 'actionpack/lib/system_testing/test_helpers')
-rw-r--r-- | actionpack/lib/system_testing/test_helpers/assertions.rb | 8 | ||||
-rw-r--r-- | actionpack/lib/system_testing/test_helpers/form_helper.rb | 28 |
2 files changed, 36 insertions, 0 deletions
diff --git a/actionpack/lib/system_testing/test_helpers/assertions.rb b/actionpack/lib/system_testing/test_helpers/assertions.rb index 865b5e59db..6e5b62e3c5 100644 --- a/actionpack/lib/system_testing/test_helpers/assertions.rb +++ b/actionpack/lib/system_testing/test_helpers/assertions.rb @@ -1,6 +1,11 @@ module SystemTesting module TestHelpers + # Assertions for system testing that aren't included by default in Capybara. + # These are assertions that are useful specifically for Rails applications. module Assertions + # Asserts that all of the provided selectors are present on the given page. + # + # assert_all_of_selectors('p', 'td') def assert_all_of_selectors(*items) options = items.extract_options! type = type_for_selector(items) @@ -10,6 +15,9 @@ module SystemTesting end end + # Asserts that none of the provided selectors are present on the page. + # + # assert_none_of_selectors('ul', 'ol') def assert_none_of_selectors(*items) options = items.extract_options! type = type_for_selector(items) diff --git a/actionpack/lib/system_testing/test_helpers/form_helper.rb b/actionpack/lib/system_testing/test_helpers/form_helper.rb index 6ce5c54864..4789694bbb 100644 --- a/actionpack/lib/system_testing/test_helpers/form_helper.rb +++ b/actionpack/lib/system_testing/test_helpers/form_helper.rb @@ -1,18 +1,46 @@ module SystemTesting module TestHelpers + # Form helpers for system testing that aren't included by default in + # Capybara. module FormHelper + # Finds all provided fields or text areas and fills in with supplied values. + # + # fill_in_all_fields('Name' => 'Eileen', 'Job Title' => 'Programmer') def fill_in_all_fields(fields) fields.each do |name, value| fill_in name, with: value end end + # Locates a checkbox that is present inside a label and checks it. When + # using styled boxes Selenium may not be able to see the checkbox. This + # form helper looks inside the checkbox and clicks the label instead of + # setting the value of the checkbox. + # + # click_checkbox_label 'Admin' + # + # By default +click_checkbox_label+ looks for checkboxes that are not + # checked by default. To locate an already checked box and uncheck it + # set checked to true: + # + # click_checkbox_label 'Admin', checked: true def click_checkbox_label(name, checked: false) field = find_checkbox(name, checked) label = find_label_wrapper(field) label.click end + # In lieu of locating a button and calling +click_on+, +press_enter+ will + # submit the form via enter. This method will only work for drivers that + # load a browser like Selenium. + # + # test 'Adding a User' do + # fill_in 'Name', with: 'Arya' + # + # press_enter + # + # assert_text 'Arya' + # end def press_enter page.driver.browser.action.send_keys(:enter).perform end |