module Playwright
namespace declaration
ref: github.com/rails/rails/blob/master/actioncable/lib/action_cable/connection/client_socket.rb ref: github.com/cavalle/chrome_remote/blob/master/lib/chrome_remote/web_socket_client.rb
Constants
- COMPATIBLE_PLAYWRIGHT_VERSION
- VERSION
Public Class Methods
# 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
# File lib/playwright/channel_owner.rb, line 87 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
# File lib/playwright/accessibility_impl.rb, line 3 def initialize(channel) @channel = channel end
Public Instance Methods
# File lib/playwright/channel_owners/browser_context.rb, line 341 def _timeout_settings @timeout_settings end
# File lib/playwright/channel_owners/route.rb, line 10 def abort(errorCode: nil) params = { errorCode: errorCode }.compact @channel.async_send_message_to_server('abort', params) end
# File lib/playwright/channel_owners/dialog.rb, line 15 def accept(promptText: nil) accept_async(prompt_text: promptText).value! end
# File lib/playwright/channel_owners/dialog.rb, line 19 def accept_async(promptText: nil) params = { promptText: promptText }.compact @channel.async_send_message_to_server('accept', params) end
# File lib/playwright/channel_owners/browser.rb, line 98 def add_context(context) @contexts << context end
# File lib/playwright/channel_owners/browser_context.rb, line 206 def add_init_script(path: nil, script: nil) source = if path File.read(path) elsif script script else raise ArgumentError.new('Either path or script parameter must be specified') end @channel.send_message_to_server('addInitScript', source: script) nil end
# File lib/playwright/channel_owners/frame.rb, line 251 def add_script_tag(content: nil, path: nil, type: nil, url: nil) params = { content: content, type: type, url: url, }.compact if path params[:content] = "#{File.read(path)}\n//# sourceURL=#{path}" end resp = @channel.send_message_to_server('addScriptTag', params) ChannelOwners::ElementHandle.from(resp) end
# File lib/playwright/channel_owners/frame.rb, line 264 def add_style_tag(content: nil, path: nil, url: nil) params = { content: content, url: url, }.compact if path params[:content] = "#{File.read(path)}\n/*# sourceURL=#{path}*/" end resp = @channel.send_message_to_server('addStyleTag', params) ChannelOwners::ElementHandle.from(resp) end
# File lib/playwright/channel_owners/android.rb, line 3 def after_initialize @timeout_settings = TimeoutSettings.new end
# File lib/playwright/locator_impl.rb, line 306 def all_inner_texts @frame.eval_on_selector_all(@selector, 'ee => ee.map(e => e.innerText)') end
# File lib/playwright/locator_impl.rb, line 310 def all_text_contents @frame.eval_on_selector_all(@selector, "ee => ee.map(e => e.textContent || '')") end
# File lib/playwright/channel_owners/playwright.rb, line 15 def android @android ||= ::Playwright::ChannelOwners::Android.from(@initializer['android']) end
# File lib/playwright/channel_owners/frame.rb, line 612 def append_child_frame_from_child(frame) @child_frames << frame end
# File lib/playwright/channel_owners/console_message.rb, line 11 def args @initializer['args']&.map do |arg| ChannelOwner.from(arg) end end
# File lib/playwright/channel_owners/js_handle.rb, line 34 def as_element nil end
# File lib/playwright/channel_owners/browser_context.rb, line 120 def background_pages @background_pages.to_a end
# File lib/playwright/channel_owners/browser_context.rb, line 349 def base_url @options[:baseURL] end
# File lib/playwright/channel_owners/response.rb, line 59 def body binary = @channel.send_message_to_server("body") Base64.strict_decode64(binary) end
# File lib/playwright/locator_impl.rb, line 33 def bounding_box(timeout: nil) with_element(timeout: timeout) do |handle| handle.bounding_box end end
# File lib/playwright/channel_owners/page.rb, line 365 def bring_to_front @channel.send_message_to_server('bringToFront') nil end
@param callback [Proc]
# File lib/playwright/channel_owners/binding_call.rb, line 12 def call(callback) frame = ChannelOwners::Frame.from(@initializer['frame']) # It is not desired to use PlaywrightApi.wrap directly. # However it is a little difficult to define wrapper for `source` parameter in generate_api. # Just a workaround... source = { context: PlaywrightApi.wrap(frame.page.context), page: PlaywrightApi.wrap(frame.page), frame: PlaywrightApi.wrap(frame), } args = if @initializer['handle'] handle = ChannelOwners::ElementHandle.from(@initializer['handle']) [handle] else @initializer['args'].map do |arg| JavaScript::ValueParser.new(arg).parse end end begin result = PlaywrightApi.unwrap(callback.call(source, *args)) @channel.send_message_to_server('resolve', result: JavaScript::ValueSerializer.new(result).serialize) rescue => err @channel.send_message_to_server('reject', error: { error: { message: err.message, name: 'Error' }}) end end
# File lib/playwright/channel_owners/binding_call.rb, line 7 def call_async(callback) Thread.new(callback) { call(callback) } end
# File lib/playwright/channel_owners/artifact.rb, line 30 def cancel @channel.send_message_to_server('cancel') end
# File lib/playwright/channel_owners/frame.rb, line 541 def check( selector, force: nil, noWaitAfter: nil, position: nil, strict: nil, timeout: nil, trial: nil) params = { selector: selector, force: force, noWaitAfter: noWaitAfter, position: position, strict: strict, timeout: timeout, trial: trial, }.compact @channel.send_message_to_server('check', params) nil end
# File lib/playwright/channel_owners/frame.rb, line 164 def checked?(selector, strict: nil, timeout: nil) params = { selector: selector, strict: strict, timeout: timeout }.compact @channel.send_message_to_server('isChecked', params) end
# File lib/playwright/channel_owners/frame.rb, line 243 def child_frames @child_frames.to_a end
# File lib/playwright/channel_owners/playwright.rb, line 3 def chromium @chromium ||= ::Playwright::ChannelOwners::BrowserType.from(@initializer['chromium']) end
# File lib/playwright/channel_owners/browser_context.rb, line 189 def clear_permissions @channel.send_message_to_server('clearPermissions') end
# File lib/playwright/channel_owners/frame.rb, line 276 def click( selector, button: nil, clickCount: nil, delay: nil, force: nil, modifiers: nil, noWaitAfter: nil, position: nil, strict: nil, timeout: nil, trial: nil) params = { selector: selector, button: button, clickCount: clickCount, delay: delay, force: force, modifiers: modifiers, noWaitAfter: noWaitAfter, position: position, strict: strict, timeout: timeout, trial: trial, }.compact @channel.send_message_to_server('click', params) nil end
# File lib/playwright/channel_owners/android_device.rb, line 83 def close @channel.send_message_to_server('close') emit(Events::AndroidDevice::Close) end
# File lib/playwright/channel_owners/page.rb, line 441 def closed? @closed end
# File lib/playwright/channel_owners/browser_type.rb, line 41 def connect_over_cdp(endpointURL, headers: nil, slowMo: nil, timeout: nil, &block) raise 'Connecting over CDP is only supported in Chromium.' unless name == 'chromium' params = { sdkLanguage: 'ruby', endpointURL: endpointURL, headers: headers, slowMo: slowMo, timeout: timeout, }.compact if headers params[:headers] = HttpHeaders.new(headers).as_serialized end result = @channel.send_message_to_server_result('connectOverCDP', params) browser = ChannelOwners::Browser.from(result['browser']) browser.send(:update_as_remote) if result['defaultContext'] context = ChannelOwners::BrowserContext.from(result['defaultContext']) browser.send(:add_context, context) end if block begin block.call(browser) ensure browser.close end else browser end end
Connects to Playwright
server, launched by `npx playwright run-server` via WebSocket
transport.
Playwright.connect_to_playwright_server(…) do |playwright|
browser = playwright.chromium.launch ...
end
@experimental
# File lib/playwright.rb, line 93 def connect_to_playwright_server(ws_endpoint, &block) require 'playwright/web_socket_client' require 'playwright/web_socket_transport' transport = WebSocketTransport.new(ws_endpoint: ws_endpoint) connection = Connection.new(transport) 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
# File lib/playwright/channel_owners/browser.rb, line 20 def connected? @connected end
# File lib/playwright/channel_owners/frame.rb, line 219 def content @channel.send_message_to_server('content') end
# File lib/playwright/channel_owners/page.rb, line 173 def context @browser_context end
# File lib/playwright/channel_owners/browser.rb, line 16 def contexts @contexts.to_a end
# File lib/playwright/channel_owners/route.rb, line 59 def continue(headers: nil, method: nil, postData: nil, url: nil) overrides = { url: url, method: method }.compact if headers overrides[:headers] = HttpHeaders.new(headers).as_serialized end if postData overrides[:postData] = Base64.strict_encode64(postData) end @channel.async_send_message_to_server('continue', overrides) end
# File lib/playwright/locator_impl.rb, line 169 def count @frame.eval_on_selector_all(@selector, 'ee => ee.length') end
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
# File lib/playwright.rb, line 60 def create(playwright_cli_executable_path:, &block) transport = Transport.new(playwright_cli_executable_path: playwright_cli_executable_path) connection = Connection.new(transport) 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
# File lib/playwright/channel_owners/frame.rb, line 334 def dblclick( selector, button: nil, delay: nil, force: nil, modifiers: nil, noWaitAfter: nil, position: nil, strict: nil, timeout: nil, trial: nil) params = { selector: selector, button: button, delay: delay, force: force, modifiers: modifiers, noWaitAfter: noWaitAfter, position: position, strict: strict, timeout: timeout, trial: trial, }.compact @channel.send_message_to_server('dblclick', params) nil end
# File lib/playwright/channel_owners/dialog.rb, line 11 def default_value @initializer['defaultValue'] end
# File lib/playwright/channel_owners/artifact.rb, line 26 def delete @channel.send_message_to_server('delete') end
# File lib/playwright/channel_owners/cdp_session.rb, line 15 def detach @channel.send_message_to_server('detach') end
# File lib/playwright/channel_owners/frame.rb, line 247 def detached? @detached end
# File lib/playwright/channel_owners/android.rb, line 7 def devices resp = @channel.send_message_to_server('devices') resp.map { |device| ChannelOwners::AndroidDevice.from(device) } end
# File lib/playwright/channel_owners/frame.rb, line 169 def disabled?(selector, strict: nil, timeout: nil) params = { selector: selector, strict: strict, timeout: timeout }.compact @channel.send_message_to_server('isDisabled', params) end
# File lib/playwright/channel_owners/dialog.rb, line 24 def dismiss @channel.async_send_message_to_server('dismiss') end
# File lib/playwright/channel_owners/frame.rb, line 198 def dispatch_event(selector, type, eventInit: nil, strict: nil, timeout: nil) params = { selector: selector, type: type, eventInit: JavaScript::ValueSerializer.new(eventInit).serialize, strict: strict, timeout: timeout, }.compact @channel.send_message_to_server('dispatchEvent', params) nil end
# File lib/playwright/channel_owners/js_handle.rb, line 38 def dispose @channel.send_message_to_server('dispose') end
# File lib/playwright/keyboard_impl.rb, line 7 def down(key) @channel.send_message_to_server('keyboardDown', key: key) nil end
# File lib/playwright/android_input_impl.rb, line 19 def drag(from, to, steps) @channel.send_message_to_server('inputDrag', from: from, to: to, steps: steps) end
# File lib/playwright/channel_owners/frame.rb, line 307 def drag_and_drop( source, target, force: nil, noWaitAfter: nil, sourcePosition: nil, strict: nil, targetPosition: nil, timeout: nil, trial: nil) params = { source: source, target: target, force: force, noWaitAfter: noWaitAfter, sourcePosition: sourcePosition, strict: strict, targetPosition: targetPosition, timeout: timeout, trial: trial, }.compact @channel.send_message_to_server('dragAndDrop', params) nil end
# File lib/playwright/channel_owners/frame.rb, line 174 def editable?(selector, strict: nil, timeout: nil) params = { selector: selector, strict: strict, timeout: timeout }.compact @channel.send_message_to_server('isEditable', params) end
# File lib/playwright/channel_owners/playwright.rb, line 19 def electron @electron ||= ::Playwright::ChannelOwners::Electron.from(@initializer['electron']) end
# File lib/playwright/file_chooser_impl.rb, line 11 def element @element_handle end
# File lib/playwright/locator_impl.rb, line 133 def element_handle(timeout: nil) @frame.wait_for_selector(@selector, strict: true, state: 'attached', timeout: timeout) end
# File lib/playwright/locator_impl.rb, line 137 def element_handles @frame.query_selector_all(@selector) end
# File lib/playwright/channel_owners/page.rb, line 185 def emit_popup_event_from_browser_context if @opener && !@opener.closed? @opener.emit(Events::Page::Popup, self) end end
# File lib/playwright/channel_owners/page.rb, line 348 def emulate_media(colorScheme: nil, media: nil, reducedMotion: nil) params = { colorScheme: colorScheme, media: media, reducedMotion: reducedMotion, }.compact @channel.send_message_to_server('emulateMedia', params) nil end
REMARK: enable_debug_console is playwright-ruby-client specific method.
# File lib/playwright/channel_owners/browser_context.rb, line 281 def enable_debug_console! # Ruby is not supported in Playwright officially, # and causes error: # # Error: # =============================== # Unsupported language: 'ruby' # =============================== # # So, launch inspector as Python app. # NOTE: This should be used only for Page#pause at this moment. @channel.send_message_to_server('recorderSupplementEnable', language: :python) @debug_console_enabled = true end
# File lib/playwright/channel_owners/frame.rb, line 179 def enabled?(selector, strict: nil, timeout: nil) params = { selector: selector, strict: strict, timeout: timeout }.compact @channel.send_message_to_server('isEnabled', params) end
# File lib/playwright/channel_owners/frame.rb, line 211 def eval_on_selector(selector, pageFunction, arg: nil, strict: nil) JavaScript::Expression.new(pageFunction, arg).eval_on_selector(@channel, selector, strict: strict) end
# File lib/playwright/channel_owners/frame.rb, line 215 def eval_on_selector_all(selector, pageFunction, arg: nil) JavaScript::Expression.new(pageFunction, arg).eval_on_selector_all(@channel, selector) end
# File lib/playwright/channel_owners/frame.rb, line 134 def evaluate(pageFunction, arg: nil) JavaScript::Expression.new(pageFunction, arg).evaluate(@channel) end
# File lib/playwright/locator_impl.rb, line 111 def evaluate_all(expression, arg: nil) @frame.eval_on_selector_all(@selector, expression, arg: arg) end
# File lib/playwright/channel_owners/frame.rb, line 138 def evaluate_handle(pageFunction, arg: nil) JavaScript::Expression.new(pageFunction, arg).evaluate_handle(@channel) end
# File lib/playwright/channel_owners/browser_type.rb, line 9 def executable_path @initializer['executablePath'] end
# File lib/playwright/channel_owners/page.rb, line 826 def expect_console_message(predicate: nil, timeout: nil, &block) expect_event(Events::Page::Console, predicate: predicate, timeout: timeout, &block) end
# File lib/playwright/channel_owners/page.rb, line 830 def expect_download(predicate: nil, timeout: nil, &block) expect_event(Events::Page::Download, predicate: predicate, timeout: timeout, &block) end
# File lib/playwright/channel_owners/browser_context.rb, line 256 def expect_event(event, predicate: nil, timeout: nil, &block) wait_helper = WaitHelper.new wait_helper.reject_on_timeout(timeout || @timeout_settings.timeout, "Timeout while waiting for event \"#{event}\"") wait_helper.wait_for_event(self, event, predicate: predicate) block&.call wait_helper.promise.value! end
# File lib/playwright/channel_owners/page.rb, line 834 def expect_file_chooser(predicate: nil, timeout: nil, &block) expect_event(Events::Page::FileChooser, predicate: predicate, timeout: timeout, &block) end
# File lib/playwright/channel_owners/browser_context.rb, line 319 def expect_page(predicate: nil, timeout: nil) params = { predicate: predicate, timeout: timeout, }.compact expect_event(Events::BrowserContext::Page, params) end
# File lib/playwright/channel_owners/page.rb, line 846 def expect_popup(predicate: nil, timeout: nil, &block) expect_event(Events::Page::Popup, predicate: predicate, timeout: timeout, &block) end
# File lib/playwright/channel_owners/page.rb, line 850 def expect_request(urlOrPredicate, timeout: nil, &block) predicate = case urlOrPredicate when String, Regexp url_matcher = UrlMatcher.new(urlOrPredicate, base_url: @browser_context.send(:base_url)) -> (req){ url_matcher.match?(req.url) } when Proc urlOrPredicate else -> (_) { true } end expect_event(Events::Page::Request, predicate: predicate, timeout: timeout, &block) end
# File lib/playwright/channel_owners/page.rb, line 865 def expect_request_finished(predicate: nil, timeout: nil, &block) expect_event(Events::Page::RequestFinished, predicate: predicate, timeout: timeout, &block) end
# File lib/playwright/channel_owners/page.rb, line 869 def expect_response(urlOrPredicate, timeout: nil, &block) predicate = case urlOrPredicate when String, Regexp url_matcher = UrlMatcher.new(urlOrPredicate, base_url: @browser_context.send(:base_url)) -> (req){ url_matcher.match?(req.url) } when Proc urlOrPredicate else -> (_) { true } end expect_event(Events::Page::Response, predicate: predicate, timeout: timeout, &block) end
# File lib/playwright/channel_owners/page.rb, line 884 def expect_websocket(predicate: nil, timeout: nil, &block) expect_event(Events::Page::WebSocket, predicate: predicate, timeout: timeout, &block) end
# File lib/playwright/channel_owners/page.rb, line 888 def expect_worker(predicate: nil, timeout: nil, &block) expect_event(Events::Page::Worker, predicate: predicate, timeout: timeout, &block) end
# File lib/playwright/tracing_impl.rb, line 23 def export(path:) resp = @channel.send_message_to_server('tracingExport') artifact = ChannelOwners::Artifact.from(resp) # if self._context._browser: # artifact._is_remote = self._context._browser._is_remote artifact.save_as(path) artifact.delete end
# File lib/playwright/channel_owners/browser_context.rb, line 220 def expose_binding(name, callback, handle: nil) if @pages.any? { |page| page.send(:has_bindings?, name) } raise ArgumentError.new("Function \"#{name}\" has been already registered in one of the pages") end if @bindings.key?(name) raise ArgumentError.new("Function \"#{name}\" has been already registered") end params = { name: name, needsHandle: handle, }.compact @bindings[name] = callback @channel.send_message_to_server('exposeBinding', params) end
# File lib/playwright/channel_owners/browser_context.rb, line 235 def expose_function(name, callback) expose_binding(name, ->(_source, *args) { callback.call(*args) }, ) end
# File lib/playwright/channel_owners/artifact.rb, line 22 def failure @channel.send_message_to_server('failure') end
# File lib/playwright/channel_owners/frame.rb, line 387 def fill( selector, value, force: nil, noWaitAfter: nil, strict: nil, timeout: nil) params = { selector: selector, value: value, force: force, noWaitAfter: noWaitAfter, strict: strict, timeout: timeout, }.compact @channel.send_message_to_server('fill', params) nil end
# File lib/playwright/channel_owners/response.rb, line 55 def finished @channel.send_message_to_server('finished') end
# File lib/playwright/channel_owners/playwright.rb, line 7 def firefox @firefox ||= ::Playwright::ChannelOwners::BrowserType.from(@initializer['firefox']) end
# File lib/playwright/locator_impl.rb, line 141 def first LocatorImpl.new( frame: @frame, timeout_settings: @timeout_settings, selector: "#{@selector} >> nth=0", ) end
# File lib/playwright/channel_owners/frame.rb, line 407 def focus(selector, strict: nil, timeout: nil) params = { selector: selector, strict: strict, timeout: timeout }.compact @channel.send_message_to_server('focus', params) nil end
# File lib/playwright/accessibility_impl.rb, line 19 def format_ax_node_from_protocol(ax_node) value = ax_node.delete('valueNumber') || ax_node.delete('valueString') ax_node['value'] = value unless value.nil? checked = case ax_node['checked'] when 'checked' true when 'unchecked' false else ax_node['checked'] end ax_node['checked'] = checked unless checked.nil? pressed = case ax_node['pressed'] when 'pressed' true when 'released' false else ax_node['pressed'] end ax_node['pressed'] = pressed unless pressed.nil? ax_node['children']&.each do |child| format_ax_node_from_protocol(child) end end
# File lib/playwright/channel_owners/page.rb, line 191 def frame(name: nil, url: nil) if name @frames.find { |f| f.name == name } elsif url matcher = UrlMatcher.new(url, base_url: @browser_context.send(:base_url)) @frames.find { |f| matcher.match?(f.url) } else raise ArgumentError.new('Either name or url matcher should be specified') end end
# File lib/playwright/channel_owners/frame.rb, line 129 def frame_element resp = @channel.send_message_to_server('frameElement') ChannelOwners::ElementHandle.from(resp) end
# File lib/playwright/channel_owners/page.rb, line 202 def frames @frames.to_a end
# File lib/playwright/channel_owners/route.rb, line 15 def fulfill( body: nil, contentType: nil, headers: nil, path: nil, status: nil) params = { contentType: contentType, status: status, }.compact length = 0 content = if body body elsif path File.read(path) else nil end param_headers = headers || {} if contentType param_headers['content-type'] = contentType elsif path param_headers['content-type'] = mime_type_for(path) end if content if content.is_a?(String) params[:body] = content params[:isBase64] = false else params[:body] = Base64.strict_encode64(content) params[:isBase64] = true end param_headers['content-length'] ||= content.length.to_s end params[:headers] = HttpHeaders.new(param_headers).as_serialized @channel.async_send_message_to_server('fulfill', params) end
# File lib/playwright/channel_owners/frame.rb, line 428 def get_attribute(selector, name, strict: nil, timeout: nil) params = { selector: selector, name: name, strict: strict, timeout: timeout, }.compact @channel.send_message_to_server('getAttribute', params) end
# File lib/playwright/channel_owners/js_handle.rb, line 24 def get_properties resp = @channel.send_message_to_server('getPropertyList') resp.map { |prop| [prop['name'], ChannelOwner.from(prop['value'])] }.to_h end
# File lib/playwright/channel_owners/js_handle.rb, line 29 def get_property(name) resp = @channel.send_message_to_server('getProperty', name: name) ChannelOwner.from(resp) end
# File lib/playwright/channel_owners/page.rb, line 336 def go_back(timeout: nil, waitUntil: nil) params = { timeout: timeout, waitUntil: waitUntil }.compact resp = @channel.send_message_to_server('goBack', params) ChannelOwners::Response.from_nullable(resp) end
# File lib/playwright/channel_owners/page.rb, line 342 def go_forward(timeout: nil, waitUntil: nil) params = { timeout: timeout, waitUntil: waitUntil }.compact resp = @channel.send_message_to_server('goForward', params) ChannelOwners::Response.from_nullable(resp) end
# File lib/playwright/channel_owners/frame.rb, line 45 def goto(url, timeout: nil, waitUntil: nil, referer: nil) params = { url: url, timeout: timeout, waitUntil: waitUntil, referer: referer }.compact resp = @channel.send_message_to_server('goto', params) ChannelOwners::Response.from_nullable(resp) end
# File lib/playwright/channel_owners/browser_context.rb, line 181 def grant_permissions(permissions, origin: nil) params = { permissions: permissions, origin: origin, }.compact @channel.send_message_to_server('grantPermissions', params) end
Expose guid for library developers. Not intended to be used by users.
# File lib/playwright/channel_owners/page.rb, line 909 def guid @guid end
# File lib/playwright/channel_owners/page.rb, line 898 def has_bindings?(name) @bindings.key?(name) end
# File lib/playwright/channel_owners/browser_context.rb, line 345 def has_record_video_option? @options.key?(:recordVideo) end
# File lib/playwright/channel_owners/request.rb, line 62 def headers @headers end
# File lib/playwright/channel_owners/frame.rb, line 438 def hover( selector, force: nil, modifiers: nil, position: nil, strict: nil, timeout: nil, trial: nil) params = { selector: selector, force: force, modifiers: modifiers, position: position, strict: strict, timeout: timeout, trial: trial, }.compact @channel.send_message_to_server('hover', params) nil end
# File lib/playwright/channel_owners/android_device.rb, line 64 def info(selector) @channel.send_message_to_server('info', selector: to_selector_channel(selector)) end
# File lib/playwright/channel_owners/frame.rb, line 423 def inner_html(selector, strict: nil, timeout: nil) params = { selector: selector, strict: strict, timeout: timeout }.compact @channel.send_message_to_server('innerHTML', params) end
# File lib/playwright/channel_owners/frame.rb, line 418 def inner_text(selector, strict: nil, timeout: nil) params = { selector: selector, strict: strict, timeout: timeout }.compact @channel.send_message_to_server('innerText', params) end
# File lib/playwright/channel_owners/frame.rb, line 480 def input_value(selector, strict: nil, timeout: nil) params = { selector: selector, strict: strict, timeout: timeout }.compact @channel.send_message_to_server('inputValue', params) end
# File lib/playwright/keyboard_impl.rb, line 16 def insert_text(text) @channel.send_message_to_server('keyboardInsertText', text: text) end
# File lib/playwright/channel_owners/response.rb, line 65 def json JSON.parse(text) end
# File lib/playwright/channel_owners/js_handle.rb, line 42 def json_value value = @channel.send_message_to_server('jsonValue') JavaScript::ValueParser.new(value).parse end
# File lib/playwright/locator_impl.rb, line 149 def last LocatorImpl.new( frame: @frame, timeout_settings: @timeout_settings, selector: "#{@selector} >> nth=-1", ) end
# File lib/playwright/channel_owners/browser_type.rb, line 13 def launch(options, &block) resp = @channel.send_message_to_server('launch', options.compact) browser = ChannelOwners::Browser.from(resp) return browser unless block begin block.call(browser) ensure browser.close end end
# File lib/playwright/channel_owners/android_device.rb, line 93 def launch_browser( pkg: nil, acceptDownloads: nil, bypassCSP: nil, colorScheme: nil, deviceScaleFactor: nil, extraHTTPHeaders: nil, geolocation: nil, hasTouch: nil, httpCredentials: nil, ignoreHTTPSErrors: nil, isMobile: nil, javaScriptEnabled: nil, locale: nil, noViewport: nil, offline: nil, permissions: nil, proxy: nil, record_har_omit_content: nil, record_har_path: nil, record_video_dir: nil, record_video_size: nil, storageState: nil, timezoneId: nil, userAgent: nil, viewport: nil, &block) params = { pkg: pkg, acceptDownloads: acceptDownloads, bypassCSP: bypassCSP, colorScheme: colorScheme, deviceScaleFactor: deviceScaleFactor, extraHTTPHeaders: extraHTTPHeaders, geolocation: geolocation, hasTouch: hasTouch, httpCredentials: httpCredentials, ignoreHTTPSErrors: ignoreHTTPSErrors, isMobile: isMobile, javaScriptEnabled: javaScriptEnabled, locale: locale, noViewport: noViewport, offline: offline, permissions: permissions, proxy: proxy, record_har_omit_content: record_har_omit_content, record_har_path: record_har_path, record_video_dir: record_video_dir, record_video_size: record_video_size, storageState: storageState, timezoneId: timezoneId, userAgent: userAgent, viewport: viewport, }.compact prepare_browser_context_options(params) resp = @channel.send_message_to_server('launchBrowser', params) context = ChannelOwners::BrowserContext.from(resp) if block begin block.call(context) ensure context.close end else context end end
# File lib/playwright/channel_owners/browser_type.rb, line 25 def launch_persistent_context(userDataDir, **options, &block) params = options.dup prepare_browser_context_options(params) params['userDataDir'] = userDataDir resp = @channel.send_message_to_server('launchPersistentContext', params.compact) context = ChannelOwners::Browser.from(resp) return context unless block begin block.call(context) ensure context.close end end
# File lib/playwright/channel_owners/console_message.rb, line 17 def location @initialize['location'] end
# File lib/playwright/channel_owners/frame.rb, line 194 def locator(selector) LocatorImpl.new(frame: self, timeout_settings: @page.send(:timeout_settings), selector: selector) end
# File lib/playwright/channel_owners/dialog.rb, line 7 def message @initializer['message'] end
# File lib/playwright/channel_owners/request.rb, line 31 def method @initializer['method'] end
# File lib/playwright/channel_owners/route.rb, line 73 def mime_type_for(filepath) mime_types = MIME::Types.type_for(filepath) mime_types.first.to_s || 'application/octet-stream' end
# File lib/playwright/channel_owners/android_device.rb, line 15 def model @initializer['model'] end
# File lib/playwright/mouse_impl.rb, line 7 def move(x, y, steps: nil) params = { x: x, y: y, steps: steps }.compact @channel.send_message_to_server('mouseMove', params) nil end
# File lib/playwright/file_chooser_impl.rb, line 15 def multiple? @is_multiple end
# File lib/playwright/channel_owners/binding_call.rb, line 3 def name @initializer['name'] end
# File lib/playwright/channel_owners/browser.rb, line 70 def new_browser_cdp_session resp = @channel.send_message_to_server('newBrowserCDPSession') ChannelOwners::CDPSession.from(resp) end
# File lib/playwright/channel_owners/browser_context.rb, line 128 def new_cdp_session(page) resp = @channel.send_message_to_server('newCDPSession', page: page.channel) ChannelOwners::CDPSession.from(resp) end
# File lib/playwright/channel_owners/browser.rb, line 24 def new_context(**options, &block) params = options.dup prepare_browser_context_options(params) resp = @channel.send_message_to_server('newContext', params.compact) context = ChannelOwners::BrowserContext.from(resp) @contexts << context context.browser = self context.options = params return context unless block begin block.call(context) ensure context.close end end
# File lib/playwright/channel_owners/browser.rb, line 42 def new_page(**options, &block) context = new_context(**options) page = context.new_page page.owned_context = context context.owner_page = page return page unless block begin block.call(page) ensure page.close end end
# File lib/playwright/locator_impl.rb, line 157 def nth(index) LocatorImpl.new( frame: @frame, timeout_settings: @timeout_settings, selector: "#{@selector} >> nth=#{index}", ) end
@override
# File lib/playwright/channel_owners/page.rb, line 166 def off(event, callback) super if event == Events::Page::FileChooser && listener_count(event) == 0 @channel.async_send_message_to_server('setFileChooserInterceptedNoReply', intercepted: false) end end
# File lib/playwright/channel_owners/response.rb, line 28 def ok status == 0 || (200...300).include?(status) end
@override
# File lib/playwright/channel_owners/page.rb, line 150 def on(event, callback) if event == Events::Page::FileChooser && listener_count(event) == 0 @channel.async_send_message_to_server('setFileChooserInterceptedNoReply', intercepted: true) end super end
# File lib/playwright/channel_owners/browser_context.rb, line 67 def on_background_page(page) @background_pages << page emit(Events::BrowserContext::BackgroundPage, page) end
# File lib/playwright/channel_owners/browser_context.rb, line 84 def on_binding(binding_call) func = @bindings[binding_call.name] if func binding_call.call_async(func) end end
# File lib/playwright/channel_owners/browser.rb, line 91 def on_close(_ = {}) @connected = false emit(Events::Browser::Disconnected, self) @closed_or_closing = true end
# File lib/playwright/channel_owners/page.rb, line 127 def on_dialog(params) dialog = ChannelOwners::Dialog.from(params['dialog']) unless emit(Events::Page::Dialog, dialog) dialog.dismiss end end
# File lib/playwright/channel_owners/page.rb, line 134 def on_download(params) download = DownloadImpl.new( page: self, url: params['url'], suggested_filename: params['suggestedFilename'], artifact: ChannelOwners::Artifact.from(params['artifact']), ) emit(Events::Page::Download, download) end
# File lib/playwright/channel_owners/cdp_session.rb, line 7 def on_event(params) emit(params['method'], params['params']) end
# File lib/playwright/channel_owners/page.rb, line 82 def on_frame_attached(frame) frame.send(:update_page_from_page, self) @frames << frame emit(Events::Page::FrameAttached, frame) end
# File lib/playwright/channel_owners/page.rb, line 88 def on_frame_detached(frame) @frames.delete(frame) frame.detached = true emit(Events::Page::FrameDetached, frame) end
# File lib/playwright/channel_owners/web_socket.rb, line 70 def on_frame_received(opcode, data) if opcode == 2 emit(Events::WebSocket::FrameReceived, Base64.strict_decode64(data)) else emit(Events::WebSocket::FrameReceived, data) end end
# File lib/playwright/channel_owners/web_socket.rb, line 62 def on_frame_sent(opcode, data) if opcode == 2 emit(Events::WebSocket::FrameSent, Base64.strict_decode64(data)) else emit(Events::WebSocket::FrameSent, data) end end
# File lib/playwright/channel_owners/frame.rb, line 25 def on_load_state(add:, remove:) if add @load_states << add @event_emitter.emit('loadstate', add) end if remove @load_states.delete(remove) end end
# File lib/playwright/channel_owners/browser_context.rb, line 61 def on_page(page) @pages << page emit(Events::BrowserContext::Page, page) page.send(:emit_popup_event_from_browser_context) end
# File lib/playwright/channel_owners/js_handle.rb, line 12 def on_preview_updated(params) @preview = params['preview'] end
# File lib/playwright/channel_owners/browser_context.rb, line 104 def on_request(request, page) emit(Events::BrowserContext::Request, request) page&.emit(Events::Page::Request, request) end
# File lib/playwright/channel_owners/browser_context.rb, line 91 def on_request_failed(request, response_end_timing, failure_text, page) request.send(:update_failure_text, failure_text) request.send(:update_response_end_timing, response_end_timing) emit(Events::BrowserContext::RequestFailed, request) page&.emit(Events::Page::RequestFailed, request) end
# File lib/playwright/channel_owners/browser_context.rb, line 98 def on_request_finished(request, response_end_timing, page) request.send(:update_response_end_timing, response_end_timing) emit(Events::BrowserContext::RequestFinished, request) page&.emit(Events::Page::RequestFinished, request) end
# File lib/playwright/channel_owners/browser_context.rb, line 109 def on_response(response, page) emit(Events::BrowserContext::Response, response) page&.emit(Events::Page::Response, response) end
# File lib/playwright/channel_owners/browser_context.rb, line 72 def on_route(route, request) # It is not desired to use PlaywrightApi.wrap directly. # However it is a little difficult to define wrapper for `handler` parameter in generate_api. # Just a workaround... wrapped_route = PlaywrightApi.wrap(route) wrapped_request = PlaywrightApi.wrap(request) if @routes.none? { |handler_entry| handler_entry.handle(wrapped_route, wrapped_request) } route.continue end end
# File lib/playwright/channel_owners/browser_context.rb, line 114 def on_service_worker(worker) worker.context = self @service_workers << worker emit(Events::BrowserContext::ServiceWorker, worker) end
# File lib/playwright/channel_owners/page.rb, line 144 def on_video(params) artifact = ChannelOwners::Artifact.from(params['artifact']) video.send(:set_artifact, artifact) end
# File lib/playwright/channel_owners/page.rb, line 114 def on_worker(worker) worker.page = self @workers << worker emit(Events::Page::Worker, worker) end
@override
# File lib/playwright/channel_owners/page.rb, line 158 def once(event, callback) if event == Events::Page::FileChooser && listener_count(event) == 0 @channel.async_send_message_to_server('setFileChooserInterceptedNoReply', intercepted: true) end super end
# File lib/playwright/channel_owners/page.rb, line 177 def opener if @opener&.closed? nil else @opener end end
# File lib/playwright/channel_owners/browser_context.rb, line 143 def pages @pages.to_a end
# File lib/playwright/channel_owners/playwright.rb, line 33 def parse_device_descriptor(descriptor) # This return value can be passed into Browser#new_context as it is. # ex: # ``` # iPhone = playwright.devices['iPhone 6'] # context = browser.new_context(**iPhone) # page = context.new_page # # ``` { userAgent: descriptor['userAgent'], viewport: { width: descriptor['viewport']['width'], height: descriptor['viewport']['height'], }, deviceScaleFactor: descriptor['deviceScaleFactor'], isMobile: descriptor['isMobile'], hasTouch: descriptor['hasTouch'], } end
# File lib/playwright/channel_owners/request.rb, line 121 def parse_headers(headers) headers.map do |header| [header['name'].downcase, header['value']] end.to_h end
# File lib/playwright/download_impl.rb, line 20 def path @artifact.path_after_finished end
# File lib/playwright/channel_owners/artifact.rb, line 10 def path_after_finished if @is_remote raise "Path is not available when using browser_type.connect(). Use save_as() to save a local copy." end @channel.send_message_to_server('pathAfterFinished') end
# File lib/playwright/channel_owners/browser_context.rb, line 302 def pause unless @debug_console_enabled raise DebugConsoleNotEnabledError.new end @channel.send_message_to_server('pause') end
# File lib/playwright/channel_owners/page.rb, line 721 def pdf( displayHeaderFooter: nil, footerTemplate: nil, format: nil, headerTemplate: nil, height: nil, landscape: nil, margin: nil, pageRanges: nil, path: nil, preferCSSPageSize: nil, printBackground: nil, scale: nil, width: nil) params = { displayHeaderFooter: displayHeaderFooter, footerTemplate: footerTemplate, format: format, headerTemplate: headerTemplate, height: height, landscape: landscape, margin: margin, pageRanges: pageRanges, preferCSSPageSize: preferCSSPageSize, printBackground: printBackground, scale: scale, width: width, }.compact encoded_binary = @channel.send_message_to_server('pdf', params) decoded_binary = Base64.strict_decode64(encoded_binary) if path File.open(path, 'wb') do |f| f.write(decoded_binary) end end decoded_binary end
# File lib/playwright/channel_owners/request.rb, line 35 def post_data post_data_buffer end
# File lib/playwright/channel_owners/request.rb, line 53 def post_data_buffer base64_content = @initializer['postData'] if base64_content Base64.strict_decode64(base64_content) else nil end end
# File lib/playwright/channel_owners/request.rb, line 39 def post_data_json data = post_data return unless data content_type = @headers['content-type'] return unless content_type if content_type == "application/x-www-form-urlencoded" URI.decode_www_form(data).to_h else JSON.parse(data) end end
# File lib/playwright/android_input_impl.rb, line 11 def press(key) @channel.send_message_to_server('inputPress', key: key) end
# File lib/playwright/channel_owners/frame.rb, line 142 def query_selector(selector, strict: nil) params = { selector: selector, strict: strict, }.compact resp = @channel.send_message_to_server('querySelector', params) ChannelOwners::ElementHandle.from_nullable(resp) end
# File lib/playwright/channel_owners/frame.rb, line 151 def query_selector_all(selector) @channel.send_message_to_server('querySelectorAll', selector: selector).map do |el| ChannelOwners::ElementHandle.from(el) end end
# File lib/playwright/channel_owners/selectors.rb, line 4 def register(name, contentScript: nil, path: nil, script: nil) source = if path File.read(path) elsif script script else raise ArgumentError.new('Either path or script parameter must be specified') end params = { name: name, source: source } if contentScript params[:contentScript] = true end @channel.send_message_to_server('register', params) nil end
# File lib/playwright/channel_owners/page.rb, line 319 def reload(timeout: nil, waitUntil: nil) params = { timeout: timeout, waitUntil: waitUntil, }.compact resp = @channel.send_message_to_server('reload', params) ChannelOwners::Response.from_nullable(resp) end
# File lib/playwright/channel_owners/browser_context.rb, line 332 def remove_background_page(page) @background_pages.delete(page) end
# File lib/playwright/channel_owners/browser.rb, line 108 def remove_context(context) @contexts.delete(context) end
# File lib/playwright/channel_owners/browser_context.rb, line 328 def remove_page(page) @pages.delete(page) end
# File lib/playwright/channel_owners/browser_context.rb, line 336 def remove_service_worker(worker) @service_workers.delete(worker) end
# File lib/playwright/channel_owners/page.rb, line 903 def remove_worker(worker) @workers.delete(worker) end
# File lib/playwright/channel_owners/route.rb, line 6 def request ChannelOwners::Request.from(@initializer['request']) end
# File lib/playwright/channel_owners/request.rb, line 27 def resource_type @initializer['resourceType'] end
# File lib/playwright/channel_owners/request.rb, line 66 def response resp = @channel.send_message_to_server('response') ChannelOwners::Response.from_nullable(resp) end
# File lib/playwright/channel_owners/browser_context.rb, line 239 def route(url, handler) entry = RouteHandlerEntry.new(url, base_url, handler) @routes.unshift(entry) if @routes.count >= 1 @channel.send_message_to_server('setNetworkInterceptionEnabled', enabled: true) end end
# File lib/playwright/channel_owners/artifact.rb, line 17 def save_as(path) stream = ChannelOwners::Stream.from(@channel.send_message_to_server('saveAsStream')) stream.save_as(path) end
# File lib/playwright/channel_owners/android_device.rb, line 72 def screenshot(path: nil) encoded_binary = @channel.send_message_to_server('screenshot') decoded_binary = Base64.strict_decode64(encoded_binary) if path File.open(path, 'wb') do |f| f.write(decoded_binary) end end decoded_binary end
# File lib/playwright/locator_impl.rb, line 230 def scroll_into_view_if_needed(timeout: nil) with_element(timeout: timeout) do |handle, options| handle.scroll_into_view_if_needed(timeout: options[:timeout]) end end
# File lib/playwright/channel_owners/response.rb, line 51 def security_details @channel.send_message_to_server('securityDetails') end
# File lib/playwright/channel_owners/frame.rb, line 460 def select_option( selector, element: nil, index: nil, value: nil, label: nil, force: nil, noWaitAfter: nil, strict: nil, timeout: nil) base_params = SelectOptionValues.new( element: element, index: index, value: value, label: label, ).as_params params = base_params.merge({ selector: selector, force: force, noWaitAfter: noWaitAfter, strict: strict, timeout: timeout }.compact) @channel.send_message_to_server('selectOption', params) end
# File lib/playwright/locator_impl.rb, line 256 def select_text(force: nil, timeout: nil) with_element(timeout: timeout) do |handle, options| handle.select_text(force: force, timeout: options[:timeout]) end end
# File lib/playwright/channel_owners/playwright.rb, line 23 def selectors @selectors ||= ::Playwright::ChannelOwners::Selectors.from(@initializer['selectors']) end
# File lib/playwright/channel_owners/cdp_session.rb, line 11 def send_message(method, params: {}) @channel.send_message_to_server('send', method: method, params: params) end
# File lib/playwright/channel_owners/android_device.rb, line 11 def serial @initializer['serial'] end
# File lib/playwright/channel_owners/response.rb, line 47 def server_addr @channel.send_message_to_server('serverAddr') end
# File lib/playwright/channel_owners/browser_context.rb, line 124 def service_workers @service_workers.to_a end
# File lib/playwright/channel_owners/frame.rb, line 223 def set_content(html, timeout: nil, waitUntil: nil) params = { html: html, timeout: timeout, waitUntil: waitUntil, }.compact @channel.send_message_to_server('setContent', params) nil end
# File lib/playwright/channel_owners/browser_context.rb, line 138 def set_default_timeout(timeout) @timeout_settings.default_timeout = timeout @channel.send_message_to_server('setDefaultTimeoutNoReply', timeout: timeout) end
# File lib/playwright/channel_owners/browser_context.rb, line 197 def set_extra_http_headers(headers) @channel.send_message_to_server('setExtraHTTPHeaders', headers: HttpHeaders.new(headers).as_serialized) end
# File lib/playwright/file_chooser_impl.rb, line 19 def set_files(files, noWaitAfter: nil, timeout: nil) @element_handle.set_input_files(files, noWaitAfter: noWaitAfter, timeout: timeout) end
# File lib/playwright/channel_owners/browser_context.rb, line 193 def set_geolocation(geolocation) @channel.send_message_to_server('setGeolocation', geolocation: geolocation) end
# File lib/playwright/channel_owners/frame.rb, line 485 def set_input_files(selector, files, noWaitAfter: nil, strict: nil, timeout: nil) file_payloads = InputFiles.new(files).as_params params = { files: file_payloads, selector: selector, noWaitAfter: noWaitAfter, strict: strict, timeout: timeout, }.compact @channel.send_message_to_server('setInputFiles', params) nil end
# File lib/playwright/channel_owners/browser_context.rb, line 202 def set_offline(offline) @channel.send_message_to_server('setOffline', offline: offline) end
# File lib/playwright/channel_owners/page.rb, line 359 def set_viewport_size(viewportSize) @viewport_size = viewportSize @channel.send_message_to_server('setViewportSize', { viewportSize: viewportSize }) nil end
# File lib/playwright/channel_owners/android_device.rb, line 88 def shell(command) resp = @channel.send_message_to_server('shell', command: command) Base64.strict_decode64(resp) end
# File lib/playwright/accessibility_impl.rb, line 7 def snapshot(interestingOnly: nil, root: nil) params = { interestingOnly: interestingOnly, root: root&.channel, }.compact result = @channel.send_message_to_server('accessibilitySnapshot', params) format_ax_node_from_protocol(result) if result result end
# File lib/playwright/tracing_impl.rb, line 8 def start(name: nil, screenshots: nil, snapshots: nil) params = { name: name, screenshots: screenshots, snapshots: snapshots, }.compact @channel.send_message_to_server('tracingStart', params) end
# File lib/playwright/channel_owners/page.rb, line 778 def start_css_coverage(resetOnNavigation: nil, reportAnonymousScripts: nil) params = { resetOnNavigation: resetOnNavigation, }.compact @channel.send_message_to_server('startCSSCoverage', params) end
# File lib/playwright/channel_owners/page.rb, line 765 def start_js_coverage(resetOnNavigation: nil, reportAnonymousScripts: nil) params = { resetOnNavigation: resetOnNavigation, reportAnonymousScripts: reportAnonymousScripts, }.compact @channel.send_message_to_server('startJSCoverage', params) end
# File lib/playwright/channel_owners/browser.rb, line 75 def start_tracing(page: nil, categories: nil, path: nil, screenshots: nil) params = { page: page&.channel, categories: categories, path: path, screenshots: screenshots, }.compact @channel.send_message_to_server('startTracing', params) end
# File lib/playwright/channel_owners/response.rb, line 33 def status @initializer['status'] end
# File lib/playwright/channel_owners/response.rb, line 37 def status_text @initializer['statusText'] end
Stop tracing.
# File lib/playwright/tracing_impl.rb, line 18 def stop(path: nil) export(path: path) if path @channel.send_message_to_server('tracingStop') end
# File lib/playwright/channel_owners/page.rb, line 786 def stop_css_coverage @channel.send_message_to_server('stopCSSCoverage') end
# File lib/playwright/channel_owners/page.rb, line 774 def stop_js_coverage @channel.send_message_to_server('stopJSCoverage') end
# File lib/playwright/channel_owners/browser.rb, line 86 def stop_tracing encoded_binary = @channel.send_message_to_server("stopTracing") return Base64.strict_decode64(encoded_binary) end
# File lib/playwright/channel_owners/browser_context.rb, line 309 def storage_state(path: nil) @channel.send_message_to_server_result('storageState', {}).tap do |result| if path File.open(path, 'w') do |f| f.write(JSON.dump(result)) end end end end
# File lib/playwright/channel_owners/android_device.rb, line 55 def tap_on(selector, duration: nil, timeout: nil) params = { selector: to_selector_channel(selector), duration: duration, timeout: timeout, }.compact @channel.send_message_to_server('tap', params) end
# File lib/playwright/android_input_impl.rb, line 15 def tap_point(point) @channel.send_message_to_server('inputTap', point: point) end
# File lib/playwright/channel_owners/console_message.rb, line 7 def text @initializer['text'] end
# File lib/playwright/channel_owners/frame.rb, line 413 def text_content(selector, strict: nil, timeout: nil) params = { selector: selector, strict: strict, timeout: timeout }.compact @channel.send_message_to_server('textContent', params) end
# File lib/playwright/channel_owners/page.rb, line 893 def timeout_settings @timeout_settings end
# File lib/playwright/channel_owners/frame.rb, line 600 def title @channel.send_message_to_server('title') end
# File lib/playwright/channel_owners/android_device.rb, line 19 def to_regex(value) case value when nil nil when Regexp value else Regexp.new("^#{value}$") end end
# File lib/playwright/channel_owners/js_handle.rb, line 8 def to_s @preview end
# File lib/playwright/channel_owners/android_device.rb, line 30 def to_selector_channel(selector) { checkable: selector[:checkable], checked: selector[:checked], clazz: to_regex(selector[:clazz]), pkg: to_regex(selector[:pkg]), desc: to_regex(selector[:desc]), res: to_regex(selector[:res]), text: to_regex(selector[:text]), clickable: selector[:clickable], depth: selector[:depth], enabled: selector[:enabled], focusable: selector[:focusable], focused: selector[:focused], hasChild: selector[:hasChild] ? { selector: to_selector_channel(selector[:hasChild][:selector]) } : nil, hasDescendant: selector[:hasDescendant] ? { selector: to_selector_channel(selector[:hasDescendant][:selector]), maxDepth: selector[:hasDescendant][:maxDepth], } : nil, longClickable: selector[:longClickable], scrollable: selector[:scrollable], selected: selector[:selected], }.compact end
# File lib/playwright/channel_owners/android_device.rb, line 68 def tree @channel.send_message_to_server('tree') end
# File lib/playwright/android_input_impl.rb, line 7 def type(text) @channel.send_message_to_server('inputType', text: text) end
# File lib/playwright/channel_owners/frame.rb, line 564 def uncheck( selector, force: nil, noWaitAfter: nil, position: nil, strict: nil, timeout: nil, trial: nil) params = { selector: selector, force: force, noWaitAfter: noWaitAfter, position: position, strict: strict, timeout: timeout, trial: trial, }.compact @channel.send_message_to_server('uncheck', params) nil end
# File lib/playwright/channel_owners/browser_context.rb, line 247 def unroute(url, handler: nil) @routes.reject! do |handler_entry| handler_entry.same_value?(url: url, handler: handler) end if @routes.count == 0 @channel.send_message_to_server('setNetworkInterceptionEnabled', enabled: false) end end
# File lib/playwright/keyboard_impl.rb, line 12 def up(key) @channel.send_message_to_server('keyboardUp', key: key) end
# File lib/playwright/channel_owners/browser.rb, line 103 def update_as_remote @remote = true end
# File lib/playwright/channel_owners/request.rb, line 89 def update_failure_text(failure_text) @failure_text = failure_text end
# File lib/playwright/channel_owners/request.rb, line 113 def update_headers(headers) @headers = parse_headers(headers) end
# File lib/playwright/channel_owners/frame.rb, line 606 def update_page_from_page(page) @page = page end
# File lib/playwright/channel_owners/request.rb, line 85 def update_redirected_to(request) @redirected_to = request end
# File lib/playwright/channel_owners/request.rb, line 117 def update_response_end_timing(response_end_timing) @timing[:responseEnd] = response_end_timing end
# File lib/playwright/channel_owners/request.rb, line 93 def update_timings( start_time:, domain_lookup_start:, domain_lookup_end:, connect_start:, secure_connection_start:, connect_end:, request_start:, response_start:) @timing[:startTime] = start_time @timing[:domainLookupStart] = domain_lookup_start @timing[:domainLookupEnd] = domain_lookup_end @timing[:connectStart] = connect_start @timing[:secureConnectionStart] = secure_connection_start @timing[:connectEnd] = connect_end @timing[:requestStart] = request_start @timing[:responseStart] = response_start end
# File lib/playwright/channel_owners/frame.rb, line 239 def url @url || '' end
# File lib/playwright/channel_owners/browser.rb, line 66 def version @initializer['version'] end
# File lib/playwright/channel_owners/page.rb, line 760 def video return nil unless @browser_context.send(:has_record_video_option?) @video ||= Video.new(self) end
# File lib/playwright/channel_owners/frame.rb, line 189 def visible?(selector, strict: nil, timeout: nil) params = { selector: selector, strict: strict, timeout: timeout }.compact @channel.send_message_to_server('isVisible', params) end
# File lib/playwright/channel_owners/frame.rb, line 591 def wait_for_function(pageFunction, arg: nil, polling: nil, timeout: nil) if polling.is_a?(String) && polling != 'raf' raise ArgumentError.new("Unknown polling option: #{polling}") end expression = JavaScript::Expression.new(pageFunction, arg) expression.wait_for_function(@channel, polling: polling, timeout: timeout) end
# File lib/playwright/channel_owners/frame.rb, line 110 def wait_for_load_state(state: nil, timeout: nil) option_state = state || 'load' option_timeout = timeout || @page.send(:timeout_settings).navigation_timeout unless %w(load domcontentloaded networkidle).include?(option_state) raise ArgumentError.new('state: expected one of (load|domcontentloaded|networkidle)') end if @load_states.include?(option_state) return end wait_helper = setup_navigation_wait_helper(timeout: option_timeout) predicate = ->(state) { state == option_state } wait_helper.wait_for_event(@event_emitter, 'loadstate', predicate: predicate) wait_helper.promise.value! nil end
# File lib/playwright/channel_owners/frame.rb, line 157 def wait_for_selector(selector, state: nil, strict: nil, timeout: nil) params = { selector: selector, state: state, strict: strict, timeout: timeout }.compact resp = @channel.send_message_to_server('waitForSelector', params) ChannelOwners::ElementHandle.from_nullable(resp) end
# File lib/playwright/channel_owners/frame.rb, line 587 def wait_for_timeout(timeout) sleep(timeout / 1000.0) end
# File lib/playwright/channel_owners/frame.rb, line 101 def wait_for_url(url, timeout: nil, waitUntil: nil) matcher = UrlMatcher.new(url, base_url: @page.context.send(:base_url)) if matcher.match?(@url) wait_for_load_state(state: waitUntil, timeout: timeout) else expect_navigation(timeout: timeout, url: url, waitUntil: waitUntil) end end
# File lib/playwright/channel_owners/playwright.rb, line 11 def webkit @webkit ||= ::Playwright::ChannelOwners::BrowserType.from(@initializer['webkit']) end
# File lib/playwright/locator_impl.rb, line 13 def with_element(timeout: nil, &block) start_time = Time.now handle = @frame.wait_for_selector(@selector, strict: true, state: 'attached', timeout: timeout) unless handle raise "Could not resolve #{@selector} to DOM Element" end call_options = {} if timeout call_options[:timeout] = (timeout - (Time.now - start_time) * 1000).to_i end begin block.call(handle, call_options) ensure handle.dispose end end
# File lib/playwright/channel_owners/page.rb, line 713 def workers @workers.to_a end