Class: Puppeteer::LifecycleWatcher::ExpectedLifecycle

Inherits:
Object
  • Object
show all
Defined in:
lib/puppeteer/lifecycle_watcher.rb

Constant Summary collapse

PUPPETEER_TO_PROTOCOL_LIFECYCLE =
{
  'load' => 'load',
  'domcontentloaded' => 'DOMContentLoaded',
  'networkidle0' => 'networkIdle',
  'networkidle2' => 'networkAlmostIdle',
}

Instance Method Summary collapse

Constructor Details

#initialize(wait_until) ⇒ ExpectedLifecycle

Returns a new instance of ExpectedLifecycle.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/puppeteer/lifecycle_watcher.rb', line 15

def initialize(wait_until)
  if wait_until.is_a?(Enumerable)
    @wait_until = wait_until.map do |value|
      unless PUPPETEER_TO_PROTOCOL_LIFECYCLE.has_key?(value.to_s)
        raise ArgumentError.new("Unknown value for options.waitUntil: #{value}")
      end
      value.to_s
    end
  elsif wait_until.is_a?(String)
    unless PUPPETEER_TO_PROTOCOL_LIFECYCLE.has_key?(wait_until)
      raise ArgumentError.new("Unknown value for options.waitUntil: #{wait_until}")
    end
    @wait_until = [wait_until]
  else
    raise ArgumentError.new('wait_until should be a Array<String> or String')
  end
end

Instance Method Details

#completed?(frame) ⇒ Boolean

Check if navigation lifecycle has experienced the expected_lifecycle events.

Parameters:

Returns:

  • (Boolean)


42
43
44
45
46
47
48
49
50
# File 'lib/puppeteer/lifecycle_watcher.rb', line 42

def completed?(frame)
  if expected_lifecycle.any? { |event| !frame.lifecycle_events.include?(event) }
    return false
  end
  if frame.child_frames.any? { |child| !completed?(child) }
    return false
  end
  true
end