【发布时间】:2021-01-28 12:30:52
【问题描述】:
我正在使用 bundle exec rspec 运行测试,这给了我以下错误:
WARN: Screenshot could not be saved. page.current_path is empty.
也出现此错误:
1) adding a new task can re-order a task
Failure/Error: expect(page).to have_selector(".name", text: "Take Notes")
expected to find visible css ".name" with text "Take Notes" within #
<Capybara::Node::Element tag="tr" path="/HTML/BODY[1]/TABLE[1]/TBODY[1]/TR[2]"> but there were
no matches. Also found "Use Telescope", which matched the selector but not all filters.
红宝石:2.7.2 导轨:6.0.3.4
经过以下测试,我得到了错误。
这是我要测试的测试:
/spec/system/add_task_spec.rb
require "rails_helper"
RSpec.describe "adding a new task" do
let!(:project) { create(:project, name: "Project Bluebook") }
let!(:task_1) { create(
:task, project: project, title: "Search Sky", size: 1, project_order: 1) }
let!(:task_2) { create(
:task, project: project, title: "Use Telescope", size: 1,
project_order: 2) }
let!(:task_3) { create(
:task, project: project, title: "Take Notes", size: 1,
project_order: 3) }
it "can re-order a task", :js do
visit(project_path(project))
find("#task_3")
within("#task_3") do
click_on("Up")
end
expect(page).to have_selector(
"tbody:nth-child(2) .name", text: "Take Notes")
#END:P1
#START:P2
visit(project_path(project))
find("#task_2")
within("#task_2") do
expect(page).to have_selector(".name", text: "Take Notes")
end
end
end
【问题讨论】:
-
这里没有足够的信息来猜测,只是页面似乎不包含您正在寻找的元素。将您的测试代码添加到问题中,您是否检查过
page.html以查看页面中的实际内容? -
@ThomasWalpole 我添加了测试文件。你现在可以检查吗?
标签: ruby-on-rails rspec capybara rspec-rails ruby-on-rails-6