dj.*_*dj. 18 testing ruby-on-rails capybara ruby-on-rails-3 stripe-payments
我试图为我的Rails 3.2应用程序为Stripe的checkout.js [ https://checkout.stripe.com/checkout.js ] 编写集成测试.
手动测试(使用Stripe的测试键)时,条纹检查对我来说正常工作,但我无法让Capybara检测fill_in
到Stripe checkout iframe模式中的电子邮件字段.
我正在使用无头javascript的poltergeist,虽然也用capybara-webkit和甚至selenium测试了同样的问题.
我要测试的是完整的订阅注册流程,以显示新用户在Stripe中输入付款详细信息后可以创建订阅者帐户 - 但我无法通过Stripe checkout弹出窗口.
这是我的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 => "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
Run Code Online (Sandbox Code Playgroud)
哪个错误:
Failure/Error: Capybara.within_frame stripe_iframe do
Capybara::Poltergeist::TimeoutError:
Timed out waiting for response to {"name":"push_frame","args":[null]}
Run Code Online (Sandbox Code Playgroud)
如果我换出尝试选择正确的iframe(这里建议:Capybara麻烦填充JS模态)如下:
# stripe_iframe = all('iframe[name=stripe_checkout_app]').last
# Capybara.within_frame stripe_iframe do
Capybara.within_frame 'stripe_checkout_app' do
Run Code Online (Sandbox Code Playgroud)
我仍然得到类似的:
Capybara::Poltergeist::TimeoutError:
Timed out waiting for response to {"name":"push_frame","args":["stripe_checkout_app"]}
Run Code Online (Sandbox Code Playgroud)
看来无论我使用哪个javascript测试宝石,rspec/capybara都找不到Stripe checkout iframe.当我查看Selenium时,我看到Choose this Plan
按下的按钮和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
Run Code Online (Sandbox Code Playgroud)
根据我用来选择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]}
Run Code Online (Sandbox Code Playgroud)
或使用Selenium stripe_iframe = all('iframe[name=stripe_checkout_app]').last
:
Failure/Error: Unable to find matching line from backtrace
SystemStackError:
stack level too deep
Run Code Online (Sandbox Code Playgroud)
甚至只是:
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
Run Code Online (Sandbox Code Playgroud)
...取决于我正在使用的测试javascript gem.
非常感谢任何帮助或智慧!
jam*_*mes 10
到目前为止,我无法获得任何解决方案为我工作,然后阅读这篇文章:https://gist.github.com/nruth/b2500074749e9f56e0b7我意识到关键是要给测试添加延迟给予Stripe有足够的时间来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
Run Code Online (Sandbox Code Playgroud)
对于Capybara-webkit来说,这个sleep
技巧并没有起作用,也没有让@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
Run Code Online (Sandbox Code Playgroud)
问题解决了!
通过parov通过他的类似问题和答案[ Poltergeist Stripe checkout.js ]的一些帮助我跟踪问题到使用旧版本的Capybara'〜> 1.1.2'以及随后的各种javascript测试的依赖效应宝石(即selenium,capybara-webkit,poltergeist ......).
做一个bundle update
Capybara到2.3.0,所以把poltergeist带到1.5.1,selenium-webdriver在2.42.0和capybara-webkit在1.1.0,得到(几乎)一切正常.
对于selenium,这种通过Capybara填充JS模态的方法 确实有效:
stripe_iframe = all('iframe[name=stripe_checkout_app]').last
Capybara.within_frame stripe_iframe do
fill_in "email", with: "test-user@example.com"
...
end
Run Code Online (Sandbox Code Playgroud)
但是,这在poltergeist或capybara-webkit中不起作用.
对于恶作剧者来说,帕罗夫的建议是有效的:
stripe = page.driver.window_handles.last
page.within_window stripe do
fill_in "email", with: "test-user@example.com"
...
end
Run Code Online (Sandbox Code Playgroud)
对于capybara-webkit,我无法获得任何工作,但考虑到我有一些与恶作剧家合作的事情,我没有花太多时间去寻找一个capybara-webkit解决方案.
评论?
归档时间: |
|
查看次数: |
5747 次 |
最近记录: |