【发布时间】:2016-10-11 21:42:05
【问题描述】:
我正在努力做到最好 test helpers 在我的应用程序中工作。我在用 Capybara with Test::Unit 我写了一个这样的测试。
class CompaniesTest < ActionDispatch::IntegrationTest
include BestInPlace::TestHelpers
def setup
@company = companies(:public)
end
test "should have best in place fields on show" do
get company_path(@company)
assert_response :success
assert_match @company.name, response.body
bip_text( @company, :name, "new name" )
end
end
我收到这样的错误
Capybara::ElementNotFound: Unable to find css "#best_in_place_company_1001664029_name"
我尝试在 bip_text 之前添加一个 sleep(0.5) 以查看是否是时间问题,这并没有改变错误。
编辑:
<span data-bip-type="input"
data-bip-attribute="name"
data-bip-object="company"
data-bip-original-content="Lightbulbs Corp."
data-bip-skip-blur="false"
data-bip-url="/companies/1001664029"
data-bip-value="Lightbulbs Corp."
class="best_in_place"
id="best_in_place_company_1001664029_name">Lightbulbs Corp.</span>
这是测试环境中页面的 css 元素的样子。看起来id是正确的。任何帮助将不胜感激。
【问题讨论】:
-
它正在寻找 id 为 best_in_place_company_1001664029_name 的项目,但您说页面上的元素的 id 为 best_in_place_company_47_name - 所以它永远不会找到。 @company 的 id 是什么?
-
这就是为什么有(不同的公司)在那里。测试中的一家公司来自我的固定装置。 html 中的那个是我的开发数据库中使用我的开发服务器查看的种子。在 Rails 控制台测试环境中,我可以执行 Company.find(1001664029) 并返回正确的公司,因此错误中的 id 是应该在页面上找到的。
-
然后你需要查看 page.html 并在测试环境中查看它的实际内容。你在使用database_cleaner吗?您是否将其设置为使用 JS 进行测试的截断模式?您是否将 use_transactional_tests/use_transactional_fixtures 设置为 false?
-
我在测试环境中编辑了来自 Rails 服务器的 html。看起来id是正确的。我不熟悉其他可能性,我会做一些搜索。顺便说一句,感谢您的帮助,让我们有一些前进的方向。
标签: capybara ruby-on-rails-5 best-in-place