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

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

问题描述

在使用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 水豚在会话中有一些方法可以处理标题。
您有

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"

因此您可以测试标题:

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"

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

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