使用 Cucumber 测试表单提交
我为演示网站上的表单编写了一个简单的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用 Capybara 来驱动测试,“然后向我显示页面”步骤会将当前页面的 HTML 放入 tmp 文件夹中,请看一下。
“蛋糕店”的数据来自哪里?在运行测试之前您的数据库是否被重置?通常,如果您的黄瓜需要一些设置数据,最好明确说明数据存在的步骤并为每个测试插入它。例如
鉴于“蛋糕店”项目存在
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.
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