我在编写Cucumber测试时遇到问题。通过Paylane付款后(不知何故只有Paylane方案存在问题; Paypal,Stripe和Payu工作正常)当它开启时,感谢你'页面看起来像Capybara点击按钮(返回商店)它在浏览器中突出显示但它没有做任何事情。此外,它进入下一步并检查它是否在商店页面上,因此它认为点击按钮进展顺利(我想)。有人可以帮我吗?
@lp @purchase @paylane @javascript
Feature: Purchase a product from a Landing Page via Paylane
As a Sneakpick user
I can access Landing Pages of product
So I can successfully purchase it via Paylane
Scenario: Purchase product via Paylane # features/purchases/landing_page/paylane.feature:7
Given I visit the Landing Page # features/step_definitions/basic_steps.rb:5
Then I want to order 1 product # features/step_definitions/purchase_steps.rb:92
And product is available via Paylane # features/step_definitions/purchase_steps.rb:1
DEPRECATION WARNING: Passing a template handler in the template name is deprecated. You can simply remove the handler name or pass render :handlers => [:erb] instead. (called from _app_views_paylane_pay_html_erb___1015711955565910954_70249561011280 at /home/szczepan/1000i/Git/sneakpick/app/views/paylane/pay.html.erb:2)
Then I go to payment # features/step_definitions/purchase_steps.rb:53
And I pay via Paylane # features/step_definitions/paylane_steps.rb:1
expected to find text "Product" in "Payment - Sneakpick.co Thank You! Your order has been processed. We've sent you a confirmation emailwith your order details. « Back to product powered by sneakpick" (RSpec::Expectations::ExpectationNotMetError)
./features/step_definitions/purchase_steps.rb:77:in `/^I am on Landing page$/'
./features/step_definitions/paylane_steps.rb:2:in `/^I pay via Paylane$/'
features/purchases/landing_page/paylane.feature:12:in `And I pay via Paylane'
And my Paylane order should be made # features/step_definitions/paylane_steps.rb:76
Scenario: Purchase product via Paylane # features/purchases/landing_page/paylane.feature:15
Given I visit the Landing Page # features/step_definitions/basic_steps.rb:5
Then I want to order 1 product # features/step_definitions/purchase_steps.rb:92
And product is available via Paylane # features/step_definitions/purchase_steps.rb:1
DEPRECATION WARNING: Passing a template handler in the template name is deprecated. You can simply remove the handler name or pass render :handlers => [:erb] instead. (called from _app_views_paylane_pay_html_erb___1015711955565910954_70249561011280 at /home/szczepan/1000i/Git/sneakpick/app/views/paylane/pay.html.erb:2)
Then I go to payment # features/step_definitions/purchase_steps.rb:53
And I pay via Paylane not with card successfully # features/step_definitions/paylane_steps.rb:13
And my Paylane order should be made # features/step_definitions/paylane_steps.rb:76
哦,第二个工作正常,但第一个没有,但他们点击相同的按钮。 以下是步骤:
And /^I pay via Paylane$/ do
steps %(
And I check if Paylane form is filled with correct data
And I fill in the card data
And I send form
And I accept confirmation alert
And I am on Thank You page
And I click 'Back to product' button
And I am on Landing page
)
end
And /^I pay via Paylane not with card successfully$/ do
steps %(
And I choose last available payment
And I send form
And I accept confirmation alert
And I click 'SUCCESS' button
And I am on Thank You page
And I click 'Back to product' button
And I am on Landing page
)
end
并且"我点击(。+)按钮"步骤:
And /^I click '(.+)' button$/ do |button|
click_on(button)
end
该按钮包含文字"返回产品"。
任何帮助将不胜感激!
答案 0 :(得分:0)
对此的一个典型解决方案(至少在Ruby-Cucumber中)是一个简单的方法,如wait_for_ajax
- 基本上,它会阻塞,直到它注册到没有更多活动的HTTP调用,然后再继续。这通常在Capybara中作为来自步骤定义的函数调用完成。每当你期望必须等待(特别是在第三方页面上)时,请在整个步骤中自由地使用它,特别是在你采取行动(比如点击某些东西)之后。它比在预定的时间内调用sleep()
更可靠。
def wait_for_ajax
Timeout.timeout(Capybara.default_max_wait_time) do
loop until finished_all_ajax_requests?
end
end
def finished_all_ajax_requests?
page.evaluate_script('jQuery.active').zero?
end
来源:Thoughtbot原始源代码(已经有一段时间了)以及修复不可靠的Capybara / Cucumber测试套件的个人经验。
此外,我上次检查过,不推荐使用Capybara中的steps%(...)
语法,您应该使用step '...'
调用单个步骤。它可以让你更像是函数调用来处理你的步骤(对于这种事情)。