[英]Regular expressions in cucumber steps
黃瓜產生了一些整潔的webrat正則表達式步驟。 我嘗試這個時遇到了一個問題。
在功能上:
And I fill in "Telephone (Home)" with "61234567"
在webrat步驟中:
When /^I fill in "([^\"]*)" with "([^\"]*)"$/ do |field, value|
fill_in(field, :with => value)
end
遇到的錯誤:
Could not find field: "Telephone (Home)" (Webrat::NotFoundError)
似乎“ Home”之間的括號給了問題。 如何調整正則表達式以說明括號?
更新:
似乎正則表達式不是問題,因為“ field ”實例變量確實產生了“ Telephone(Home)”。 真正的問題是webrat的“ fill_in ”方法解析字段變量的方式。
如果只想捕獲“電話”,請嘗試以下操作:
/^I fill in "(\w+).*?" with "([^\"]*)"$/
如果是“家”,您可以嘗試以下方法:
/^I fill in "(?:.*?\()?(.+?)\)?" with "([^\"]*)"$/;
這在字段“(注銷)”中也遇到了我...
您可以要求輸入id字段嗎?
fill_in("user_telephone_home", :with => data)
我在將標簽與webrat中的字段匹配時遇到了類似的問題,並且我想到了此代碼段,該代碼段使用於將標簽與字段匹配的正則表達式松開了。 也許它將幫助您。
我在我的features/support/env.rb
有這個
module Webrat
module Locators
class FieldLabeledLocator < Locator
def matching_label_elements_with_numbering
label_elements.select do |label_element|
text(label_element) =~ /^.*#{Regexp.escape(@value.to_s)}.*$/i
end
end
alias_method_chain :matching_label_elements, :numbering
end
end
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.