Capybara:如何测试页面的标题? [英] Capybara: How to test the title of a page?

查看:17
本文介绍了Capybara:如何测试页面的标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用 Steak、Capybara 和 RSpec 的 Rails 3 应用程序中,我如何测试页面的标题?

In a Rails 3 application using Steak, Capybara and RSpec how do I test the page's title?

推荐答案

2.1.0 版本开始,在 session 上有处理标题的方法.你有

Since the version 2.1.0 of capybara there are methods on the session to deal with the title. You have

page.title
page.has_title? "my title"
page.has_no_title? "my not found title"

所以你可以像这样测试标题:

So you can test the title like:

expect(page).to have_title "my_title"

根据 github.com/jnicklas/capybara/issues/863 以下是还使用水豚 2.0:

According to github.com/jnicklas/capybara/issues/863 the following is also working with capybara 2.0:

expect(first('title').native.text).to eq "my title"

这篇关于Capybara:如何测试页面的标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆