Class: Leash::Integration::PuppeteerClient

Inherits:
Object
  • Object
show all
Defined in:
lib/leash/integration/puppeteer.rb

Instance Method Summary collapse

Constructor Details

#initialize(leash) ⇒ PuppeteerClient

Create a new Puppeteer integration client.

Parameters:

  • leash (Leash::Client)

    the Leash SDK client



11
12
13
# File 'lib/leash/integration/puppeteer.rb', line 11

def initialize(leash)
  @leash = leash
end

Instance Method Details

#puppeteer_click(selector) ⇒ Object

Click an element on the page

Parameters:

  • selector (String)

    CSS selector for element to click

Returns:

  • (Object)


53
54
55
56
57
58
# File 'lib/leash/integration/puppeteer.rb', line 53

def puppeteer_click(selector)
  params = {
    'selector' => selector
  }.compact
  @leash.call('puppeteer', 'puppeteer_click', params)
end

#puppeteer_evaluate(script) ⇒ Object

Execute JavaScript in the browser console

Parameters:

  • script (String)

    JavaScript code to execute

Returns:

  • (Object)


101
102
103
104
105
106
# File 'lib/leash/integration/puppeteer.rb', line 101

def puppeteer_evaluate(script)
  params = {
    'script' => script
  }.compact
  @leash.call('puppeteer', 'puppeteer_evaluate', params)
end

#puppeteer_fill(selector, value) ⇒ Object

Fill out an input field

Parameters:

  • selector (String)

    CSS selector for input field

  • value (String)

    Value to fill

Returns:

  • (Object)


65
66
67
68
69
70
71
# File 'lib/leash/integration/puppeteer.rb', line 65

def puppeteer_fill(selector, value)
  params = {
    'selector' => selector,
    'value' => value
  }.compact
  @leash.call('puppeteer', 'puppeteer_fill', params)
end

#puppeteer_hover(selector) ⇒ Object

Hover an element on the page

Parameters:

  • selector (String)

    CSS selector for element to hover

Returns:

  • (Object)


90
91
92
93
94
95
# File 'lib/leash/integration/puppeteer.rb', line 90

def puppeteer_hover(selector)
  params = {
    'selector' => selector
  }.compact
  @leash.call('puppeteer', 'puppeteer_hover', params)
end

#puppeteer_navigate(url, launchoptions: nil, allowdangerous: nil) ⇒ Object

Navigate to a URL

Parameters:

  • url (String)

    URL to navigate to

  • launchoptions (Hash, nil) (defaults to: nil)

    PuppeteerJS LaunchOptions. Default null. If changed and not null, browser restarts. Example: { headless: true, args: [‘–no-sandbox’] }

  • allowdangerous (Boolean, nil) (defaults to: nil)

    Allow dangerous LaunchOptions that reduce security. When false, dangerous args like –no-sandbox will throw errors. Default false.

Returns:

  • (Object)


21
22
23
24
25
26
27
28
# File 'lib/leash/integration/puppeteer.rb', line 21

def puppeteer_navigate(url, launchoptions: nil, allowdangerous: nil)
  params = {
    'url' => url,
    'launchOptions' => launchoptions,
    'allowDangerous' => allowdangerous
  }.compact
  @leash.call('puppeteer', 'puppeteer_navigate', params)
end

#puppeteer_screenshot(name, selector: nil, width: nil, height: nil, encoded: nil) ⇒ Object

Take a screenshot of the current page or a specific element

Parameters:

  • name (String)

    Name for the screenshot

  • selector (String, nil) (defaults to: nil)

    CSS selector for element to screenshot

  • width (Float, nil) (defaults to: nil)

    Width in pixels (default: 800)

  • height (Float, nil) (defaults to: nil)

    Height in pixels (default: 600)

  • encoded (Boolean, nil) (defaults to: nil)

    If true, capture the screenshot as a base64-encoded data URI (as text) instead of binary image content. Default false.

Returns:

  • (Object)


38
39
40
41
42
43
44
45
46
47
# File 'lib/leash/integration/puppeteer.rb', line 38

def puppeteer_screenshot(name, selector: nil, width: nil, height: nil, encoded: nil)
  params = {
    'name' => name,
    'selector' => selector,
    'width' => width,
    'height' => height,
    'encoded' => encoded
  }.compact
  @leash.call('puppeteer', 'puppeteer_screenshot', params)
end

#puppeteer_select(selector, value) ⇒ Object

Select an element on the page with Select tag

Parameters:

  • selector (String)

    CSS selector for element to select

  • value (String)

    Value to select

Returns:

  • (Object)


78
79
80
81
82
83
84
# File 'lib/leash/integration/puppeteer.rb', line 78

def puppeteer_select(selector, value)
  params = {
    'selector' => selector,
    'value' => value
  }.compact
  @leash.call('puppeteer', 'puppeteer_select', params)
end