From 0d7980e87b6123aa040984daecbcc0e91c0c69c9 Mon Sep 17 00:00:00 2001 From: Reinier Balt Date: Mon, 3 May 2010 21:26:48 +0200 Subject: [PATCH 1/2] migrate selenium for users to cucumber --- app/controllers/login_controller.rb | 2 +- app/controllers/users_controller.rb | 2 +- features/manage_project.feature | 2 +- features/manage_users.feature | 31 ++++++++++++++++++ features/step_definitions/context_steps.rb | 38 +++++++++++----------- features/step_definitions/user_steps.rb | 18 ++++++++++ features/support/paths.rb | 4 ++- test/selenium/users/delete_user.rsel | 7 ---- 8 files changed, 74 insertions(+), 30 deletions(-) create mode 100644 features/manage_users.feature delete mode 100644 test/selenium/users/delete_user.rsel diff --git a/app/controllers/login_controller.rb b/app/controllers/login_controller.rb index 0c1037ed..5106686f 100644 --- a/app/controllers/login_controller.rb +++ b/app/controllers/login_controller.rb @@ -54,7 +54,7 @@ class LoginController < ApplicationController end when :get if User.no_users_yet? - redirect_to :controller => 'users', :action => 'new' + redirect_to signup_path return end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 387c7689..1198837f 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -90,7 +90,7 @@ class UsersController < ApplicationController unless user.valid? session['new_user'] = user - redirect_to :action => 'new' + redirect_to signup_path return end diff --git a/features/manage_project.feature b/features/manage_project.feature index 5db9910e..74eaaeec 100644 --- a/features/manage_project.feature +++ b/features/manage_project.feature @@ -11,7 +11,7 @@ Feature: Manage a project And I have logged in as "testuser" with password "secret" And there exists a project "manage me" for user "testuser" - @selenium + @selenium, @wip Scenario: I can describe the project using markup When I visit the "manage me" project And I edit the project description to "_successfull outcome_: project is *done*" diff --git a/features/manage_users.feature b/features/manage_users.feature new file mode 100644 index 00000000..6d716853 --- /dev/null +++ b/features/manage_users.feature @@ -0,0 +1,31 @@ +Feature: Manage users + + In order to be able to manage the users able to use Tracks + As the administrator of this installed Tracks + I want to add and delete accounts of users + + Background: + Given the following user records + | login | password | is_admin | + | testuser | secret | false | + | admin | secret | true | + And I have logged in as "admin" with password "secret" + + Scenario: Show all accounts + When I go to the manage users page + Then I should see "testuser" + And I should see "admin" + + Scenario: Add new account + When I go to the manage users page + And I follow "Signup new user" + Then I should be on the signup page + When I submit the signup form with username "new.user", password "secret123" and confirm with "secret123" + Then I should be on the manage users page + And I should see "new.user" + + @selenium + Scenario: Delete account from users page + When I go to the manage users page + And I delete the user "testuser" + Then I should see that a user named "testuser" is not present diff --git a/features/step_definitions/context_steps.rb b/features/step_definitions/context_steps.rb index 9bab68a5..fa117871 100644 --- a/features/step_definitions/context_steps.rb +++ b/features/step_definitions/context_steps.rb @@ -2,6 +2,13 @@ Given /^I have a context called "([^\"]*)"$/ do |context_name| @context = @current_user.contexts.create!(:name => context_name) end +Given /^I have a context "([^\"]*)" with (.*) actions$/ do |context_name, number_of_actions| + context = @current_user.contexts.create!(:name => context_name) + 1.upto number_of_actions.to_i do |i| + @current_user.todos.create!(:context_id => context.id, :description => "todo #{i}") + end +end + When /^I visits the context page for "([^\"]*)"$/ do |context_name| context = @current_user.contexts.find_by_name(context_name) context.should_not be_nil @@ -14,25 +21,6 @@ When /^I edit the context name in place to be "([^\"]*)"$/ do |new_context_name| click_button "OK" end -Then /^I should see the context name is "([^\"]*)"$/ do |context_name| - Then "I should see \"#{context_name}\"" -end - -Then /^he should see that a context named "([^\"]*)" is present$/ do |context_name| - Then "I should see \"#{context_name}\"" -end - -Then /^he should see that a context named "([^\"]*)" is not present$/ do |context_name| - Then "I should not see \"#{context_name} (\"" -end - -Given /^I have a context "([^\"]*)" with (.*) actions$/ do |context_name, number_of_actions| - context = @current_user.contexts.create!(:name => context_name) - 1.upto number_of_actions.to_i do |i| - @current_user.todos.create!(:context_id => context.id, :description => "todo #{i}") - end -end - When /^I delete the context "([^\"]*)"$/ do |context_name| context = @current_user.contexts.find_by_name(context_name) context.should_not be_nil @@ -51,3 +39,15 @@ When /^I edit the context to rename it to "([^\"]*)"$/ do |new_name| selenium.is_visible("flash") end end + +Then /^I should see the context name is "([^\"]*)"$/ do |context_name| + Then "I should see \"#{context_name}\"" +end + +Then /^he should see that a context named "([^\"]*)" is present$/ do |context_name| + Then "I should see \"#{context_name}\"" +end + +Then /^he should see that a context named "([^\"]*)" is not present$/ do |context_name| + Then "I should not see \"#{context_name} (\"" +end \ No newline at end of file diff --git a/features/step_definitions/user_steps.rb b/features/step_definitions/user_steps.rb index 834bd20f..05022302 100644 --- a/features/step_definitions/user_steps.rb +++ b/features/step_definitions/user_steps.rb @@ -10,6 +10,24 @@ Given "no users exists" do User.delete_all end +When /^I delete the user "([^\"]*)"$/ do |username| + # click "//tr[@id='user-3']//img" + # assert_confirmation "Warning: this will delete user 'john', all their actions, contexts, project and notes. Are you sure that you want to continue?" + user = User.find_by_login(username) + user.should_not be_nil + + selenium.click "xpath=//tr[@id='user-#{user.id}']//img" + selenium.get_confirmation.should == "Warning: this will delete user '#{user.login}', all their actions, contexts, project and notes. Are you sure that you want to continue?" + wait_for do + !selenium.is_element_present("//tr[@id='user-#{user.id}']//img") + end + +end + +Then /^I should see that a user named "([^\"]*)" is not present$/ do |username| + Then "I should not see \"#{username} (\"" +end + Then "I should be an admin" do # just check on the presence of the menu item for managing users Then "I should see \"Manage users\"" diff --git a/features/support/paths.rb b/features/support/paths.rb index 91222396..cb895557 100644 --- a/features/support/paths.rb +++ b/features/support/paths.rb @@ -9,13 +9,15 @@ module NavigationHelpers when /the statistics page/ stats_path when /the signup page/ - "/users/new" + signup_path when /the login page/ login_path when /the notes page/ notes_path when /the contexts page/ contexts_path + when /the manage users page/ + users_path # Add more page name => path mappings here diff --git a/test/selenium/users/delete_user.rsel b/test/selenium/users/delete_user.rsel deleted file mode 100644 index 32ff3545..00000000 --- a/test/selenium/users/delete_user.rsel +++ /dev/null @@ -1,7 +0,0 @@ -setup :fixtures => :all -login :as => 'admin' -open '/users' -assert_text_present "John Deere" -click "//tr[@id='user-3']//img" -assert_confirmation "Warning: this will delete user 'john', all their actions, contexts, project and notes. Are you sure that you want to continue?" -wait_for_text_not_present "John Deere" \ No newline at end of file From e1b52aeb13b11d0b4cb5905eee7fbf63789ecae8 Mon Sep 17 00:00:00 2001 From: Reinier Balt Date: Wed, 5 May 2010 13:00:44 +0200 Subject: [PATCH 2/2] replace selenium script with cucumber story for switching recurrence option --- features/recurring_todos.feature | 25 +++++++++++++++++++ .../step_definitions/recurring_todo_steps.rb | 7 ++++++ features/support/paths.rb | 2 ++ .../switch_recurrence_options.rsel | 12 --------- 4 files changed, 34 insertions(+), 12 deletions(-) create mode 100644 features/recurring_todos.feature create mode 100644 features/step_definitions/recurring_todo_steps.rb delete mode 100644 test/selenium/recurring_todos/switch_recurrence_options.rsel diff --git a/features/recurring_todos.feature b/features/recurring_todos.feature new file mode 100644 index 00000000..98d54c82 --- /dev/null +++ b/features/recurring_todos.feature @@ -0,0 +1,25 @@ +Feature: Manage recurring todos + + In order to manage repeating todos + As a Tracks user + I want to view, edit, add, or remove recurrence patterns of repeating todos + + Background: + Given the following user record + | login | password | is_admin | + | testuser | secret | false | + And I have logged in as "testuser" with password "secret" + + @selenium + Scenario: Being able to select daily, weekly, monthly and yearly pattern + When I go to the repeating todos page + And I follow "Add a new recurring action" + Then I should see the form for "Daily" recurrence pattern + When I select "Weekly" recurrence pattern + Then I should see the form for "Weekly" recurrence pattern + When I select "Monthly" recurrence pattern + Then I should see the form for "Monthly" recurrence pattern + When I select "Yearly" recurrence pattern + Then I should see the form for "Yearly" recurrence pattern + When I select "Daily" recurrence pattern + Then I should see the form for "Daily" recurrence pattern \ No newline at end of file diff --git a/features/step_definitions/recurring_todo_steps.rb b/features/step_definitions/recurring_todo_steps.rb new file mode 100644 index 00000000..2982eb26 --- /dev/null +++ b/features/step_definitions/recurring_todo_steps.rb @@ -0,0 +1,7 @@ +When /^I select "([^\"]*)" recurrence pattern$/ do |recurrence_period| + selenium.click("recurring_todo_recurring_period_#{recurrence_period.downcase}") +end + +Then /^I should see the form for "([^\"]*)" recurrence pattern$/ do |recurrence_period| + selenium.is_visible("recurring_#{recurrence_period.downcase}") +end diff --git a/features/support/paths.rb b/features/support/paths.rb index cb895557..51edcca2 100644 --- a/features/support/paths.rb +++ b/features/support/paths.rb @@ -18,6 +18,8 @@ module NavigationHelpers contexts_path when /the manage users page/ users_path + when /the repeating todos page/ + recurring_todos_path # Add more page name => path mappings here diff --git a/test/selenium/recurring_todos/switch_recurrence_options.rsel b/test/selenium/recurring_todos/switch_recurrence_options.rsel deleted file mode 100644 index 073c0f9c..00000000 --- a/test/selenium/recurring_todos/switch_recurrence_options.rsel +++ /dev/null @@ -1,12 +0,0 @@ -setup :fixtures => :users, :clear_tables => [:projects, :contexts, :todos] -login :as => 'admin' -open "/recurring_todos" -click "css=#recurring_new_container a" -click "recurring_todo_recurring_period_daily" -assert_visible "recurring_daily" -click "recurring_todo_recurring_period_weekly" -assert_visible "recurring_weekly" -click "recurring_todo_recurring_period_monthly" -assert_visible "recurring_monthly" -click "recurring_todo_recurring_period_yearly" -assert_visible "recurring_yearly"