How can I test the page title with Capybara 2.0?

后端 未结 6 856
北荒
北荒 2020-11-27 05:32

Trying to test that page contains My Title with:

# spec/features/reports_spec.rb
require \'spec_helper\'

feature \"A         


        
6条回答
  •  春和景丽
    2020-11-27 06:14

    I know this has an accepted answer already, but for what it's worth, you can do the following, in less lines of code:

    title = first("head title").native.text
    expect(title).to == "What you expect it to match"
    

    This allows access to the native driver element; further, since Capybara 2.0 ignores invisible text (title is invisible except to the browser), you would need this (or a similar workaround) to satisfy this case. (See https://github.com/jnicklas/capybara/issues/863)

提交回复
热议问题