From aaf7e693228a0f21509cec0f6b01041774bd0912 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sun, 22 Feb 2015 17:07:38 +0100 Subject: [PATCH] Improved speed of tests. --- .../signup_password_change_and_reset_test.rb | 623 +++++++----------- 1 file changed, 248 insertions(+), 375 deletions(-) diff --git a/test/browser/signup_password_change_and_reset_test.rb b/test/browser/signup_password_change_and_reset_test.rb index bbd67271f..97ded50e1 100644 --- a/test/browser/signup_password_change_and_reset_test.rb +++ b/test/browser/signup_password_change_and_reset_test.rb @@ -4,381 +4,254 @@ require 'browser_test_helper' class SignupPasswordChangeAndResetTest < TestCase def test_signup signup_user_email = 'signup-test-' + rand(999999).to_s + '@example.com' - tests = [ - { - :name => 'start', - :instance => browser_instance, - :url => browser_url, - :action => [ - { - :execute => 'click', - :css => 'a[href="#signup"]', - }, - { - :execute => 'check', - :css => '.signup', - :result => true, - }, - ], - }, - { - :name => 'signup', - :action => [ - { - :execute => 'set', - :css => 'input[name="firstname"]', - :value => 'Signup Firstname', - }, - { - :execute => 'set', - :css => 'input[name="lastname"]', - :value => 'Signup Lastname', - }, - { - :execute => 'set', - :css => 'input[name="email"]', - :value => signup_user_email, - }, - { - :execute => 'set', - :css => 'input[name="password"]', - :value => 'some-pass', - }, - { - :execute => 'set', - :css => 'input[name="password_confirm"]', - :value => 'some-pass', - }, - { - :execute => 'click', - :css => 'button.submit', - }, - { - :execute => 'wait', - :value => 5, - }, - { - :execute => 'check', - :css => '.signup', - :result => false, - }, - { - :execute => 'match', - :css => '.user-menu .user a', - :attribute => 'title', - :value => signup_user_email, - :match_result => true, - }, - ], - }, - { - :name => 'set password', - :action => [ - { - :execute => 'click', - :css => '.navbar-items-personal .user a', - }, - { - :execute => 'wait', - :value => 1, - }, - { - :execute => 'click', - :css => 'a[href="#profile"]', - }, - { - :execute => 'click', - :css => 'a[href="#profile/password"]', - }, - { - :execute => 'set', - :css => 'input[name="password_old"]', - :value => 'nonexisiting', - }, - { - :execute => 'set', - :css => 'input[name="password_new"]', - :value => 'some', - }, - { - :execute => 'set', - :css => 'input[name="password_new_confirm"]', - :value => 'some', - }, - { - :execute => 'click', - :css => '.content .btn--primary', - }, - { - :execute => 'watch_for', - :area => 'body', - :value => 'current password is wrong', - }, - { - :execute => 'set', - :css => 'input[name="password_old"]', - :value => 'some-pass', - }, - { - :execute => 'set', - :css => 'input[name="password_new_confirm"]', - :value => 'some2', - }, - { - :execute => 'click', - :css => '.content .btn--primary', - }, - { - :execute => 'watch_for', - :area => 'body', - :value => 'passwords do not match', - }, - { - :execute => 'set', - :css => 'input[name="password_new"]', - :value => 'some', - }, - { - :execute => 'set', - :css => 'input[name="password_new_confirm"]', - :value => 'some', - }, - { - :execute => 'click', - :css => '.content .btn--primary', - }, - { - :execute => 'watch_for', - :area => 'body', - :value => 'it must be at least', - }, - { - :execute => 'set', - :css => 'input[name="password_new"]', - :value => 'some-pass-new', - }, - { - :execute => 'set', - :css => 'input[name="password_new_confirm"]', - :value => 'some-pass-new', - }, - { - :execute => 'click', - :css => '.content .btn--primary', - }, - { - :execute => 'watch_for', - :area => 'body', - :value => 'must contain at least 1 digit', - }, - { - :execute => 'set', - :css => 'input[name="password_new"]', - :value => 'some-pass-new2', - }, - { - :execute => 'set', - :css => 'input[name="password_new_confirm"]', - :value => 'some-pass-new2', - }, - { - :execute => 'click', - :css => '.content .btn--primary', - }, - { - :execute => 'watch_for', - :area => 'body', - :value => 'Password changed successfully', - }, - { - :execute => 'logout', - }, - { - :execute => 'login', - :username => signup_user_email, - :password => 'some-pass-new2', - }, - { - :execute => 'logout', - }, - ], - }, - { - :name => 'reset password (not possible)', - :action => [ - # got to wrong url - { - :execute => 'navigate', - :to => browser_url + '/#password_reset_verify/not_existing_token', - }, - { - :execute => 'watch_for', - :area => 'body', - :value => 'Token is invalid', - }, - # with valid session - { - :execute => 'navigate', - :to => browser_url + '/#', - }, - { - :execute => 'login', - :username => signup_user_email, - :password => 'some-pass-new2', - }, - { - :execute => 'navigate', - :to => browser_url + '/#password_reset', - }, - { - :execute => 'wait', - :value => 1, - }, - { - :execute => 'match', - :css => 'body', - :value => 'password', - :match_result => false, - }, - { - :execute => 'logout', - }, - ], - }, - { - :name => 'reset password (correct way)', - :action => [ - { - :execute => 'click', - :css => 'a[href="#password_reset"]', - }, - { - :execute => 'set', - :css => 'input[name="username"]', - :value => 'nonexisiting', - }, - { - :execute => 'click', - :css => '.content .btn--primary', - }, - { - :execute => 'watch_for', - :area => 'body', - :value => 'address invalid', - }, - { - :execute => 'set', - :css => 'input[name="username"]', - :value => signup_user_email, - }, - { - :execute => 'click', - :css => '.content .btn--primary', - }, - { - :execute => 'watch_for', - :area => 'body', - :value => 'sent password reset instructions', - }, + @browser = browser_instance + location( :url => browser_url ) + click( :css => 'a[href="#signup"]' ) + exists( :css => '.signup' ) - # redirect to "#password_reset_verify/#{token}" url by app, because of "developer_mode" - { - :execute => 'watch_for', - :area => 'body', - :value => 'Choose your new password', - }, + # signup + set( + :css => 'input[name="firstname"]', + :value => 'Signup Firstname', + ) + set( + :css => 'input[name="lastname"]', + :value => 'Signup Lastname', + ) + set( + :css => 'input[name="email"]', + :value => signup_user_email, + ) + set( + :css => 'input[name="password"]', + :value => 'some-pass', + ) + set( + :css => 'input[name="password_confirm"]', + :value => 'some-pass', + ) + click( :css => 'button.submit' ) + sleep 5 + + result = exists( :css => '.signup' ) + assert( !result, ".signup still exists" ) + + match( + :css => '.user-menu .user a', + :value => signup_user_email, + :attribute => 'title', + ) + + # change password + click( :css => '.navbar-items-personal .user a' ) + sleep 1 + click( :css => 'a[href="#profile"]' ) + click( :css => 'a[href="#profile/password"]' ) + set( + :css => 'input[name="password_old"]', + :value => 'nonexisiting', + ) + set( + :css => 'input[name="password_new"]', + :value => 'some', + ) + set( + :css => 'input[name="password_new_confirm"]', + :value => 'some', + ) + click( :css => '.content .btn--primary' ) + + + watch_for( + :css => 'body', + :value => 'current password is wrong', + ) + + set( + :css => 'input[name="password_old"]', + :value => 'some-pass', + ) + set( + :css => 'input[name="password_new_confirm"]', + :value => 'some2', + ) + click( :css => '.content .btn--primary' ) + watch_for( + :css => 'body', + :value => 'passwords do not match', + ) + + set( + :css => 'input[name="password_new"]', + :value => 'some', + ) + set( + :css => 'input[name="password_new_confirm"]', + :value => 'some', + ) + click( :css => '.content .btn--primary' ) + + watch_for( + :css => 'body', + :value => 'it must be at least', + ) + + set( + :css => 'input[name="password_new"]', + :value => 'some-pass-new', + ) + set( + :css => 'input[name="password_new_confirm"]', + :value => 'some-pass-new', + ) + click( :css => '.content .btn--primary' ) + + watch_for( + :css => 'body', + :value => 'must contain at least 1 digit', + ) + + set( + :css => 'input[name="password_new"]', + :value => 'some-pass-new2', + ) + set( + :css => 'input[name="password_new_confirm"]', + :value => 'some-pass-new2', + ) + click( :css => '.content .btn--primary' ) + + watch_for( + :css => 'body', + :value => 'Password changed successfully', + ) + logout() + sleep 4 + + login( + :username => signup_user_email, + :password => 'some-pass-new2', + ) + logout() + + # reset password (not possible) + location( :url => browser_url + '/#password_reset_verify/not_existing_token' ) + + watch_for( + :css => 'body', + :value => 'Token is invalid', + ) + + # reset password (with valid session - should not be possible) + login( + :username => signup_user_email, + :password => 'some-pass-new2', + :url => browser_url, + ) + + location( :url => browser_url + '/#password_reset' ) + sleep 1 + + match( + :css => 'body', + :value => 'password', + :should_not_match => true, + ) + logout() + + # reset password (correct way) + click( :css => 'a[href="#password_reset"]' ) + + set( + :css => 'input[name="username"]', + :value => 'nonexisiting', + ) + click( :css => '.content .btn--primary' ) + watch_for( + :css => 'body', + :value => 'address invalid', + ) + + set( + :css => 'input[name="username"]', + :value => signup_user_email, + ) + click( :css => '.content .btn--primary' ) + watch_for( + :css => 'body', + :value => 'sent password reset instructions', + ) + + # redirect to "#password_reset_verify/#{token}" url by app, because of "developer_mode" + watch_for( + :css => 'body', + :value => 'Choose your new password', + ) + + # set new password + set( + :css => 'input[name="password"]', + :value => 'some', + ) + set( + :css => 'input[name="password_confirm"]', + :value => 'some2', + ) + click( :css => '.content .btn--primary' ) + watch_for( + :css => 'body', + :value => 'passwords do not match', + ) + + set( + :css => 'input[name="password"]', + :value => 'some', + ) + set( + :css => 'input[name="password_confirm"]', + :value => 'some', + ) + click( :css => '.content .btn--primary' ) + watch_for( + :css => 'body', + :value => 'it must be at least', + ) + + set( + :css => 'input[name="password"]', + :value => 'some-pass-new', + ) + set( + :css => 'input[name="password_confirm"]', + :value => 'some-pass-new', + ) + click( :css => '.content .btn--primary' ) + watch_for( + :css => 'body', + :value => 'must contain at least 1 digit', + ) + + set( + :css => 'input[name="password"]', + :value => 'some-pass-new2', + ) + set( + :css => 'input[name="password_confirm"]', + :value => 'some-pass-new2', + ) + click( :css => '.content .btn--primary' ) + watch_for( + :css => 'body', + :value => 'Your password has been changed', + ) + + # check if user is logged in + sleep 5 + match( + :css => '.user-menu .user a', + :value => signup_user_email, + :attribute => 'title', + ) - # set new password - { - :execute => 'set', - :css => 'input[name="password"]', - :value => 'some', - }, - { - :execute => 'set', - :css => 'input[name="password_confirm"]', - :value => 'some2', - }, - { - :execute => 'click', - :css => '.content .btn--primary', - }, - { - :execute => 'watch_for', - :area => 'body', - :value => 'passwords do not match', - }, - { - :execute => 'set', - :css => 'input[name="password"]', - :value => 'some', - }, - { - :execute => 'set', - :css => 'input[name="password_confirm"]', - :value => 'some', - }, - { - :execute => 'click', - :css => '.content .btn--primary', - }, - { - :execute => 'watch_for', - :area => 'body', - :value => 'it must be at least', - }, - { - :execute => 'set', - :css => 'input[name="password"]', - :value => 'some-pass-new', - }, - { - :execute => 'set', - :css => 'input[name="password_confirm"]', - :value => 'some-pass-new', - }, - { - :execute => 'click', - :css => '.content .btn--primary', - }, - { - :execute => 'watch_for', - :area => 'body', - :value => 'must contain at least 1 digit', - }, - { - :execute => 'set', - :css => 'input[name="password"]', - :value => 'some-pass-new2', - }, - { - :execute => 'set', - :css => 'input[name="password_confirm"]', - :value => 'some-pass-new2', - }, - { - :execute => 'click', - :css => '.content .btn--primary', - }, - { - :execute => 'watch_for', - :area => 'body', - :value => 'Your password has been changed', - }, - { - :execute => 'wait', - :value => 5, - }, - { - :execute => 'match', - :css => '.user-menu .user a', - :attribute => 'title', - :value => signup_user_email, - :match_result => true, - }, - ], - }, - ] - browser_single_test(tests) end -end +end \ No newline at end of file