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, #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
# File 'lib/capybara/playwright/driver.rb', line 9

def initialize(app, **options)
  @playwright_cli_executable_path = options[:playwright_cli_executable_path] || 'npx playwright'
  @browser_type = options[:browser_type] || :chromium
  unless %i(chromium firefox webkit).include?(@browser_type)
    raise ArgumentError.new("Unknown browser_type: #{@browser_type}")
  end

  @browser_options = BrowserOptions.new(options)
  @page_options = PageOptions.new(options)
end

Instance Method Details

#browserObject



23
24
25
26
27
28
29
30
# File 'lib/capybara/playwright/driver.rb', line 23

def browser
  @browser ||= ::Capybara::Playwright::Browser.new(
    driver: self,
    playwright_browser: playwright_browser,
    page_options: @page_options.value,
    record_video: callback_on_save_screenrecord?,
  )
end

#invalid_element_errorsObject



88
89
90
91
92
93
# File 'lib/capybara/playwright/driver.rb', line 88

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

#needs_server?Boolean

Returns:

  • (Boolean)


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

def needs_server?; true; end

#no_such_window_errorObject



95
96
97
# File 'lib/capybara/playwright/driver.rb', line 95

def no_such_window_error
  Browser::NoSuchWindowError
end

#reset!Object



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

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)


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

def wait?; true; end