2013-01-13 39 views
3

我有這樣的代碼在我的網頁水豚/黃瓜曖昧匹配類似的標籤

<div> 
    <label for="user_password">Heslo</label> 
    <br /> 
    <input id="user_password" name="user[password]" size="30" type="password"> 
    </div> 

    <div> 
    <label for="user_password_confirmation">Heslo pro kontrolu</label> 
    <br> 
    <input id="user_password_confirmation" name="user[password_confirmation]" size="30" type="password"> 
    </div> 

而且我想在黃瓜使用這些步驟:

And I fill in "Heslo" with "NeznameHeslo328" 
And I fill in "Heslo pro konrolu" with "NeznameHeslo328" 

步驟簡單定義是:

When /^I fill in "([^"]*)" with "([^"]*)"$/ do |name, text| 
    fill_in(name, :with => text) 
end 

但是 水豚提高模糊匹配找到2 el匹配字段「Heslo」(水豚::含糊) 第一步。

當我將標籤中的名稱更改爲for="user_password_confirmation"爲「Hesla pro kontrolu」(和相應的第二步)時,一切正常。

有沒有什麼辦法可以強迫Capybara在標籤內匹配確切的短語?在場景中不使用css選擇器。

回答

2

更新

在水豚2.1 you can use :exact option

fill_in(name, with: 'Heslo', exact: true) 

此選項默認爲


設置爲false在水豚以前的版本中,它是不可能作出準確字符串匹配。所有匹配都是使用子字符串完成的。您只能使用其他選擇器類型。

+0

感謝您的通知。我會做一些解決方法。 – Foton

0

這就是我已經開始使用的。它到目前爲止我的工作:

Given /^I fill in "([^\"]*)" with "([^\"]*)"$/ do |field_name, text| 
    page.find(field_name).set "#{text}" 
end 
+0

當你用css(field_name)搜索時,這是有用的。但情況並不正確。我認爲,場景應該來自用戶視圖。用戶看到「密碼確認」,而不是「#密碼確認」。 – Foton