When /^(?:|I)follow "([^"]*)"(?: within "([^"]*)")?$/ do |link, selector|
with_scope(selector) do
click_link(link)
end
end
这是我从拨打:
Background:
Given I am an existing admin user
When I follow "CLIENTS"
我的HTML是这样的:
<a class="active" href="/companies"><h2>CLIENTS</h2></a>
,我不断收到此错误:
.F-.F--U-----U
(::) failed steps (::)
no link with title, id or text 'CLIENTS' found (Capybara::ElementNotFound)
(eval):2:in `click_link'
./features/step_definitions/web_steps.rb:54:in `block (2 levels) in <top (required)>'
./features/step_definitions/web_steps.rb:14:in `with_scope'
./features/step_definitions/web_steps.rb:53:in `/^(?:|I)follow "([^"]*)"(?: within "([^"]*)")?$/'
features/client_add.feature:8:in `When I follow "CLIENTS"'
我想从几件事情:
When I follow "<h2>CLIENTS</h2>"
,甚至试图将save_and_open_page
应该打开浏览器,仍然得到同样的结果:
Given /^I am an existing admin user$/ do
role_user = FactoryGirl.create(:role_user)
admin_user = role_user.user
sign_in(admin_user)
save_and_open_page
end
有没有一种方法来打印HTML或某种方式弄清楚为什么我的测试失败了?
使用capybara的save_and_open_page,如http://berk.es/2013/01/08/make-cucumber-open-the-browser-with-the-current-page/ – deepak 2014-04-15 09:22:55
上给出的也使用pry_remote(https:/ /github.com/Mon-Ouie/pry-remote)在功能测试中进行调试。可能需要睡觉,以便在规范中不发生超时 – deepak 2014-04-15 09:26:48