Project

General

Profile

Need help making Capybara + selenium with Ajax working

Added by Etienne Massip almost 12 years ago

Ok I've tried and failed to make it work, could someone please save me a lot of time and tell me why this test is failing on the last assert_selector call telling me there is nothing in the div although there should ba a fieldset labelled "Description"?

Index: Gemfile
===================================================================
--- Gemfile    (revision 11050)
+++ Gemfile    (working copy)
@@ -81,6 +81,8 @@
   platforms << :jruby if defined?(JRUBY_VERSION) && JRUBY_VERSION >= "1.7" 
   gem "test-unit", :platforms => platforms
   gem "mocha", "0.12.3" 
+  gem 'capybara', '~> 2.0.1'
+  gem 'database_cleaner'
 end

 local_gemfile = File.join(File.dirname(__FILE__), "Gemfile.local")
Index: test/integration/capybara.rb
===================================================================
--- test/integration/capybara.rb    (revision 0)
+++ test/integration/capybara.rb    (working copy)
@@ -0,0 +1,47 @@
+# Redmine - project management software
+# Copyright (C) 2006-2012  Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+require File.expand_path('../../test_helper', __FILE__)
+
+class PreviewTest < ActionDispatch::IntegrationTest
+  fixtures :projects,
+           :users,
+           :roles,
+           :members,
+           :member_roles,
+           :trackers,
+           :projects_trackers,
+           :enabled_modules,
+           :issue_statuses,
+           :issues,
+           :enumerations,
+           :custom_fields,
+           :custom_values,
+           :custom_fields_trackers
+
+  def test_new_issue_preview
+    log_user 'jsmith', 'jsmith'
+
+    visit new_issue_path(:project_id => 1)
+
+    find('form#issue-form #issue_description').set 'This is a test'
+
+    click_link 'Preview'
+
+    assert_selector('div#preview fieldset', :visible => true, :text => 'This is a test')
+  end
+end
Index: test/test_helper.rb
===================================================================
--- test/test_helper.rb    (revision 11050)
+++ test/test_helper.rb    (working copy)
@@ -20,13 +20,46 @@
 require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
 require 'rails/test_help'
 require Rails.root.join('test', 'mocks', 'open_id_authentication_mock.rb').to_s
+require 'capybara/rails'

 require File.expand_path(File.dirname(__FILE__) + '/object_helpers')
 include ObjectHelpers

+# Transactional fixtures do not work with Selenium tests, because Capybara
+# uses a separate server thread, which the transactions would be hidden
+# from. We hence use DatabaseCleaner to truncate our test database.
+DatabaseCleaner.strategy = :truncation
+#Capybara.default_driver = :webkit
+
+class ActionDispatch::IntegrationTest
+  # Make the Capybara DSL available in all integration tests
+  include Capybara::DSL
+
+  def log_user(login, password)
+    User.anonymous
+    visit '/my/page'
+    assert_equal '/login', current_path
+    within('#login-form form') do
+      fill_in 'username', :with => login
+      fill_in 'password', :with => password
+      click_button('Login')
+    end
+    assert_equal '/my/page', current_path
+  end
+
+  # Stop ActiveRecord from wrapping tests in transactions
+  self.use_transactional_fixtures = false
+
+  teardown do
+    DatabaseCleaner.clean       # Truncate the database
+    Capybara.reset_sessions!    # Forget the (simulated) browser state
+    Capybara.use_default_driver # Revert Capybara.current_driver to Capybara.default_driver
+  end
+end
+
 class ActiveSupport::TestCase
   include ActionDispatch::TestProcess

Thanks !


Replies (1)

RE: Need help making Capybara + selenium with Ajax working - Added by Etienne Massip almost 12 years ago

My bad, I thought that Capybara was using some combination of racktest and selenium for default driver.

    (1-1/1)