module Register
Public Class Methods
biography_field()
click to toggle source
# File lib/lapis_lazuli/generators/cucumber/template/features/helpers/registration_helper.rb, line 14 def biography_field; browser.find(:like => [:textarea, :id, 'register-bio']); end
ensure_open_registrarion()
click to toggle source
And finally as function that ensures an action was successfully completed.
# File lib/lapis_lazuli/generators/cucumber/template/features/helpers/registration_helper.rb, line 49 def ensure_open_registrarion Auth.ensure_log_out Register.open_registration unless Register.is_registration_open? end
ensure_registered(user)
click to toggle source
# File lib/lapis_lazuli/generators/cucumber/template/features/helpers/registration_helper.rb, line 91 def ensure_registered(user) begin Auth.ensure_log_in(user) Auth.log_out rescue Exception => e Register.ensure_open_registrarion Register.register_user end end
experience_field()
click to toggle source
# File lib/lapis_lazuli/generators/cucumber/template/features/helpers/registration_helper.rb, line 13 def experience_field; browser.find(:like => [:select, :id, "register-experience"], :context => form); end
fill_form()
click to toggle source
# File lib/lapis_lazuli/generators/cucumber/template/features/helpers/registration_helper.rb, line 54 def fill_form #the setter goes too fast sometimes not finishing the username, this will re-set the username when it does browser.wait_until(timeout: 10, message: 'False did not become true withing 10 seconds') { Register.username_field.to_subtype.set(User.get('username')) Register.username_field.value == User.get('username') } Register.username_field.to_subtype.set(User.get('username')) Register.password_field.to_subtype.set(User.get('password')) Register.gender_radio(User.get('gender')).click Register.select_experiences(User.get('experience').split(',')) Register.biography_field.to_subtype.set(User.get('biography')) Register.policy_checkbox.to_subtype.set((User.get('complete_all').to_i == 1)) end
form()
click to toggle source
This is a list of elements relevant for this helper. The following is short notation, only use this if the element selector can be done in 1 line. @formatter:off
# File lib/lapis_lazuli/generators/cucumber/template/features/helpers/registration_helper.rb, line 9 def form; browser.wait(:like => [:form, :id, 'form-register']); end
gender_radio(gender)
click to toggle source
@formatter:on
# File lib/lapis_lazuli/generators/cucumber/template/features/helpers/registration_helper.rb, line 19 def gender_radio(gender) browser.find( :label => {:text => /#{gender}/i}, :context => Register.form, :message => "Unable to find gender `#{gender}`, are you sure it's an option to select?" ) end
is_registration_open?()
click to toggle source
Second, a function that confirms that the action was successful
# File lib/lapis_lazuli/generators/cucumber/template/features/helpers/registration_helper.rb, line 44 def is_registration_open? return Register.form rescue false end
open_registration()
click to toggle source
The following 3 functions are a typical example of something to use. First a function in which you perform an action (open_something, click_something, press_something)
# File lib/lapis_lazuli/generators/cucumber/template/features/helpers/registration_helper.rb, line 39 def open_registration Register.open_register_button.click end
password_field()
click to toggle source
# File lib/lapis_lazuli/generators/cucumber/template/features/helpers/registration_helper.rb, line 12 def password_field; browser.find(:element => {:name => 'password'}, :context => Register.form); end
policy_checkbox()
click to toggle source
# File lib/lapis_lazuli/generators/cucumber/template/features/helpers/registration_helper.rb, line 15 def policy_checkbox; browser.find(:like => [:input, :id, 'register-complete-all']) end
register_user()
click to toggle source
# File lib/lapis_lazuli/generators/cucumber/template/features/helpers/registration_helper.rb, line 76 def register_user Register.fill_form Register.submit_form end
registration_result()
click to toggle source
# File lib/lapis_lazuli/generators/cucumber/template/features/helpers/registration_helper.rb, line 81 def registration_result alert = browser.wait(like: [:div, :class, 'alert'], timeout: 2, throw: false) if alert.nil? return false, 'No message was displayed after registering' elsif !alert.html.include? User.get('username') return false, "An error message did display, but didn't contain the expected text: `#{alert.html}`" end return true, 'Successfully found the success message' end
select_experiences(*experience_list)
click to toggle source
# File lib/lapis_lazuli/generators/cucumber/template/features/helpers/registration_helper.rb, line 27 def select_experiences(*experience_list) experience_list.each do |exp| option = browser.find( :option => {:value => /#{exp}/i}, :context => Register.experience_field ) option.click(:control) end end
submit_form()
click to toggle source
# File lib/lapis_lazuli/generators/cucumber/template/features/helpers/registration_helper.rb, line 68 def submit_form Register.submit_button.click browser.wait( :like => [:div, :class, 'modal-backdrop fade in'], :condition => :while ) end
username_field()
click to toggle source
# File lib/lapis_lazuli/generators/cucumber/template/features/helpers/registration_helper.rb, line 11 def username_field; browser.wait(:element => {:name => 'username'}, :context => Register.form); end