Tag: capybara

Capybara选择(“单选按钮”)不起作用

我的观点快照: 然而,在我的Rspec集成测试文件(spec / requests / requests_spec.rb)上,当我写时(注意,选择单选按钮是用户从列表中请求项目的表单的一部分,并且测试是针对结果页面的提交后,应指明用户请求的项目)。 我正在使用gem’rspec-rails’,’2.13.1′ describe “Requests” do subject { page } describe “new request” do before { visit root_path } describe “with valid information” do before do choose(“Snow/waterproof shell (upper)”) click_button submit end it { should have_content(“Snow/waterproof shell (upper)”) end end end 我总是得到错误: ←[31mFailure/Error:←[0m ←[31mchoose(“Snow/waterproof shell (upper)”)←[0m ←[31mCapybara::ElementNotFound←[0m: ←[31mUnable to find radio […]

Rspec渲染文本

我有这个代码 if @temp_user.save sign_in(:user, @temp_user) render text: “OK” else render text: render_to_string(:partial => “errors”) end 我尝试用rspecvalidation渲染“OK” 这是我的实际规格: it “render text OK” do post :create, {:agent => valid_attributes} # response.should have_content(“OK”) response.should render_template(:text => “OK”) end 但这个规范总是会响应0次失败,即使我把“OKI”放到位“OK” 有人对此有一个建议吗?

Capybara不等待ajax完成

我正在开发一个由EmberJS前端组成的应用程序,它通过REST与Rails服务器通信。 在我的应用程序中通过向导来创建一个作业,所以我想测试是否创建了该作业,这是我的测试。 feature ‘Processing step three’, :js => true do background do to_step_2 to_step_3 end scenario ‘Creating job’, js: true do within ‘#login’ do fill_in ‘Email’, with: @customer.email fill_in ‘Password’, with: @customer.password click_button ‘Login’ end expect { click_link ‘Create job’ }.to change(Job, :count).by(1) end end 因此,当用户填写所有内容时,最后他们点击创建作业,就像我的测试所描述的那样。 当我手动操作时,这工作正常,但当我运行我的规格时,我得到。 1) Creating a new job Processing step three […]

Rspec中的test.host测试Rails重定向

这是我在Rails 3.1.12应用程序中的test.rb环境文件中的一行: config.action_mailer.default_url_options = config.action_controller.default_url_options = { :host => “127.0.0.1”, :port => 3000 } 现在这是我做的测试: subject { get :success } subject.should redirect_to(:home) 这会产生错误: Failure/Error: subject.should redirect_to(:home) Expected response to be a redirect to but was a redirect to 我做错了什么? 或者,配置测试主机的位置? 这是spec_helper.rb文件以供完整参考。 # This file is copied to spec/ when you run ‘rails generate rspec:install’ ENV[“RAILS_ENV”] […]

Capybara没有找到元标签

Capybara 2.1.0似乎没有找到任何元标记: (rdb:1) p page.find ‘meta’ *** Capybara::ElementNotFound Exception: Unable to find css “meta” 即使它们出现在page.source : (rdb:1) p page.source “\n\n\nMyTitle\n\n\n\n\n\n…”

Capybara NoMethodError:未定义的方法`visit’for

感谢回复。 我在应用程序Git应用程序中收到错误错误 Failures: 1) Page pages page creation with invalid information should not create a page Failure/Error: before(:each) { visit new_admin_page_path } NoMethodError: undefined method `visit’ for # # ./spec/requests/page_request_spec.rb:13:in `block (3 levels) in ‘ 2) Page pages page creation with invalid information error messages Failure/Error: before(:each) { visit new_admin_page_path } NoMethodError: undefined method `visit’ […]

Capybara ajax比赛条件

我经常遇到水豚问题,请求测试失败,因为水豚不会等待ajax事件完成后再继续。 谷歌似乎表明我应该使用:我的测试的resynchronize选项来解决这个问题。 但它没有用。 为了certificate这是一个问题,可以通过在ajax调用之后放置一个sleep语句来修复失败的测试。 这似乎是任何不好的做法,因为适当的延迟将根据运行测试的机器的速度而变化。 选择一个适当大的值会严重减慢运行带有大量ajax操作的测试套件的速度。 下面是失败/通过测试的一个例子。 单击“保存”之前的睡眠会使页面上的传递/失败区别开来。应该是has_content(’custom item’): it “should be able create a new todo item”, :js, :resynchronize, :focus do # Visit new action visit new_todo_list # Fill in the name fill_in “#name”, “test list” # Click on add item to launch inline popup find(‘a.add-item’).click within ‘#new_item’ do fill_in ‘todo_item_description’, :with => ‘custom […]

如何在水豚中单击此按钮

请帮我解决水豚这个问题 我在水豚中有一个这样的按钮: 我试过了 click_button “verify” 但它给出了错误: Failure/Error: find(‘#verify’).click NoMethodError: undefined method `node_name’ for nil:NilClass

MiniTest,Capybara,Fixture,Database_Cleaner第二次不通过

以下测试首次通过(在rake db:test:prepare ),但是失败在后续运行时出错。 Capybara :: ElementNotFound:无法找到css“#sale_payment_btn” require “test_helper” DatabaseCleaner.strategy = :transaction class SaleFeatureTest < Capybara::Rails::TestCase include Warden::Test::Helpers Warden.test_mode! self.use_transactional_fixtures = false setup do login_as users(:admin), scope: :user Capybara.current_driver = :selenium #:webkit DatabaseCleaner.start end teardown do DatabaseCleaner.clean Warden.test_reset! end test "Sale" do visit(new_sale_path) # create new sale and redirect to it assert page.has_css?('#sale_payment_btn') # gave error […]

在RSpec请求规范中使用Capybara时,设置自定义请求标头的最佳方法是什么?

我正在使用set_headers方法修补Capybara :: Session,该方法分配给Capybara :: RackTest :: Browser的选项属性(我已经从attr_reader更改为attr_accessor)。 补丁: class Capybara::RackTest::Browser attr_accessor :options end class Capybara::Session def set_headers(headers) if driver.browser.respond_to?(:options=) #because we’ve monkey patched it above options = driver.browser.options if options.nil? || options[:headers].nil? options ||= {} options[:headers] = headers else options[:headers].merge!(headers) end else raise Capybara::NotSupportedByDriverError end end end 在我的请求规范中,我正在做: page.set_headers(“REMOTE_ADDR” => “1.2.3.4”) visit root_path 这有效,但我想知道是否有更好的方法,只是能够在请求上设置自定义remote_ip / […]