测试 RSpec XPath 问题

axiwei · December 29, 2020 · Last by axiwei replied at January 01, 2021 · 257 hits

很奇怪的问题,测试页面是否有 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 有关。

Reply to spike76

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

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

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

Reply to ThxFly

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

Reply to ThxFly

非常感谢。

axiwei closed this topic. 01 Jan 13:43
You need to Sign in before reply, if you don't have an account, please Sign up first.