Module: Register

Extended by:
LapisLazuli
Defined in:
lib/lapis_lazuli/generators/cucumber/template/features/helpers/registration_helper.rb

Constant Summary

Constants included from LapisLazuli

LapisLazuli::CONFIG_OPTIONS, LapisLazuli::PLACEHOLDERS, LapisLazuli::VERSION

Constants included from LapisLazuli::ArgParse

LapisLazuli::ArgParse::ERROR_OPTIONS

Constants included from LapisLazuli::WorldModule::Hooks

LapisLazuli::WorldModule::Hooks::HOOK_QUEUES

Instance Attribute Summary

Attributes included from LapisLazuli

#software_versions

Class Method Summary collapse

Methods included from LapisLazuli

After, Before, Start, fetch_versions

Methods included from LapisLazuli::Assertions

#assertions, #assertions=

Methods included from LapisLazuli::GenericModule::XPath

#xp_and, #xp_contains, #xp_not, #xp_or

Methods included from LapisLazuli::WorldModule::API

#api, #has_api?

Methods included from LapisLazuli::WorldModule::Browser

#browser, #has_browser?

Methods included from LapisLazuli::WorldModule::Browser::ClassMethods

#browser_module, #browser_modules

Methods included from LapisLazuli::WorldModule::Proxy

#has_proxy?, #proxy

Methods included from LapisLazuli::WorldModule::Logging

#log

Methods included from LapisLazuli::WorldModule::Config

#add_config_from_file, #config, #current_env, #env, #env_or_config, #get_config_from_file, #has_config?, #has_env?, #has_env_or_config?, #init, #load_config, #metadata, #var_from_env

Methods included from LapisLazuli::WorldModule::Config::ClassMethods

#add_config, #config_file, #config_file=, #config_files

Methods included from LapisLazuli::WorldModule::Error

#error, #start_debugger

Methods included from LapisLazuli::WorldModule::Annotate

#annotate, #annotations

Methods included from LapisLazuli::ArgParse

#make_list_from_item, #make_list_from_nested, #parse_args

Methods included from LapisLazuli::WorldModule::Variable

#has_storage?, #scenario, #storage, #time, #uuid, #variable, #variable!

Methods included from LapisLazuli::WorldModule::Hooks

add_hook, #after_scenario_hook, #before_scenario_hook

Class Method Details

.biography_fieldObject



14
# 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_registrarionObject

And finally as function that ensures an action was successfully completed.



49
50
51
52
# 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) ⇒ Object



91
92
93
94
95
96
97
98
99
# File 'lib/lapis_lazuli/generators/cucumber/template/features/helpers/registration_helper.rb', line 91

def ensure_registered(user)
  begin
    Auth.(user)
    Auth.log_out
  rescue Exception => e
    Register.ensure_open_registrarion
    Register.register_user
  end
end

.experience_fieldObject



13
# 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_formObject



54
55
56
57
58
59
60
61
62
63
64
65
66
# 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

.formObject

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



9
# 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) ⇒ Object

@formatter:on



19
20
21
22
23
24
25
# 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?Boolean

Second, a function that confirms that the action was successful

Returns:

  • (Boolean)


44
45
46
# 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_register_buttonObject



10
# File 'lib/lapis_lazuli/generators/cucumber/template/features/helpers/registration_helper.rb', line 10

def open_register_button; browser.find(:like => [:button, :id, 'button-register']); end

.open_registrationObject

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)



39
40
41
# File 'lib/lapis_lazuli/generators/cucumber/template/features/helpers/registration_helper.rb', line 39

def open_registration
  Register.open_register_button.click
end

.password_fieldObject



12
# 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_checkboxObject



15
# 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_userObject



76
77
78
79
# 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_resultObject



81
82
83
84
85
86
87
88
89
# 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) ⇒ Object



27
28
29
30
31
32
33
34
35
# 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_buttonObject



16
# File 'lib/lapis_lazuli/generators/cucumber/template/features/helpers/registration_helper.rb', line 16

def submit_button; browser.find(:button => {:id => 'button-save'}, :context => Register.form); end

.submit_formObject



68
69
70
71
72
73
74
# 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_fieldObject



11
# 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