Module: Daddy::Cucumber::Html

Defined in:
lib/daddy/cucumber/html.rb

Instance Method Summary collapse

Instance Method Details

#confirm(ok = true) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/daddy/cucumber/html.rb', line 41

def confirm(ok = true)
  puts("確認ダイアログで #{ok ? 'OK' : 'キャンセル'} をクリック")
  return unless Capybara.current_driver == :selenium

  if ok
    page.driver.browser.switch_to.alert.accept
  else
    page.driver.browser.switch_to.alert.deny
  end
end

#find_option(select_selector, text, fail_on_missing = true) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/daddy/cucumber/html.rb', line 24

def find_option(select_selector, text, fail_on_missing = true)
  within select_selector do
    all('option').each do |option|
      if option.text.include?(text)
        if block_given?
          within option do
            yield
          end
        end
        return option
      end
    end
  end
  
  fail "セレクトボックス #{select_selector} 内に #{text} を含むオプションが見つかりませでした。" if fail_on_missing
end

#find_tr(table_selector, text, fail_on_missing = true) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/daddy/cucumber/html.rb', line 7

def find_tr(table_selector, text, fail_on_missing = true)
  within table_selector do
    all('tr').each do |tr|
      if tr.text.include?(text)
        if block_given?
          within tr do
            yield tr
          end
        end
        return tr
      end
    end
  end
  
  fail "テーブル #{table_selector} 内に #{text} を含む行が見つかりませでした。" if fail_on_missing
end