Class: Capybara::Playwright::BrowserRunner::PlaywrightCreate

Inherits:
Object
  • Object
show all
Defined in:
lib/capybara/playwright/browser_runner.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ PlaywrightCreate

Returns a new instance of PlaywrightCreate.



54
55
56
57
58
59
60
61
# File 'lib/capybara/playwright/browser_runner.rb', line 54

def initialize(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)
end

Instance Method Details

#playwright_browserObject



69
70
71
72
73
# File 'lib/capybara/playwright/browser_runner.rb', line 69

def playwright_browser
  browser_type = playwright_execution.playwright.send(@browser_type)
  browser_options = @browser_options.value
  browser_type.launch(**browser_options)
end

#playwright_executionObject



63
64
65
66
67
# File 'lib/capybara/playwright/browser_runner.rb', line 63

def playwright_execution
  @playwright_execution ||= ::Playwright.create(
    playwright_cli_executable_path: @playwright_cli_executable_path,
  )
end