Class: Selenium::WebDriver::DevTools
- Inherits:
-
Object
- Object
- Selenium::WebDriver::DevTools
show all
- Defined in:
- lib/selenium/webdriver/devtools.rb,
lib/selenium/webdriver/devtools/request.rb,
lib/selenium/webdriver/devtools/response.rb,
lib/selenium/webdriver/devtools/console_event.rb,
lib/selenium/webdriver/devtools/pinned_script.rb,
lib/selenium/webdriver/devtools/mutation_event.rb,
lib/selenium/webdriver/devtools/exception_event.rb,
lib/selenium/webdriver/devtools/network_interceptor.rb
Defined Under Namespace
Classes: ConsoleEvent, ExceptionEvent, MutationEvent, NetworkInterceptor, PinnedScript, Request, Response
Instance Method Summary
collapse
Constructor Details
#initialize(url:) ⇒ DevTools
Returns a new instance of DevTools.
31
32
33
34
35
|
# File 'lib/selenium/webdriver/devtools.rb', line 31
def initialize(url:)
@ws = WebSocketConnection.new(url: url)
@session_id = nil
start_session
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *_args) ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/selenium/webdriver/devtools.rb', line 54
def method_missing(method, *_args)
namespace = "Selenium::DevTools::V#{Selenium::DevTools.version}"
methods_to_classes = "#{namespace}::METHODS_TO_CLASSES"
desired_class = if Object.const_defined?(methods_to_classes)
"#{namespace}::#{Object.const_get(methods_to_classes)[method]}"
else
"#{namespace}::#{method.capitalize}"
end
return unless Object.const_defined?(desired_class)
self.class.class_eval do
define_method(method) do
Object.const_get(desired_class).new(self)
end
end
send(method)
end
|
Instance Method Details
#callbacks ⇒ Object
41
42
43
|
# File 'lib/selenium/webdriver/devtools.rb', line 41
def callbacks
@ws.callbacks
end
|
#close ⇒ Object
37
38
39
|
# File 'lib/selenium/webdriver/devtools.rb', line 37
def close
@ws.close
end
|
#respond_to_missing?(method, *_args) ⇒ Boolean
77
78
79
80
|
# File 'lib/selenium/webdriver/devtools.rb', line 77
def respond_to_missing?(method, *_args)
desired_class = "Selenium::DevTools::V#{Selenium::DevTools.version}::#{method.capitalize}"
Object.const_defined?(desired_class)
end
|
#send_cmd(method, **params) ⇒ Object
45
46
47
48
49
50
51
52
|
# File 'lib/selenium/webdriver/devtools.rb', line 45
def send_cmd(method, **params)
data = {method: method, params: params.compact}
data[:sessionId] = @session_id if @session_id
message = @ws.send_cmd(**data)
raise Error::WebDriverError, error_message(message['error']) if message['error']
message
end
|