我试图为我的Rails 3.2应用程序的Stripe的checkout.js [https://checkout.stripe.com/checkout.js]写一个集成测试。如何在Rails上为Stripe checkout编写集成测试?
当我手动测试时(使用Stripe的测试键),条纹结帐对我来说工作正常,但我无法让Capybara检测并在条纹结帐iframe模式中检测到fill_in
电子邮件字段。
我使用骚灵无头的JavaScript,虽然也有水豚,WebKit的甚至硒同样的问题测试了。
我想要测试的是完整的订阅注册流程,以显示新用户可以在条目中输入付款详细信息后创建订阅者帐户 - 但我无法通过条带结帐弹出窗口。
这里是我的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 => "[email protected]"
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(不是它应该涉及,对吗?)。
- 运行针对条纹自己的网站相同的测试,这给了同样的错误:
测试用:
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: '[email protected]'
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: '[email protected]'
Capybara::ElementNotFound:
cannot fill in, no text field, text area or password field with id, name, or label 'Email' found
...这取决于测试我使用JavaScript的宝石。
非常感谢任何帮助或智慧!
这工作完美,但我确实增加了一点睡眠,而不是把代码放在前一个块,我把它放到实际的场景中。无论哪种方式,很好的解决方案谢谢。 –
'Capybara.default_wait_time = 2'优先于睡眠(2)' –
对我来说唯一的工作解决方案。很遗憾我需要硒来进行这项测试! – hcarreras