【问题标题】:Using cucumber to check page titles使用黄瓜检查页面标题
【发布时间】:2011-07-27 05:23:09
【问题描述】:

功能

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

步骤

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

错误

expected css "title" to return something (RSpec::Expectations::ExpectationNotMetError)

它在 然后 步骤失败,但是当我手动转到该页面时,该页面确实呈现标题:“注册”。我希望它确保它在测试中进入正确的位置。如何检查?

提前感谢所有帮助。

【问题讨论】:

  • 没关系——如果你是,试试@Bohdan Pohorilets 的回答。

标签: ruby-on-rails ruby cucumber acceptance-testing


【解决方案1】:

试试这个:

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

【讨论】:

  • 我使用了 page.should have_selector('title', :content =>) 并且它有效。谢谢!
  • 这需要 rspec。
【解决方案2】:

从 2.1 开始,您可以这样做:

expect(page).to have_title "my_title"

【讨论】:

  • 这要求您使用 rspec。
【解决方案3】:

这可能会发生,因为默认情况下水豚选择器设置为 CSS 尝试将其更改为

response.should have_xpath('//title', :text => "#{page_title}")

【讨论】:

    【解决方案4】:

    如果您使用的是 cucumber-rails gem,请尝试使用

    assert page.has_title?(page_title), "page has title of '#{page.title}'"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多