Module: FerrumCommon::Common

Defined in:
lib/ferrum_common.rb

Instance Method Summary collapse

Instance Method Details

#abort(msg_or_cause) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/ferrum_common.rb', line 40

def abort msg_or_cause
  # puts (msg_or_cause.respond_to?(:backtrace) ? msg_or_cause : Thread.current).backtrace
  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

#until_one(type, selector, timeout) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ferrum_common.rb', line 26

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

#until_true(timeout, msg = nil) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/ferrum_common.rb', line 16

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