Module: CustomFormHelpers

Defined in:
lib/SimpliTest/helpers/step_helpers/custom_form_helpers.rb

Instance Method Summary collapse

Instance Method Details

#blur(selector_and_xpath) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/SimpliTest/helpers/step_helpers/custom_form_helpers.rb', line 11

def blur(selector_and_xpath)
  css_selector, xpath = selector_and_xpath
  selector = xpath ? xpath : css_selector
  if xpath
    return
  else
    #TODO: Hate how this done...need to come back to this

   execute_script_for_driver(SimpliTest.config_driver, %Q{ $('#{selector}').blur(); })
  end
end

#fill_in_masked_field(css_selector, value) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/SimpliTest/helpers/step_helpers/custom_form_helpers.rb', line 22

def fill_in_masked_field(css_selector, value)
  STDOUT.puts "Entering #{value} in Masked Field #{css_selector} now" #TODO: Delete this debugging statement

  execute_script_for_driver(SimpliTest.config_driver, %Q{ $("#{css_selector}").val("#{value}"); })
  STDOUT.puts "Blurring the field now" #TODO: Delete this debugging statement

  execute_script_for_driver(SimpliTest.config_driver, %Q{ $("#{css_selector}").blur(); })
  #page.driver.debug

end

#keycode_forObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/SimpliTest/helpers/step_helpers/custom_form_helpers.rb', line 46

def keycode_for
  {
    :tab => 9,
    :enter => 13,
    :up_arrow => 38,
    :down_arrow => 40,
    :left_arrow => 37,
    :right_arrow => 39,
    :escape => 27,
    :spacebar => 32,
    :ctrl => 17,
    :alt => 18,
    :shift => 16,
    :caps_lock => 20,
    :backspace => 8,
    :delete => 46
  }
end

#keypress_on(elem, key, charCode = 0) ⇒ Object



41
42
43
44
# File 'lib/SimpliTest/helpers/step_helpers/custom_form_helpers.rb', line 41

def keypress_on(elem, key, charCode = 0)
  keyCode = keycode_for[key]
  elem.base.invoke('keypress', false, false, false, false, keyCode, charCode);
end

#numerize(number_name) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/SimpliTest/helpers/step_helpers/custom_form_helpers.rb', line 3

def numerize(number_name)
  case number_name
  when 'first'; 0
  when 'last'; -1
  else number_name.match(/[0-9]/)[1].to_i + 1 rescue 0 #take the first one if you cant figure it out

  end
end

#press_key(key) ⇒ Object



31
32
33
34
35
# File 'lib/SimpliTest/helpers/step_helpers/custom_form_helpers.rb', line 31

def press_key(key)
  keycode = keycode_for[key.downcase.gsub(' ','_')]
  keypress_script = "var e = $.Event('keydown', { keyCode: #{keycode} }); $('body').trigger(e);"
  execute_js(keypress_script)
end

#tab_on(element) ⇒ Object



37
38
39
# File 'lib/SimpliTest/helpers/step_helpers/custom_form_helpers.rb', line 37

def tab_on(element)
  element.native.send_key(:tab)
end