使用 Cucumber 测试表单提交

发布于 2024-10-09 15:53:42 字数 907 浏览 2 评论 0原文

我为演示网站上的表单编写了一个简单的 Cuke 功能。该功能看起来像这样。

    Given I am on the home page
    When I set the "Start Date" to "2010-10-25"
    And I set the "End Date" to "2011-1-3"
    And I press the "Go" button
    Then I should see "Cake Shop"

这个想法是,在我按下“Go”按钮后,将加载一个新页面,显示结果列表,其中一个结果应该是“Cake Shop”。

但我还没有设法让它发挥作用。我有什么遗漏的吗?

编辑:这是步骤定义。

Given /^I am on the "([^"]*)" page$/ do |page|
  visit root_path
end

When /^I set the "([^"]*)" to "([^"]*)"$/ do |field, date|
  fill_in field, :with=>date
end

When /^I press the "([^"]*)" button$/ do |arg1|
  click_button('Go')
end

我相信最后一步是在 web_steps.rb 中定义的......而且它总是会失败。

预期 #has_content?("Cake Shop") 返回 true,结果为 false

(RSpec::期望::ExpectationNotMetError) ./features/step_definitions/web_steps.rb:110:in `阻止(2 级)在 '

I wrote a simple Cuke feature for a form on a demo site. The feature looks like this.

    Given I am on the home page
    When I set the "Start Date" to "2010-10-25"
    And I set the "End Date" to "2011-1-3"
    And I press the "Go" button
    Then I should see "Cake Shop"

The idea is that after I press the Go button, a new page will load, showing a list of results, and one of the results should be "Cake Shop."

But I have not managed to get this to work. Is there something that I am missing?

Edit: here is the step definitions.

Given /^I am on the "([^"]*)" page$/ do |page|
  visit root_path
end

When /^I set the "([^"]*)" to "([^"]*)"$/ do |field, date|
  fill_in field, :with=>date
end

When /^I press the "([^"]*)" button$/ do |arg1|
  click_button('Go')
end

The final step is defined in web_steps.rb I believe....and it's always there that it's failing.

expected #has_content?("Cake Shop") to return true, got false

(RSpec::Expectations::ExpectationNotMetError)
./features/step_definitions/web_steps.rb:110:in
`block (2 levels) in '

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

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

发布评论

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

评论(1

凝望流年 2024-10-16 15:53:42
  1. 如果您使用 Capybara 来驱动测试,“然后向我显示页面”步骤会将当前页面的 HTML 放入 tmp 文件夹中,请看一下。

  2. “蛋糕店”的数据来自哪里?在运行测试之前您的数据库是否被重置?通常,如果您的黄瓜需要一些设置数据,最好明确说明数据存在的步骤并为每个测试插入它。例如

    鉴于“蛋糕店”项目存在

  1. If you're using Capybara to drive tests the step "Then show me the page" will put the HTML of the current page in to the tmp folder, take a look at that.

  2. Where is the data "Cake shop" coming from? Is your database being reset before you run the tests? Usually if your cucumbers require some setup data it's best to explicitly state that the data exists with a step and insert it for each test. e.g.

    Given the item "Cake shop" exists

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