Cucmber测试了一个按钮按下,但没有成功更新页面



我正在我的rails应用程序上运行cumber测试。我正试着按一下按钮登录到一个页面。在测试中,我完成了登录步骤,按下按钮,然后检查文本,看看它是否与按下按钮后页面上的内容匹配。我运气不好

html代码看起来像

<% provide(:title, "Log in") %>
<h1>Log in</h1>
<h2>Note: authentication currently supports both a TAMU NetID or the use of CAS.</h2>
<h2>To access the CAS authentication system, click <%= link_to "here", new_member_session_path %></h2> <br />
<div class="row">
<div class="col-md-6 col-md-offset-3">
<%= form_for(:session, url: login_path) do |f| %>
<%= f.label :netid %>
<%= f.text_field :username, class: 'form-control' %>
<%= f.submit "Log in", class: "btn btn-primary" %>
<% end %>
</div>
</div>

我的测试看起来像

Given I am logged in as an admin user
And I should see "admin@member.com"
And I should see "Test Member"
And I should see "Create Member"
And I should see "Create Committee"

在我的Web步骤文件中使用此步骤

Given(/^I am logged in as an admin user$/) do    
visit '/sessions/new'
page.should have_content('Log in')
page.should have_content('Note: authentication currently supports both a TAMU NetID or the use of CAS.')
page.should have_content('To access the CAS authentication system, click here')
fill_in 'session_username' , :with => 'admin'
click_button 'Log in'
expect(page).to have_content 'Admin Member'

结束

但我一直收到这个错误

expected to find text "Admin Member" in "MembershipHubnHome About Help LoginnNo member found with that NetIDnLog innNote: authentication currently supports both a TAMU NetID or the use of CAS.nTo access the CAS authentication system, click herenNetidnAbout Help Members SEC Main Site RegistrationHub FinanceHub (Alpha)" (RSpec::Expectations::ExpectationNotMetError)
./features/step_definitions/web_steps.rb:140:in `/^(?:|I )should see "([^"]*)"$/'
features/IterationTwo_adminMember_testing.feature:6:in `Then I should see "Admin Member"'

它显示的文本实际上在登录页面上。我不知道为什么按下登录按钮后我看不到页面。

正如评论中所讨论的,这里的问题是以身份登录的用户不存在,因为在运行测试之前还没有设置测试所需的数据。这些数据需要在测试数据库中初始化(通常使用Rails fixture或factory_bot等工厂工具(。

最新更新