Capybara 和 Rails,为什么是 has_link?总是返回 false?

发布于 2024-12-27 01:22:48 字数 479 浏览 2 评论 0原文

我正在尝试使用 has_link 进行测试?在我的规范测试中,这是我的测试:

page.has_link?('next_page', {}).should == true

但是,测试总是失败,尽管 id 为“next_page”的链接存在! 奇怪的是,have_content 总是工作正常,这是我实现它的方法:

page.should have_content("some text")

你能帮我吗?我在这里缺少什么?

编辑

这是页面中生成的链接:

<a id="next_page" href="javascript: void(0)" onclick="javascript: void(0)" style="color: #888888">Next</a>

I am trying to test with has_link? in my spec test, here is my test:

page.has_link?('next_page', {}).should == true

but, the test always fail, although the link with id 'next_page' dose exist!
the strange thing is that have_content always works fine, here is how I implement it:

page.should have_content("some text")

Can you help me please ? what I am missing here ?

EDIT

Here is the resulted link in the page:

<a id="next_page" href="javascript: void(0)" onclick="javascript: void(0)" style="color: #888888">Next</a>

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

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

发布评论

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

评论(3

假面具 2025-01-03 01:22:48

我认为你应该这样做:

page.has_link? “next_page”

还是

page.has_link? “下一页”,url_path

I think you should do :

page.has_link? "next_page"

or

page.has_link? "next_page", url_path

征棹 2025-01-03 01:22:48

您可以尝试下面的示例 -

it "should have logout link" do
  expect(page).to have_link('Logout') 
end 

You can try below sample -

it "should have logout link" do
  expect(page).to have_link('Logout') 
end 
屋顶上的小猫咪 2025-01-03 01:22:48

我这样做是:

rendered.should have_link("Teams", :href => teams_path)

I do this with:

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