par*_*rov 7 ruby-on-rails capybara stripe-payments poltergeist
我正在尝试在我的Rails应用程序中测试Stripe checkout弹出窗口(http://www.stripe.com/checkout).
我使用的是Capybara + selenium-driver,一切运转良好.加载页面后,checkout.js会添加一个iframe,然后我就可以访问它了
within_frame('stripe_checkout_app') do
do something
end
Run Code Online (Sandbox Code Playgroud)
现在,切换到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.
Run Code Online (Sandbox Code Playgroud)
我也试着等了半分钟!同
sleep 30
Run Code Online (Sandbox Code Playgroud)
这些是我的webmock设置:
RSpec.configure { |config|
WebMock.disable_net_connect!(allow_localhost: true)
}
Run Code Online (Sandbox Code Playgroud)
更新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>
Run Code Online (Sandbox Code Playgroud)
对于任何感兴趣的人,我找到了一种方法来访问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
Run Code Online (Sandbox Code Playgroud)
对于西班牙人,我在这里找到了解决方案:numerica latina.
| 归档时间: |
|
| 查看次数: |
1564 次 |
| 最近记录: |