Class: Capybara::Playwright::Driver

Inherits:
Driver::Base
  • Object
show all
Extended by:
Forwardable
Includes:
DriverExtension
Defined in:
lib/capybara/playwright/driver.rb

Instance Method Summary collapse

Methods included from DriverExtension

#on_save_raw_screenshot_before_reset, #on_save_screenrecord, #on_save_trace, #start_tracing, #stop_tracing, #trace, #with_playwright_page

Constructor Details

#initialize(app, **options) ⇒ Driver

Returns a new instance of Driver.



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/capybara/playwright/driver.rb', line 9

def initialize(app, **options)
  @browser_runner = BrowserRunner.new(options)
  @page_options = PageOptions.new(options)
  if options[:timeout].is_a?(Numeric) # just for compatibility with capybara-selenium-driver
    @default_navigation_timeout = options[:timeout] * 1000
  end
  if options[:default_timeout].is_a?(Numeric)
    @default_timeout = options[:default_timeout] * 1000
  end
  if options[:default_navigation_timeout].is_a?(Numeric)
    @default_navigation_timeout = options[:default_navigation_timeout] * 1000
  end
end

Instance Method Details

#invalid_element_errorsObject



85
86
87
88
89
90
# File 'lib/capybara/playwright/driver.rb', line 85

def invalid_element_errors
  @invalid_element_errors ||= [
    Node::NotActionableError,
    Node::StaleReferenceError,
  ].freeze
end

#needs_server?Boolean

Returns:

  • (Boolean)


24
# File 'lib/capybara/playwright/driver.rb', line 24

def needs_server?; true; end

#no_such_window_errorObject



92
93
94
# File 'lib/capybara/playwright/driver.rb', line 92

def no_such_window_error
  Browser::NoSuchWindowError
end

#reset!Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/capybara/playwright/driver.rb', line 61

def reset!
  # screenshot is available only before closing page.
  if callback_on_save_screenshot?
    raw_screenshot = @browser&.raw_screenshot
    if raw_screenshot
      callback_on_save_screenshot(raw_screenshot)
    end
  end

  # video path can be aquired only before closing context.
  # video is completedly saved only after closing context.
  video_path = @browser&.video_path

  # [NOTE] @playwright_browser should keep alive for better performance.
  # Only `Browser` is disposed.
  @browser&.clear_browser_contexts

  if video_path
    callback_on_save_screenrecord(video_path)
  end

  @browser = nil
end

#wait?Boolean

Returns:

  • (Boolean)


23
# File 'lib/capybara/playwright/driver.rb', line 23

def wait?; true; end