Module: FerrumCommon::Common

Defined in:
lib/ferrum_common.rb

Instance Method Summary collapse

Instance Method Details

#abort(msg_or_cause) ⇒ Object



74
75
76
77
78
79
80
# File 'lib/ferrum_common.rb', line 74

def abort msg_or_cause
  puts msg_or_cause
  puts (msg_or_cause.respond_to?(:full_message) ? msg_or_cause.full_message : Thread.current.backtrace)
  mhtml path: "temp.mhtml"
  STDERR.puts "dumped to ./temp.mhtml"
  Kernel.abort msg_or_cause.to_s
end

#find_any(type, selector, timeout) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/ferrum_common.rb', line 46

def find_any type, selector, timeout
  Timeout.timeout timeout do
    t = public_method(type).call selector
    return t unless t.empty?
    sleep timeout * 0.1
    redo
  end
rescue Timeout::Error
end

#until_n(type, selector, timeout, n, node = nil) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/ferrum_common.rb', line 56

def until_n type, selector, timeout, n, node = nil
  t = nil
  yield_with_timeout self, timeout, __method__, ->{ "expected exactly #{n} nodes for #{type} #{selector.inspect}, got #{t ? t.size : "none"}" } do
    t = begin
      public_method(type).call selector, within: node
    end
    unless n == t.size
      sleep timeout * 0.1
      redo
    end
  end
  t
end

#until_one(type, selector, timeout, node = nil) ⇒ Object



70
71
72
# File 'lib/ferrum_common.rb', line 70

def until_one type, selector, timeout, node = nil
  until_n(type, selector, timeout, 1, node).first
end

#until_true(timeout, msg = nil) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/ferrum_common.rb', line 36

def until_true timeout, msg = nil
  yield_with_timeout self, timeout, __method__, msg do
    begin
      yield
    rescue Ferrum::NodeNotFoundError
      redo
    end or (sleep timeout * 0.1; redo)
  end
end