0

我有一个页面,我想要几个其他项目中的几个项目。所以基本上我的功能可能是这样的:

Scenario: Footer has caption Impressum
  Given I am on the index page.
  When I look at the footer
  Then I should see a caption "Impressum"

我希望工作的是:

When /I look at the footer/ do
  scope("footer") # << css selector <footer\b.*</footer>
end

Then /I should see a caption "(.*?)"/ do |caption|
  within "h3" do
    page.should have_content(caption)
  end
end

我怎样才能尽可能可靠地实现这一点?

更详细地说,应该通过的页面是这样的:

<html>
<head></head>
<body>
<footer>
<h3>Impressum</h3>
<p>Address: Baker Street 21</p>
</footer>
</body>
</html>

虽然应该通过的页面是这样的:

<html>
<head></head>
<body>
<h3>Impressum</h3>
<footer><p>Address: Baker Street 21</p></footer>
</body>
</html>
4

3 回答 3

3

这是我要做的:

When /I look at the footer/ do
  # save a scope that should be used in a 'within' block
  @scope = "footer" # << css selector <footer\b.*</footer>
end

Then /I should see a caption "(.*?)"/ do |caption|
  # use the scope set above, or don't if it's not set
  within "#{@scope || ''} h3" do
    page.should have_content(caption)
  end
end
于 2013-10-04T21:13:26.037 回答
0

我的解决方案是使用助手

# features/support/scope_helper.rb
module ScopeHelper
  def scope sel = nil
    @scope = sel if sel
    within @scope, &Proc.new if block_given?
  end
end
World(ScopeHelper)

然后,我像这样使用它:

When /^I look at the footer$/ do
  scope 'footer'
end

Then /^I should see a caption "(.*)"$/ do |caption|
  scope{ find('h3').should have_content(caption) }
end
于 2014-03-17T10:31:26.607 回答
0

对于这种依赖,我也遇到了类似的挑战。就我而言,我有一个表格,并想单击特定行的删除链接。我找不到合适的解决方案,所以我决定用一句话来做:

When I search for the row containing «Beverly C. Crusher» and click on «Delete Task»
于 2019-03-27T12:08:51.430 回答