Class: Perus::Pinger::ChromeExecute

Inherits:
ChromeCommand show all
Defined in:
lib/perus/pinger/commands/chrome_execute.rb

Instance Attribute Summary

Attributes inherited from Command

#id, #options

Instance Method Summary collapse

Methods inherited from ChromeCommand

#execute, #send_command

Methods inherited from Command

abstract!, abstract?, #cleanup, #darwin?, description, human_name, inherited, #initialize, metric!, metric?, option, options, #shell, subclasses

Constructor Details

This class inherits a constructor from Perus::Pinger::Command

Instance Method Details

#runObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/perus/pinger/commands/chrome_execute.rb', line 7

def run
    result = false
    command = '{"id":1,"method":"Runtime.evaluate","params":{"expression":"' + options.js.gsub('"', '\\"') + '","objectGroup":"perus","returnByValue":true}}'
    
    execute([command]) do |message|
        if message.include?('id') && message['id'] == 1
            if message.include?('result')
                result = message['result'].to_s
            elsif message.include?('error')
                result = message['error'].to_s
            else
                result = false
            end

            # clean up any memory used by the executed command
            send_command('{"id":2,"method":"Runtime.releaseObjectGroup","params":{"objectGroup":"perus"}}')
        end
    end

    result
end