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