Class: Playwright::WebSocket

Inherits:
PlaywrightApi show all
Defined in:
lib/playwright_api/web_socket.rb

Overview

The ‘WebSocket` class represents websocket connections in the page.

Instance Method Summary collapse

Methods inherited from PlaywrightApi

#initialize, unwrap, wrap

Constructor Details

This class inherits a constructor from Playwright::PlaywrightApi

Instance Method Details

#closed?Boolean

Indicates that the web socket has been closed.

Returns:

  • (Boolean)


8
9
10
# File 'lib/playwright_api/web_socket.rb', line 8

def closed?
  wrap_impl(@impl.closed?)
end

#expect_event(event, predicate: nil, timeout: nil, &block) ⇒ Object

Waits for event to fire and passes its value into the predicate function. Returns when the predicate returns truthy value. Will throw an error if the webSocket is closed before the event is fired. Returns the event data value.



21
22
23
# File 'lib/playwright_api/web_socket.rb', line 21

def expect_event(event, predicate: nil, timeout: nil, &block)
  wrap_impl(@impl.expect_event(unwrap_impl(event), predicate: unwrap_impl(predicate), timeout: unwrap_impl(timeout), &wrap_block_call(block)))
end

#off(event, callback) ⇒ Object

– inherited from EventEmitter –



37
38
39
# File 'lib/playwright_api/web_socket.rb', line 37

def off(event, callback)
  event_emitter_proxy.off(event, callback)
end

#on(event, callback) ⇒ Object

– inherited from EventEmitter –



49
50
51
# File 'lib/playwright_api/web_socket.rb', line 49

def on(event, callback)
  event_emitter_proxy.on(event, callback)
end

#once(event, callback) ⇒ Object

– inherited from EventEmitter –



43
44
45
# File 'lib/playwright_api/web_socket.rb', line 43

def once(event, callback)
  event_emitter_proxy.once(event, callback)
end

#urlObject

Contains the URL of the WebSocket.



14
15
16
# File 'lib/playwright_api/web_socket.rb', line 14

def url
  wrap_impl(@impl.url)
end

#wait_for_event(event, predicate: nil, timeout: nil, &block) ⇒ Object

NOTE: In most cases, you should use [‘method: WebSocket.waitForEvent`].

Waits for given ‘event` to fire. If predicate is provided, it passes event’s value into the ‘predicate` function and waits for `predicate(event)` to return a truthy value. Will throw an error if the socket is closed before the `event` is fired.



31
32
33
# File 'lib/playwright_api/web_socket.rb', line 31

def wait_for_event(event, predicate: nil, timeout: nil, &block)
  wrap_impl(@impl.wait_for_event(unwrap_impl(event), predicate: unwrap_impl(predicate), timeout: unwrap_impl(timeout), &wrap_block_call(block)))
end