Class: Selenium::WebDriver::DevTools
Relationships & Source Files | |
Namespace Children | |
Classes:
| |
Inherits: | Object |
Defined in: | rb/lib/selenium/webdriver/devtools.rb, rb/lib/selenium/webdriver/devtools/console_event.rb, rb/lib/selenium/webdriver/devtools/exception_event.rb, rb/lib/selenium/webdriver/devtools/mutation_event.rb, rb/lib/selenium/webdriver/devtools/network_interceptor.rb, rb/lib/selenium/webdriver/devtools/pinned_script.rb, rb/lib/selenium/webdriver/devtools/request.rb, rb/lib/selenium/webdriver/devtools/response.rb |
Class Method Summary
- .new(url:) ⇒ DevTools constructor
Instance Method Summary
Constructor Details
.new(url:) ⇒ DevTools
# File 'rb/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)
[ GitHub ]# File 'rb/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) # selenium-devtools 0.113 and newer "#{namespace}::#{Object.const_get(methods_to_classes)[method]}" else # selenium-devtools 0.112 and older "#{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
[ GitHub ]# File 'rb/lib/selenium/webdriver/devtools.rb', line 41
def callbacks @ws.callbacks end
#close
[ GitHub ]# File 'rb/lib/selenium/webdriver/devtools.rb', line 37
def close @ws.close end
#error_message(error) (private)
[ GitHub ]# File 'rb/lib/selenium/webdriver/devtools.rb', line 91
def (error) [error['code'], error['message'], error['data']].join(': ') end
#respond_to_missing?(method, *_args) ⇒ Boolean
#send_cmd(method, **params)
# File 'rb/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 = @ws.send_cmd(**data) raise Error::WebDriverError, ( ['error']) if ['error'] end
#start_session (private)
[ GitHub ]# File 'rb/lib/selenium/webdriver/devtools.rb', line 84
def start_session targets = target.get_targets.dig('result', 'targetInfos') page_target = targets.find { |target| target['type'] == 'page' } session = target.attach_to_target(target_id: page_target['targetId'], flatten: true) @session_id = session.dig('result', 'sessionId') end