开发者

Cucumber HTML tag in feature

I have a cucumber scenario where I wan to test for an HTML tag.

Scenario: enter words
    Given I enter "c开发者_C百科at,dog"
    When I set tag to "li" and the class to "word"
    Then I should see "<li class=\"word\">cat</li>"
    And I should see "<li class=\"word\">dog</li>"

Is this the correct way to write this scenario?


You should aim to have your scenario's read in plain english. If I weren't a developer then the scenario wouldn't make much sense to me. You could do something like this:

Then I should see cat within a word list element

The step for this would be:

Then /^(?:|I )should see "([^"]*)" within (.*)$/ do |text, parent|
  with_scope(parent) do
    if page.respond_to? :should
      page.should have_content(text)
    else
      assert page.has_content?(text)
    end
  end
end

The cucumber generator should already provide the with_scope method but here it is anyways:

module WithinHelpers
  def with_scope(locator)
    locator ? within(*selector_for(locator)) { yield } : yield
  end
end
World(WithinHelpers)

And just be sure to add the selector to your selectors.rb in features/support/selectors inside the case statement for locator:

module HtmlSelectorsHelpers

  def selector_for(locator)
    case locator

    when ' a word list element'
      'li.word'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜