Module: CapybaraAngularHelpers

Defined in:
lib/capybara_angular_helpers.rb,
lib/capybara_angular_helpers/version.rb

Constant Summary collapse

VERSION =
"0.1.2"

Instance Method Summary collapse

Instance Method Details

#ng_click_on(target, opts = {}) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/capybara_angular_helpers.rb', line 35

def ng_click_on(target, opts = {})
  selector = '*[ui-sref],' +
             '*[ng-click],' +
             'button'
 if element_index = opts[:index]
   target_element = all(selector, text: target)[element_index]

   if !target_element
     raise "#{target} could not be found"
   end
 else
   target_element = find(:css, selector, text: target)
 end

 target_element.click
end

#ng_fill_in(target, opts) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/capybara_angular_helpers.rb', line 5

def ng_fill_in(target, opts)
  if opts.is_a?(Fixnum)
    opts = opts.to_s
  end

  if opts.is_a?(String)
    opts = { with: opts }
  end

  selector = "input[ng-model='#{target}']," +
             "textarea[ng-model='#{target}']," +
             "select[ng-model='#{target}']"

  if element_index = opts[:index]
    target_element = all(selector)[element_index]

    if !target_element
      raise "#{target} could not be found"
    end
  else
    target_element = find(:css, selector)
  end

  if target_element.tag_name == 'select'
    target_element.find(:option, opts[:with]).select_option
  else
    target_element.set(opts[:with])
  end
end

#ng_ionic_click_left_navObject



52
53
54
# File 'lib/capybara_angular_helpers.rb', line 52

def ng_ionic_click_left_nav
  find('ion-header-bar .buttons-left button').click
end

#ng_ionic_click_right_navObject



56
57
58
# File 'lib/capybara_angular_helpers.rb', line 56

def ng_ionic_click_right_nav
  find('ion-header-bar .buttons-right button').click
end

#ng_ionic_list_item_click_on(list_item_text, button_text = nil) ⇒ Object



60
61
62
63
64
65
66
67
# File 'lib/capybara_angular_helpers.rb', line 60

def ng_ionic_list_item_click_on(list_item_text, button_text = nil)
  if button_text.nil?
    # find(:xpath, "//ion-side-menu-content/descendant::ion-item/descendant-or-self::*[contains(text(), '#{target}')]/ancestor-or-self::ion-item").click
    find(:xpath, "//ion-side-menu-content/descendant::ion-item/descendant-or-self::*[text()[contains(., '#{list_item_text}')]]/ancestor-or-self::ion-item").click
  else
    find(:xpath, "//ion-side-menu-content/descendant::ion-item/descendant-or-self::*[text()[contains(., '#{list_item_text}')]]/ancestor-or-self::ion-item/descendant-or-self::*[text()[contains(., '#{button_text}')]]").click
  end
end