diff --git a/spec/selenium/common.rb b/spec/selenium/common.rb index 67b02b06055..2e02f350b3d 100644 --- a/spec/selenium/common.rb +++ b/spec/selenium/common.rb @@ -98,12 +98,20 @@ module SeleniumTestsHelperMethods end # f means "find" this is a shortcut to finding elements - # if driver.find_element fails, then it'll try to find it with jquery def f(selector, scope = nil) begin (scope || driver).find_element :css, selector rescue + nil + end + end + + # short for find with jquery + def fj(selector, scope = nil) + begin find_with_jquery selector, scope + rescue + nil end end @@ -112,7 +120,16 @@ module SeleniumTestsHelperMethods begin (scope || driver).find_elements :css, selector rescue + [] + end + end + + # same as find with jquery but tries to find several elements instead of one + def ffj(selector, scope = nil) + begin find_all_with_jquery selector, scope + rescue + [] end end @@ -739,7 +756,7 @@ shared_examples_for "all selenium tests" do ## # returns true if a form validation error message is visible, false otherwise def error_displayed? - f('.error_text:visible') != nil + fj('.error_text:visible') != nil end self.use_transactional_fixtures = false diff --git a/spec/selenium/conversations_common.rb b/spec/selenium/conversations_common.rb index 335f649fc90..bc4397fce6e 100644 --- a/spec/selenium/conversations_common.rb +++ b/spec/selenium/conversations_common.rb @@ -70,7 +70,7 @@ shared_examples_for "conversations selenium tests" do @elements = prev_elements @level -= 1 - @input.send_keys(:arrow_left) unless ff('.autocomplete_menu:visible .list').empty? + @input.send_keys(:arrow_left) unless ffj('.autocomplete_menu:visible .list').empty? wait_for_animations end diff --git a/spec/selenium/conversations_context_filtering_spec.rb b/spec/selenium/conversations_context_filtering_spec.rb index b0ee04658af..452140f1ac1 100644 --- a/spec/selenium/conversations_context_filtering_spec.rb +++ b/spec/selenium/conversations_context_filtering_spec.rb @@ -56,8 +56,8 @@ describe "conversations context filtering" do it "should let you browse for filters" do new_conversation - @browser = f("#context_tags_filter .browser:visible") - @input = f("#context_tags_filter input:visible") + @browser = fj("#context_tags_filter .browser:visible") + @input = fj("#context_tags_filter input:visible") browse_menu menu.should eql ["that course", "the course", "the group"] diff --git a/spec/selenium/course_settings_spec.rb b/spec/selenium/course_settings_spec.rb index b822cd53788..029833e449b 100644 --- a/spec/selenium/course_settings_spec.rb +++ b/spec/selenium/course_settings_spec.rb @@ -18,8 +18,8 @@ describe "course settings tests" do f('.find_grading_standard_link').click wait_for_ajaximations - f('.grading_standard_select:visible a').click - f('button.select_grading_standard_link:visible').click + fj('.grading_standard_select:visible a').click + fj('button.select_grading_standard_link:visible').click f('.done_button').click f('#course_form').submit wait_for_ajaximations diff --git a/spec/selenium/file_uploads_spec.rb b/spec/selenium/file_uploads_spec.rb index c456199f246..6ede7fb68ba 100644 --- a/spec/selenium/file_uploads_spec.rb +++ b/spec/selenium/file_uploads_spec.rb @@ -33,12 +33,9 @@ shared_examples_for "file uploads selenium tests" do filename, fullpath, data = get_file("testfile5.zip") - driver.find_element(:css, '#choose_migration_system'). - find_element(:css, 'option[value="common_cartridge_importer"]').click - driver.find_element(:css, '#config_options'). - find_element(:name, 'export_file').send_keys(fullpath) - driver.find_element(:css, '#config_options'). - find_element(:css, '.submit_button').click + click_option('#choose_migration_system', 'common_cartridge_importer', :value) + driver.find_element(:css, '#config_options').find_element(:name, 'export_file').send_keys(fullpath) + driver.find_element(:css, '#config_options').find_element(:css, '.submit_button').click wait_for_ajax_requests keep_trying_until { driver.find_element(:id, 'file_uploaded').should be_displayed } diff --git a/spec/selenium/gradebooks_spec.rb b/spec/selenium/gradebooks_spec.rb index 2d5622cc60c..4469951d3c2 100644 --- a/spec/selenium/gradebooks_spec.rb +++ b/spec/selenium/gradebooks_spec.rb @@ -84,13 +84,13 @@ describe "gradebooks" do get "/courses/#{@course.id}/gradebook" wait_for_ajaximations - ff('img.turnitin:visible').size.should eql 2 + ffj('img.turnitin:visible').size.should eql 2 # now create a ton of students so that the data loads via ajax 100.times { |i| student_in_course(:active_all => true, :name => "other guy #{i}") } get "/courses/#{@course.id}/gradebook" wait_for_ajaximations - ff('img.turnitin:visible').size.should eql 2 + ffj('img.turnitin:visible').size.should eql 2 end end diff --git a/spec/selenium/quizzes_common.rb b/spec/selenium/quizzes_common.rb index 77674394abd..d66f68fbe3c 100644 --- a/spec/selenium/quizzes_common.rb +++ b/spec/selenium/quizzes_common.rb @@ -106,7 +106,7 @@ shared_examples_for "quizzes selenium tests" do end def hover_first_question - question = f '.display_question' + question = f('.display_question') driver.action.move_to(question).perform end @@ -117,7 +117,7 @@ shared_examples_for "quizzes selenium tests" do end def save_question - f('.question_form:visible').submit + fj('.question_form:visible').submit wait_for_ajax_requests end @@ -131,7 +131,7 @@ shared_examples_for "quizzes selenium tests" do end def edit_first_multiple_choice_answer(text) - element = f 'input[name=answer_text]:visible' + element = fj('input[name=answer_text]:visible') element.click element.send_keys text end @@ -144,7 +144,7 @@ shared_examples_for "quizzes selenium tests" do def delete_first_multiple_choice_answer driver.execute_script "$('.answer').addClass('hover');" - f('.delete_answer_link:visible').click + fj('.delete_answer_link:visible').click end diff --git a/spec/selenium/quizzes_question_creation_spec.rb b/spec/selenium/quizzes_question_creation_spec.rb index 0f769c37746..11ee93db6d9 100644 --- a/spec/selenium/quizzes_question_creation_spec.rb +++ b/spec/selenium/quizzes_question_creation_spec.rb @@ -507,6 +507,5 @@ describe "quizzes question creation" do save_question error_displayed?.should be_true end - end