功能中的 Cucumber HTML 标签

发布于 2024-11-27 16:50:43 字数 307 浏览 1 评论 0原文

我有一个黄瓜场景,我想测试 HTML 标签。

Scenario: enter words
    Given I enter "cat,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>"

这是编写这个场景的正确方法吗?

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

Scenario: enter words
    Given I enter "cat,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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

始于初秋 2024-12-04 16:50:43

您应该以简单的英语阅读您的场景。如果我不是开发人员,那么这个场景对我来说就没多大意义。你可以这样做:

Then I should see cat within a word list element

步骤是:

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

黄瓜生成器应该已经提供了 with_scope 方法,但无论如何都是这样:

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

并且只需确保将选择器添加到 features/support/selectors 中的 selectors.rb 中定位器的案例说明:

module HtmlSelectorsHelpers

  def selector_for(locator)
    case locator

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

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'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文