Class: Playwright::ConsoleMessage

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

Overview

‘ConsoleMessage` objects are dispatched by page via the [`event: Page.console`] event. For each console messages logged in the page there will be corresponding event in the Playwright context.

“‘python sync # Listen for all console logs page.on(“console”, lambda msg: print(msg.text))

# Listen for all console events and handle errors page.on(“console”, lambda msg: print(f“error: msgmsg.text”) if msg.type == “error” else None)

# Get the next console log with page.expect_console_message() as msg_info:

# Issue console.log inside the page
page.evaluate("console.log('hello', 42, { foo: 'bar' })")

msg = msg_info.value

# Deconstruct print arguments msg.args.json_value() # hello msg.args.json_value() # 42 “‘

Instance Method Summary collapse

Methods inherited from PlaywrightApi

#initialize, unwrap, wrap

Constructor Details

This class inherits a constructor from Playwright::PlaywrightApi

Instance Method Details

#argsObject

List of arguments passed to a ‘console` function call. See also [`event: Page.console`].



28
29
30
# File 'lib/playwright_api/console_message.rb', line 28

def args
  wrap_impl(@impl.args)
end

#locationObject



32
33
34
# File 'lib/playwright_api/console_message.rb', line 32

def location
  wrap_impl(@impl.location)
end

#off(event, callback) ⇒ Object

– inherited from EventEmitter –



58
59
60
# File 'lib/playwright_api/console_message.rb', line 58

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

#on(event, callback) ⇒ Object

– inherited from EventEmitter –



70
71
72
# File 'lib/playwright_api/console_message.rb', line 70

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

#once(event, callback) ⇒ Object

– inherited from EventEmitter –



64
65
66
# File 'lib/playwright_api/console_message.rb', line 64

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

#pageObject

The page that produced this console message, if any.



38
39
40
# File 'lib/playwright_api/console_message.rb', line 38

def page
  wrap_impl(@impl.page)
end

#textObject

The text of the console message.



44
45
46
# File 'lib/playwright_api/console_message.rb', line 44

def text
  wrap_impl(@impl.text)
end

#typeObject

One of the following values: ‘’log’‘, `’debug’‘, `’info’‘, `’error’‘, `’warning’‘, `’dir’‘, `’dirxml’‘, `’table’‘, `’trace’‘, `’clear’‘, `’startGroup’‘, `’startGroupCollapsed’‘, `’endGroup’‘, `’assert’‘, `’profile’‘, `’profileEnd’‘, `’count’‘, `’timeEnd’‘.



52
53
54
# File 'lib/playwright_api/console_message.rb', line 52

def type
  wrap_impl(@impl.type)
end