Module: Playwright

Defined in:
lib/playwright.rb,
lib/playwright.rb,
lib/playwright/utils.rb,
lib/playwright/video.rb,
lib/playwright/errors.rb,
lib/playwright/events.rb,
lib/playwright/channel.rb,
lib/playwright/version.rb,
lib/playwright/download.rb,
lib/playwright_api/page.rb,
lib/playwright/transport.rb,
lib/playwright_api/frame.rb,
lib/playwright_api/mouse.rb,
lib/playwright_api/route.rb,
lib/playwright/connection.rb,
lib/playwright/javascript.rb,
lib/playwright/mouse_impl.rb,
lib/playwright_api/dialog.rb,
lib/playwright_api/worker.rb,
lib/playwright/input_files.rb,
lib/playwright/url_matcher.rb,
lib/playwright/wait_helper.rb,
lib/playwright_api/android.rb,
lib/playwright_api/browser.rb,
lib/playwright_api/request.rb,
lib/playwright/http_headers.rb,
lib/playwright_api/keyboard.rb,
lib/playwright_api/response.rb,
lib/playwright/channel_owner.rb,
lib/playwright/event_emitter.rb,
lib/playwright/keyboard_impl.rb,
lib/playwright_api/js_handle.rb,
lib/playwright_api/selectors.rb,
lib/playwright/playwright_api.rb,
lib/playwright_api/playwright.rb,
lib/playwright_api/web_socket.rb,
lib/playwright_api/cdp_session.rb,
lib/playwright_api/touchscreen.rb,
lib/playwright/timeout_settings.rb,
lib/playwright/touchscreen_impl.rb,
lib/playwright_api/browser_type.rb,
lib/playwright_api/file_chooser.rb,
lib/playwright/file_chooser_impl.rb,
lib/playwright_api/accessibility.rb,
lib/playwright_api/android_input.rb,
lib/playwright/android_input_impl.rb,
lib/playwright/api_implementation.rb,
lib/playwright_api/android_device.rb,
lib/playwright_api/android_socket.rb,
lib/playwright_api/element_handle.rb,
lib/playwright/channel_owners/page.rb,
lib/playwright/event_emitter_proxy.rb,
lib/playwright/javascript/function.rb,
lib/playwright/route_handler_entry.rb,
lib/playwright_api/browser_context.rb,
lib/playwright_api/console_message.rb,
lib/playwright/channel_owners/frame.rb,
lib/playwright/channel_owners/route.rb,
lib/playwright/select_option_values.rb,
lib/playwright_api/android_web_view.rb,
lib/playwright/channel_owners/dialog.rb,
lib/playwright/channel_owners/stream.rb,
lib/playwright/javascript/expression.rb,
lib/playwright/channel_owners/android.rb,
lib/playwright/channel_owners/browser.rb,
lib/playwright/channel_owners/request.rb,
lib/playwright/channel_owners/artifact.rb,
lib/playwright/channel_owners/electron.rb,
lib/playwright/channel_owners/response.rb,
lib/playwright/javascript/value_parser.rb,
lib/playwright/channel_owners/js_handle.rb,
lib/playwright/channel_owners/selectors.rb,
lib/playwright/channel_owners/playwright.rb,
lib/playwright/channel_owners/binding_call.rb,
lib/playwright/channel_owners/browser_type.rb,
lib/playwright/javascript/value_serializer.rb,
lib/playwright/channel_owners/android_device.rb,
lib/playwright/channel_owners/element_handle.rb,
lib/playwright/channel_owners/browser_context.rb,
lib/playwright/channel_owners/console_message.rb

Overview

namespace declaration

Defined Under Namespace

Modules: ApiImplementation, ChannelOwners, EventEmitter, EventListenerInterface, Events, JavaScript, Utils Classes: Accessibility, Android, AndroidDevice, AndroidInput, AndroidSocket, AndroidWebView, Browser, BrowserContext, BrowserType, CDPSession, Channel, ChannelOwner, Connection, ConsoleMessage, Dialog, Download, DriverCrashedError, ElementHandle, Error, EventEmitterCallback, EventEmitterOnceCallback, EventEmitterProxy, Execution, FileChooser, Frame, HttpHeaders, InputFiles, JSHandle, Keyboard, Mouse, Page, Playwright, PlaywrightApi, Request, Response, RootChannelOwner, Route, RouteHandlerEntry, SelectOptionValues, Selectors, TimeoutError, TimeoutSettings, Touchscreen, Transport, UrlMatcher, Video, WaitHelper, WebSocket, Worker

Constant Summary collapse

VERSION =
'0.5.5'

Class Method Summary collapse

Class Method Details

.create(playwright_cli_executable_path:, &block) ⇒ Object

Recommended to call this method with block.

Playwright.create(…) do |playwright|

browser = playwright.chromium.launch
...

end

When we use this method without block, an instance of Puppeteer::Execution is returned and we must call execution.stop on the end. The instance of playwright is available by calling execution.playwright



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/playwright.rb', line 61

module_function def create(playwright_cli_executable_path:, &block)
  connection = Connection.new(playwright_cli_executable_path: playwright_cli_executable_path)
  connection.async_run

  execution =
    begin
      playwright = connection.wait_for_object_with_known_name('Playwright')
      Execution.new(connection, PlaywrightApi.wrap(playwright))
    rescue
      connection.stop
      raise
    end

  if block
    begin
      block.call(execution.playwright)
    ensure
      execution.stop
    end
  else
    execution
  end
end

.define_api_implementation(class_name, &block) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/playwright/api_implementation.rb', line 6

def self.define_api_implementation(class_name, &block)
  klass = Class.new
  klass.include(ApiImplementation)
  klass.class_eval(&block) if block
  if ::Playwright.const_defined?(class_name)
    raise ArgumentError.new("Playwright::#{class_name} already exist. Choose another class name.")
  end
  ::Playwright.const_set(class_name, klass)
end

.define_channel_owner(class_name, &block) ⇒ Object



84
85
86
87
88
# File 'lib/playwright/channel_owner.rb', line 84

def self.define_channel_owner(class_name, &block)
  klass = Class.new(ChannelOwner)
  klass.class_eval(&block) if block
  ChannelOwners.const_set(class_name, klass)
end

.instanceObject



85
86
87
# File 'lib/playwright.rb', line 85

module_function def instance
  @playwright_instance
end