Cucumber:找到带有标签文本 X 的输入? [英] Cucumber: find the input with label text X?
问题描述
在 Cucumber 中,我正在尝试创建这样的步骤:
In Cucumber, I'm trying to create a step like this:
Then I should see "Example business name" in the "Business name" input
我希望将企业名称"输入定义为标签包含文本企业名称"的输入.
I'd like the "Business name" input to be defined as "the input whose label has text "Business name."
到目前为止,这是我在这一步所做的:
Here's what I've got on the step so far:
Then /^I should see "([^"]*)" in the "([^"]*)" input$/ do |content, labeltext|
# Not sure what to put here
end
在 jQuery 中,我会查找带有该文本的标签,查看其for"属性,然后找到带有该 id 的输入.但到目前为止,我在 Cucumber 中看到的唯一选择器是这些:
In jQuery, I'd look for the label with that text, look at its "for" attribute, and find the input with that id. But the only selectors I've seen so far in Cucumber are these:
within("input:nth-child(#{pos.to_i}")
和
page.should have_content('foo')
谁能建议使用 Webrat/Capybara 选择器语法的解决方案?
Can anybody suggest a solution using the Webrat / Capybara selector syntax?
推荐答案
想通了
您可以使用 find_field(labeltext)
通过其标签文本查找输入.
Figured it out
You can find an input by its label text using find_field(labeltext)
.
# Example:
# 'I should see "Howdy" in the "Greeting" input' ("Greeting" is the label text)
Then /^I should see "([^"]*)" in the "([^"]*)" input$/ do |content, labeltext|
find_field("#{labeltext}").value.should == content
end
这篇关于Cucumber:找到带有标签文本 X 的输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!