2013-01-13 39 views
1

試圖讓測試方案,其中用戶登錄(管理員),然後再創建用戶。黃瓜中的情景會話不堅持

在日誌中我可以看到,控制進到登錄頁面,然後管理員用戶登錄時,當控制重定向到另外的用戶創建頁面登錄過濾得到暫停,改變運行回到登錄頁面。

新手黃瓜這樣的代碼是不是在質量好,所以登錄的用戶服務測試的任何指導,將有助於

這裏是我的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

看起來你是不是在Given the following user information一步,這使得And I am logged in as author "gulled" with password "thebest"一步失敗創建admin用戶提前。

嘗試使用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鏈接確保登錄確實成功。希望這有助於微調你的步驟定義。

+0

是改變代碼的指導,但仍然失敗,在第一步用戶在獲取記錄並在「何時」下執行的認證系統引發錯誤 處理AuthorBackendContentController#index [GET] {「action」=>「index」,「controller」=>「author_backend_content」} 重定向到http://www.example.com/account/login 過濾器鏈停止爲[:login_required] rendered_or_redirected。 [http://www.example。com/author_backend_content] 請求頁面:獲取http://www.example.com/account/logi – Gull

+0

'重定向到example.com/account/login' =>看起來用戶登錄沒有成功。你使用'save_and_open_page'來調試這個問題嗎? –

+0

是使用它,並在每一步它保持(顯示)登錄頁面。 – Gull

0

我有使用說明黃瓜做這樣的事情的更好(IMO)方式的示例項目。我想這可能提供一些你問

see here

希望它有用