Cucumber 场景会话中的cumber不会持续存在
尝试获取测试用户登录(admin)的场景,然后创建更多用户 在日志中,我可以看到控件转到登录页面,然后管理员用户登录,当控件重定向到其他用户创建页面时,登录过滤器会停止并将控件重定向回登录页面 在cucumber中是新手,所以代码质量不好,所以任何关于测试登录用户服务的指南都会很有帮助 这是我的scnarioCucumber 场景会话中的cumber不会持续存在,cucumber,Cucumber,尝试获取测试用户登录(admin)的场景,然后创建更多用户 在日志中,我可以看到控件转到登录页面,然后管理员用户登录,当控件重定向到其他用户创建页面时,登录过滤器会停止并将控件重定向回登录页面 在cucumber中是新手,所以代码质量不好,所以任何关于测试登录用户服务的指南都会很有帮助 这是我的scnario Feature: Create user from LMS In order to create lms user with multiple groups As a author
Feature: Create user from LMS
In order to create lms user with multiple groups
As a author
I want to create lms user with multipl groups
Scenario: Add new user with multiple groups
Given the following user information
And I am logged in as author "gulled" with password "thebest"
When I request for new lms user creation
Then the new user "user1" should be created
这是定义
Given /^the following user information$/ do
# Factory(:login)
# Factory(:author)
end
Given /^I am logged in as author "([^"]*)" with password "([^"]*)"$/ do |username, password|
visit "account/login"
fill_in "loginfield", :with => username
fill_in "password", :with => password
click_button "submit_button"
end
When /^I request for new lms user creation$/ do
visit "/author_backend_lms/new_user"
fill_in "login_first_name", :with => ""
fill_in "login_last_name", :with => ""
fill_in "login_login", :with => ""
fill_in "login_email", :with => ""
fill_in "login_password_confirmation", :with => ""
click_button "create_user_form_submit_button"
end
Then /^the new user "([^"]*)" should be created$/ do |user_login|
login = Login.find_by_login user
assert_no_nil login, "Record creation failed"
end
在“新lms用户创建请求”中,当尝试访问lms用户创建页面时,控件重定向回登录页面
这是我要测试的宝石清单
gem "capybara", "1.1.1"
gem "cucumber", "1.1.0"
gem "cucumber-rails", "0.3.2"
鉴于以下用户信息,您似乎没有在
步骤中预先创建管理员用户,这使得和我作为作者“gulled”登录,密码为“thebest”
步骤失败
尝试使用调试每个步骤后发生的事情
我将按照以下方式重写场景(没有太多不需要的细节):
请查看一些关于如何编写更好的场景的好建议
编辑
下面是我的一个项目中的一个步骤定义示例,用于预先创建用户并登录:
Given /^the user has an account$/ do
@user = FactoryGirl.create( :user )
end
When /^the user submits valid signin information$/ do
fill_in "user_email", with: @user.email
fill_in "user_password", with: @user.password
click_button "Sign in"
page.should have_link('Logout', href: destroy_user_session_path)
end
使用实例变量可以使用户工厂对象跨步骤持久化。并检查步骤结束时是否存在注销链接,以确保登录确实成功。希望这有助于微调您的步骤定义。我有一个示例项目,演示了使用Cucumber做这类事情的更好(IMO)方法。我想它可能会提供你要求的一些指导
希望它有用yes更改代码,但仍然失败,在第一步中,用户登录并且在执行“when”案例时,身份验证系统引发错误处理AuthorBackendContentController#index[GET]{“action”=>“index”,“controller”=>“author\u backend\u content”}重定向到过滤器链,由于[:login\u required]渲染或重定向。[请求页面:GET重定向到example.com/account/login
=>看起来用户登录未成功。是否使用save_and_open_PAGE
调试问题?是使用了它,并且在每一步中它都保持不变(显示)登录页面。因此用户登录不成功。看起来您不是使用name=>“gulled”
和password=>“thebest”
创建用户/作者,而是尝试使用这些凭据登录。编辑了答案以包含示例;希望对您有所帮助。
Given /^the user has an account$/ do
@user = FactoryGirl.create( :user )
end
When /^the user submits valid signin information$/ do
fill_in "user_email", with: @user.email
fill_in "user_password", with: @user.password
click_button "Sign in"
page.should have_link('Logout', href: destroy_user_session_path)
end