我正在学习Ruby on Rails,我正在开发一个使用stripe来创建高级帐户的应用程序。另外,我正在使用Rspec和Capybara进行集成测试。
require 'spec_helper'
feature "user upgrade account to a premium plan" do
scenario "user upgrade account", :js => true do
user = FactoryGirl.create :user
visit new_user_session_path
fill_in 'Email', :with => user.email
fill_in 'Password', :with => user.password
click_button 'Sign in'
visit new_charge_path
click_button "Pay with Card"
fill_in 'Email', :with => 'persona@example.com'
fill_in "Card number", :with => "4242424242424242"
fill_in 'CVC', :with => '123'
fill_in 'MM/YY', :with => '11/14'
click_button 'Pay $5.00'
end
我运行测试并收到一条错误消息:
Failure/Error: fill_in "Card number", :with => "4242424242424242"
Capybara::ElementNotFound:
Unable to find field "Card number"
任何人都知道,可能是什么问题? 感谢。
答案 0 :(得分:2)
根据您对Stripe进行集成的方式,可能会在iframe
内呈现表单。如果是这种情况,您需要使用Capybara.within_frame
将操作定位到正确的框架:
scenario "user upgrade account", :js => true do
user = FactoryGirl.create :user
visit new_user_session_path
fill_in 'Email', :with => user.email
fill_in 'Password', :with => user.password
click_button 'Sign in'
visit new_charge_path
click_button "Pay with Card"
Capybara.within_frame 'stripe_checkout_app' do
fill_in 'Email', :with => 'persona@example.com'
fill_in "Card number", :with => "4242424242424242"
fill_in 'CVC', :with => '123'
fill_in 'MM/YY', :with => '11/14'
click_button 'Pay $5.00'
end
end
答案 1 :(得分:0)
尝试使用元素ID而不是字段标签。
fill_in 'card_number', :with => '4242424242424242'
fill_in 'cvc', :with => '123'
(作为card_number和cvc输入字段的ID。)
= f.text_field :card_number, :class => 'span12', :id => :card_number
= f.text_field :cvc, :class => 'span12', :id => :cvc
我有同样的问题,我使用这个解决方案,不确定这是不是很好的做法,但对我有用。
答案 2 :(得分:0)
具有条纹测试的水豚:
Capybara.within_frame 'stripe_checkout_app' do
fill_in "Card number", :with => "4242424242424242"
fill_in 'CVC', :with => '123'
fill_in 'Expiry', :with => '11/22'
click_button 'Pay $5.00'
end
始终将激发日期编辑为未来的一个月和一年。