首页 文章

Poltergeist Stripe checkout.js

提问于
浏览
7

我正在尝试在我的Rails应用程序中测试Stripe checkout弹出窗口(http://www.stripe.com/checkout) .

我正在使用Capybara selenium-driver,一切运转良好 . 加载页面后,checkout.js会添加一个iframe,然后我就可以访问它了

within_frame('stripe_checkout_app') do
 do something
end

现在,切换到Poltergeist,我收到此错误:

失败/错误:within_frame('stripe_checkout_app')执行Capybara :: Poltergeist :: FrameNotFound:找不到框架'stripe_checkout_app' .

如果我检查页面,那就没有iframe . 所以我认为这个脚本

<script type="text/javascript" src="https://checkout.stripe.com/checkout.js"></script>

我用Poltergeist运行测试时没有加载 .

更新

我尝试用Capybara-webkit运行测试,结果相同 .

Failure/Error: Capybara.within_frame('stripe_checkout_app') do
 Capybara::Webkit::InvalidResponseError:
   Unable to locate frame.

我也试着等了半分钟!同

sleep 30

这些是我的webmock设置:

RSpec.configure { |config|
WebMock.disable_net_connect!(allow_localhost: true)
 }

更新2:

'stripe_checkout_app'是iframe的名称 .

<iframe frameborder="0" allowtransparency="true" src="https://checkout.stripe.com/v3" name="stripe_checkout_app" class="stripe_checkout_app" style="z-index: 9999; display: none; background-color: transparent; border: 0px none transparent; overflow-x: hidden; overflow-y: auto; visibility: visible; margin: 0px; padding: 0px; -webkit-tap-highlight-color: transparent; position: fixed; left: 0px; top: 0px; width: 100%; height: 100%;"></iframe>

2 回答

  • 8

    对于任何感兴趣的人,我找到了一种方法来访问iframe而不使用'within_frame',只需使用Poltergeist切换窗口方法 .

    stripe = page.driver.window_handles.last
    
    page.within_window stripe do
      fill_in "Name", :with => "Name"
      fill_in "Street", :with => "Street"
      fill_in "Postal", :with => 10000
      fill_in "City", :with => "Berlin"
    
      click_button "Payment Info"
    end
    

    对于西班牙人,我在这里找到了解决方案:numerica latina .

  • 1

    如果您对 phantomjs 1.9.7 有类似问题,那是因为SSL设置 . 您可以使用以下方法禁用检

    Capybara.register_driver :poltergeist do |app|
      options = {
        phantomjs_options: ['--ssl-protocol=any', '--ignore-ssl-errors=yes'],
        inspector: false
      }
      Capybara::Poltergeist::Driver.new(app, options)
    end
    

相关问题