Module: CapybaraAngularHelpers

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

Constant Summary collapse

VERSION =
"0.1.1"

Instance Method Summary collapse

Instance Method Details

#ng_click_on(target) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/capybara_angular_helpers.rb', line 29

def ng_click_on(target)
  begin
    find('*[ui-sref]', text: target)
  rescue Capybara::ElementNotFound
    begin
      find('*[ng-click]', text: target)
    rescue Capybara::ElementNotFound
      find('button', text: target)
    end
  end.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
# 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}']"

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

    if page_element
      page_element.set(opts[:with])
    else
      raise "#{target} could not be found"
    end
  else
    find(selector).set(opts[:with])
  end
end

#ng_ionic_click_left_navObject



41
42
43
# File 'lib/capybara_angular_helpers.rb', line 41

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

#ng_ionic_click_right_navObject



45
46
47
# File 'lib/capybara_angular_helpers.rb', line 45

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



49
50
51
52
53
54
55
56
# File 'lib/capybara_angular_helpers.rb', line 49

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