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 に答える