Ruby   发布时间:2022-04-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了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弹出窗口,但规范超时寻找电子邮件字段填写.

有任何想法吗?

我已经尝试过:

>选择或查找电子邮件领域的各种方法.
>更新我的所有宝石.
>在此之前使用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: '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

大佬总结

以上是大佬教程为你收集整理的ruby-on-rails – 如何在Rails上编写Stripe checkout的集成测试?全部内容,希望文章能够帮你解决ruby-on-rails – 如何在Rails上编写Stripe checkout的集成测试?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。