ruby-on-rails – 如何在Rails上编写Stripe checkout的集成测试
我试图为Stripe的checkout.js [
https://checkout.stripe.com/checkout.js]为我的Rails 3.2应用程序编写一个集成测试.
当我手动测试(使用Stripe的测试键)时,条形码检查可以正常工作,但是我无法让Capybara在Stripe checkout iframe模式中检测并填写电子邮件字段. 我正在使用poltergeist无头的JavaScript,虽然也已经用capybara-webkit甚至硒测试了同样的问题. 我试图测试的是完整的订阅注册流程,以显示新用户可以在条形码中输入付款详细信息后创建订户帐户,但是我无法通过条形码结算弹出窗口. 这是我以前..做: 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测试宝石,rspec / capybara都找不到Stripe checkout iframe.当我检查Selenium我看到选择这个计划按钮和Checkout弹出窗口,但规范超时寻找电子邮件字段填写. 有任何想法吗? 我已经尝试过: >选择或查找电子邮件领域的各种方法. 测试与: 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’做: Failure/Error: Capybara.within_frame stripe_iframe do Capybara::Poltergeist::TimeoutError: Timed out waiting for response to {"name":"push_frame","args":[null]} 或使用带有stripe_iframe = all(‘iframe [name = stripe_checkout_app]’)的Selenium.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宝石. 任何帮助或智慧非常感谢! 解决方法
我无法得到这里的任何解决方案到目前为止为我工作,然后阅读这篇文章:
https://gist.github.com/nruth/b2500074749e9f56e0b7我意识到关键是添加一个延迟测试给条纹足够的时间1)加载结帐窗口和2)处理令牌.
因为这个原因,我可以上班的唯一代码是这样(随时随地玩): 硒 describe "test stripe" do,js: true,driver: :selenium do before do ... # fill in order form or whatever click_button "checkout_with_stripe" sleep(2) # allows stripe_checkout_app frame to load stripe_iframe = all('iframe[name=stripe_checkout_app]').last Capybara.within_frame stripe_iframe do page.execute_script(%Q{ $('input#email').val('jamesdd9302@yahoo.com'); }) page.execute_script(%Q{ $('input#card_number').val('4242424242424242'); }) page.execute_script(%Q{ $('input#cc-exp').val('08/44'); }) page.execute_script(%Q{ $('input#cc-csc').val('999'); }) page.execute_script(%Q{ $('#submitButton').click(); }) sleep(3) # allows stripe_checkout_app to submit end end it "should successfully process the request" do ... # test should pass end end 对于Capybara-webkit来说,睡眠技巧并没有像Ryan的解决方案那样无动于衷,我也厌倦了试图解决这个问题,所以我刚刚停下来,但希望别人能够得到它,因为我宁愿使用webkit速度的原因! (我使用的是capybara-webkit 1.3.0) 如果有帮助,这里是我的相关版本: selenium-webdriver 2.35.1 rspec-rails 2.14.2 capybara 2.1.0 stripe 1.16.0 da216fd rails 4.1.1 ruby 2.1.2 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |