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



82
83
84
85
86
87
88
89
90
# File 'lib/lapis_lazuli/generators/cucumber/template/features/helpers/registration_helper.rb', line 82

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
# File 'lib/lapis_lazuli/generators/cucumber/template/features/helpers/registration_helper.rb', line 54

def fill_form
  Register.username_field.set(User.get('username'))
  Register.password_field.set(User.get('password'))
  Register.gender_radio(User.get('gender')).click
  Register.select_experiences(User.get('experience').split(','))
  Register.biography_field.set(User.get('biography'))
  Register.policy_checkbox.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



67
68
69
70
# File 'lib/lapis_lazuli/generators/cucumber/template/features/helpers/registration_helper.rb', line 67

def register_user
  Register.fill_form
  Register.submit_form
end

.registration_resultObject



72
73
74
75
76
77
78
79
80
# File 'lib/lapis_lazuli/generators/cucumber/template/features/helpers/registration_helper.rb', line 72

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.text.include? User.get('username')
    return false, "An error message did display, but didn't contain the expected text: `#{alert.text}`"
  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



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

def submit_form
  Register.submit_button.click
end

.username_fieldObject



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

def username_field; browser.find(:element => {:name => 'username'}, :context => Register.form); end