【发布时间】:2014-06-06 11:57:54
【问题描述】:
我在尝试为我的 Rails 3.2 应用程序编写 Stripe 的 checkout.js [https://checkout.stripe.com/checkout.js] 集成测试时碰壁了。
在手动测试时(使用 Stripe 的测试密钥),Stripe checkout 对我来说可以正常工作,但我无法让 Capybara 检测和fill_in Stripe checkout iframe 模式中的电子邮件字段。
我正在将 poltergeist 用于无头 javascript,但也使用 capybara-webkit 甚至 selenium 进行了同样的测试。
我要测试的是完整的订阅注册流程,以表明新用户可以在 Stripe 中输入他们的付款详细信息后创建订阅者帐户 - 但我无法通过 Stripe 结帐弹出窗口。
这是我的before .. do:
describe "show Stripe checkout", :js => true do
before do
visit pricing_path
click_button 'plan-illuminated'
stripe_iframe = all('iframe[name=stripe_checkout_app]').last
Capybara.within_frame stripe_iframe do
fill_in "email", :with => "test-user@example.com"
fill_in "billing-name", :with => "Mr Name"
fill_in "billing-street", :with => "test Street"
fill_in "billing-zip", :with => 10000
fill_in "billing-city", :with => "Berlin"
click_button "Payment Info"
end
end
it { should have_selector('button', text: "Subscribe") }
end
哪些错误:
Failure/Error: Capybara.within_frame stripe_iframe do
Capybara::Poltergeist::TimeoutError:
Timed out waiting for response to {"name":"push_frame","args":[null]}
如果我换掉尝试选择正确的 iframe(此处建议:Capybara trouble filling in JS modal),如下所示:
# stripe_iframe = all('iframe[name=stripe_checkout_app]').last
# Capybara.within_frame stripe_iframe do
Capybara.within_frame 'stripe_checkout_app' do
我仍然得到类似的:
Capybara::Poltergeist::TimeoutError:
Timed out waiting for response to {"name":"push_frame","args":["stripe_checkout_app"]}
看来,无论我使用哪个 javascript 测试 gem,rspec/capybara 都找不到 Stripe checkout iframe。当我检查 Selenium 时,我看到按下了 Choose this Plan 按钮并弹出了 Checkout 弹出窗口,但规范在寻找要填写的电子邮件字段时超时。
有什么想法吗?
我已经试过了:
- 选择或查找电子邮件字段的各种方式。
- 更新我所有的宝石。
- 在此之前使用 StripeMock(不应该涉及它,对吧?)。
- 对 Stripe 自己的网站运行相同的测试,结果相同:
测试:
visit "https://stripe.com/docs/checkout"
click_button 'Pay with Card'
stripe_iframe = all('iframe[name=stripe_checkout_app]').last
Capybara.within_frame stripe_iframe do
fill_in 'Email', with: 'test@example.com'
sleep 3
end
根据我用来选择 iframe 的方法,我会收到相同的错误。仅使用Capybara.within_frame 'stripe_checkout_app' do:
Failure/Error: Capybara.within_frame stripe_iframe do
Capybara::Poltergeist::TimeoutError:
Timed out waiting for response to {"name":"push_frame","args":[null]}
或将 Selenium 与 stripe_iframe = all('iframe[name=stripe_checkout_app]').last 一起使用:
Failure/Error: Unable to find matching line from backtrace
SystemStackError:
stack level too deep
甚至只是:
Failure/Error: fill_in 'Email', with: 'test@example.com'
Capybara::ElementNotFound:
cannot fill in, no text field, text area or password field with id, name, or label 'Email' found
...取决于我使用的测试 javascript gem。
非常感谢任何帮助或智慧!
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 testing capybara stripe-payments