尝试测试用户登录(admin)的场景,然后创建更多用户。
在日志中我可以看到控件进入登录页面然后管理员用户登录,当控件重定向到更多用户创建页面时,登录过滤器停止并将控制重定向回登录页面。
新手黄瓜所以代码质量不好,所以任何登录用户服务的测试指南都会有所帮助
这是我的scnario
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
这是deffinitions
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"
答案 0 :(得分:0)
您似乎没有事先在Given the following user information
步骤中创建管理员用户,这导致And I am logged in as author "gulled" with password "thebest"
步骤失败。
尝试使用save_and_open_page
method调试每个步骤后发生的事情。
我会按如下方式重写场景(没有太多不需要的细节):
Scenario: Add new user with multiple groups
Given I am logged in as an admin user
When I request for new lms user creation
Then a new user should be created
请查看http://aslakhellesoy.com/post/11055981222/the-training-wheels-came-off以获取有关如何编写更好方案的一些好建议。
修改强> 的
以下是我的一个项目中的step_definitions示例,用于预先创建用户并登录:
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
使用实例变量可使用户工厂对象跨步骤保持不变。并且检查步骤结束时是否存在logout
链接可确保登录确实成功。希望这有助于微调您的步骤定义。
答案 1 :(得分:0)