我正在学习 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 => '[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
将 Action 定位到正确的帧:
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
关于ruby-on-rails-3 - Capybara 无法从 Stripe 中找到表单字段?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20601127/