我正在学习Ruby on Rails,并且正在开发一个使用条纹创建高级帐户的应用程序。另外,我正在使用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 => '[email protected]'
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"
所有人都知道,这可能是什么问题?谢谢。
取决于您如何集成Stripe,它可能正在iframe
中呈现表单。在这种情况下,您需要使用Capybara.within_frame
将操作定位到正确的帧:
Capybara.within_frame
尝试使用元素ID代替字段标签。
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 => '[email protected]'
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
(是card_number和cvc输入字段的ID。)>
fill_in 'card_number', :with => '4242424242424242' fill_in 'cvc', :with => '123'
我遇到了同样的问题,我使用了此解决方案,不确定这是否是一个好习惯,但是对我有用。
对于有条纹测试的水豚: