xij*_*ijo 14 css ruby css-selectors webrat cucumber
是否可以通过它的类名而不是id,文本或标题来关注链接?鉴于我有(哈哈,黄瓜内幕他?)以下的HTML代码:
<div id="some_information_container">
<a href="edit" class="edit_button">Translation here</a>
</div>
Run Code Online (Sandbox Code Playgroud)
在Cucumber/Webrat中有什么我错过的吗?或者你有什么建议以更好的方式解决这个问题?
感谢您的帮助和问候,
乔
编辑:我发现这里有关于这个主题的有趣讨论- 现在似乎仍然是一个悬而未决的问题.你还有其他解决方案吗?
以上就是我用黄瓜做的方法,希望对你有帮助。步骤定义中的 # 有助于 CSS 理解发生了什么。
这只适用于 ID,不适用于类名
步骤定义
Then /^(?:|I )should see ([^\"]*) within a div with id "([^\"]*)"$/ do |text, selector|
# checks for text within a specified div id
within "##{selector}" do |content|
if defined?(Spec::Rails::Matchers)
content.should contain(text)
else
hc = Webrat::Matchers::HasContent.new(text)
assert hc.matches?(content), hc.failure_message
end
end
end
Run Code Online (Sandbox Code Playgroud)
特征
Scenario Outline: Create Project
When I fill in name with <title>
And I select <data_type> from data_type
And I press "Create"
Then I should see <title> within a div with id "specifications"
Scenarios: Search Terms and Results
| data_type | title |
| Books | A Book Title |
Run Code Online (Sandbox Code Playgroud)