Ruby on rails 使用cucumber检查页面标题
功能Ruby on rails 使用cucumber检查页面标题,ruby-on-rails,ruby,cucumber,acceptance-testing,Ruby On Rails,Ruby,Cucumber,Acceptance Testing,功能 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 tit
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)
在然后步骤失败,但是当我手动转到页面时,页面会显示标题:“注册”。我希望它能确保它在测试中的正确位置。我怎么检查
提前感谢您的帮助。试试这个:
page.应该有_css('head title',:text=>title)
这可能发生,因为默认情况下,水豚选择器设置为css
尝试将其更改为
response.should have_xpath('//title', :text => "#{page_title}")
从2.1开始,您可以这样做:
expect(第页)。如果您使用的是cucumber rails gem,请尝试使用
assert page.has_title?(page_title), "page has title of '#{page.title}'"
没关系-如果你是,试试@Bohdan Pohorilets的答案。我使用了页面。应该有_选择器('title',:content=>),它成功了。谢谢这需要rspec。这需要您使用rspec。