用黄瓜检查页面标题

Bri*_*ich 3 ruby ruby-on-rails acceptance-testing cucumber

特征

Scenario: As a user that has not signed in I want to be able to sign up for provisioner
        Given I am not logged in
        When I go to the home page
        And click on the "Sign Up" button
        Then I should be on the page with the title: "Sign Up"
        When I provide valid information
        And click the "Submit" button
        Then I should see "Account is being created and verified, you will receive an   email with instructions once account has been approved"
        And the application should send the administrator an email
        And I should be redirected to the home page as an anonymous user
Run Code Online (Sandbox Code Playgroud)

脚步

When /^I go to the home page$/ do
  visit root_path
end

When /^click on the "([^"]*)" button$/ do |page_name|
  click_link page_name
end

Then /^I should be on the page with the title: "([^"]*)"$/ do |page_title|
  response.should have_selector('title', :content => "#{page_title}")
end
Run Code Online (Sandbox Code Playgroud)

错误

expected css "title" to return something (RSpec::Expectations::ExpectationNotMetError)
Run Code Online (Sandbox Code Playgroud)

它在Then步骤失败,但是当我手动转到它时,页面会使用标题:"注册"进行渲染.我希望它能确保它在测试中找到正确的位置.我怎么检查?

在此先感谢您的所有帮助.

iaf*_*nov 6

试试这个:

page.should have_css('head title', :text => title)

  • 我使用了page.should have_selector('title',:content =>)并且它有效.谢谢! (3认同)