gpt4 book ai didi

ruby-on-rails - 检查 cucumber 测试中的网页内容

转载 作者:行者123 更新时间:2023-12-04 16:35:50 25 4
gpt4 key购买 nike

我开始探索 BDD 和 Cucumber。所以我想检查我的页面是否显示了我拥有的 2 篇文章的内容。这是我正在使用的检查内容是否存在的步骤:

Then /^I should see "([^"]*)"$/ do |desc|
page.should have_content desc

expected = Article.find_by_description(desc)
page.should have_content(expected.navision_code)
page.should have_content(expected.category.name)
end

通常这应该可以解决我的问题,但是当我运行测试时我收到了这个错误消息:

expected there to be content "---\n- tenetur\n" in "Alfa Paints Order System\n\n\n\nAlfa Paints\n\n\n\nSeth abernathy, admin\n\n\nVerander paswoord\n\nLogout\n\n\n\n\n\n\n\n\n\n\n\nAlfa Paints\nordering system\n\n\n\n\n\nOverzicht van alle artikelen\n\n\n\nBack\n\n\n\n\n\n\nProduct ID\nBeschrijving\nCategorie\n3001\nPaint\n---\n- tenetur\n\n3002\nBrush\n---\n- tenetur\n\n\n\n\n\n\n\n\n\n\n
(RSpec::Expectations::ExpectationNotMetError)
./features/step_definitions/admin_articles_steps.rb:41:in `/^I should see "([^"]*)"$/'
features/admin_articles.feature:10:in `Then I should see "Paint"'

如您所见,我期待绘画,错误消息显示内容中有绘画。但不知何故, cucumber 无法识别它。

我是 cucumber 的新手,我可能遗漏了一些东西,但也许有人可以帮助我。

最佳答案

您同时测试三件事,因此很难判断哪个期望失败了。第一步,尝试注释掉除第一个期望之外的所有内容,以确保它在您认为的地方失败。

Then /^I should see "([^"]*)"$/ do |desc|
page.should have_content desc

// expected = Article.find_by_description(desc)
// page.should have_content(expected.navision_code)
// page.should have_content(expected.category.name)
end

如果您仍然遇到同样的问题,请添加调试器,以便您可以进行试验并查看测试环境中发生的情况。如果您计划进行大量 cucumber 测试,这是一项值得培养的技能。

Then /^I should see "([^"]*)"$/ do |desc|
debugger
page.should have_content desc
end

从调试控制台,查看 desc 变量和页面的样子:

p desc
p page.content

关于ruby-on-rails - 检查 cucumber 测试中的网页内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10986388/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com