Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capybara: How to test the title of a page?

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

like image 753
Nerian Avatar asked Feb 26 '11 20:02

Nerian


People also ask

What is Capybara in testing?

Capybara is a web-based test automation software that simulates scenarios for user stories and automates web application testing for behavior-driven software development. It is written in the Ruby programming language. Capybara.


1 Answers

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" 

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" 
like image 101
Lars Schirrmeister Avatar answered Oct 11 '22 19:10

Lars Schirrmeister