测试 RSpec XPath 问题

axiwei · 2020年12月29日 · 最后由 axiwei 回复于 2021年01月01日 · 257 次阅读

很奇怪的问题,测试页面是否有 head,竟然测不通!😂

expect(page).to have_selector(:xpath, "/html/head")

报错:

Failure/Error: expect(page).to have_selector(:xpath, "/html/head") expected to find visible xpath "/html/head" but there were no matches. Also found "", which matched the selector but not all filters.

难道我的页面没有 head? 可是我检查过,响应很正常,head 和 body 都是有的。

body 和 title 是可以测通的。

expect(page).to have_selector(:xpath, "/html/body")
expect(page).to have_title(@home.title + ' - ' + I18n.t('app_name'))

没写过 view 层的测试。不过怀疑可能跟 turbolinks 有关。

spike76 回复

谢谢回复。我把 JS 禁用了,还是如此。

看了下文档,目测你需要传参数 visible:false。

visible 默认是 true,不显示非可见元素。

ThxFly 回复

果然如此,我还以为这里的 visible 参数是表示 CSS 中的 visibility 属性哩!

ThxFly 回复

非常感谢。

axiwei 关闭了讨论。 01月01日 13:43
需要 登录 后方可回复, 如果你还没有账号请 注册新账号