Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/rb/lib/selenium/webdriver/bidi.rb
1864 views
1
# frozen_string_literal: true
2
3
# Licensed to the Software Freedom Conservancy (SFC) under one
4
# or more contributor license agreements. See the NOTICE file
5
# distributed with this work for additional information
6
# regarding copyright ownership. The SFC licenses this file
7
# to you under the Apache License, Version 2.0 (the
8
# "License"); you may not use this file except in compliance
9
# with the License. You may obtain a copy of the License at
10
#
11
# http://www.apache.org/licenses/LICENSE-2.0
12
#
13
# Unless required by applicable law or agreed to in writing,
14
# software distributed under the License is distributed on an
15
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
# KIND, either express or implied. See the License for the
17
# specific language governing permissions and limitations
18
# under the License.
19
20
module Selenium
21
module WebDriver
22
class BiDi
23
autoload :Session, 'selenium/webdriver/bidi/session'
24
autoload :LogInspector, 'selenium/webdriver/bidi/log_inspector'
25
autoload :LogHandler, 'selenium/webdriver/bidi/log_handler'
26
autoload :Browser, 'selenium/webdriver/bidi/browser'
27
autoload :BrowsingContext, 'selenium/webdriver/bidi/browsing_context'
28
autoload :Struct, 'selenium/webdriver/bidi/struct'
29
autoload :Network, 'selenium/webdriver/bidi/network'
30
autoload :InterceptedRequest, 'selenium/webdriver/bidi/network/intercepted_request'
31
autoload :InterceptedResponse, 'selenium/webdriver/bidi/network/intercepted_response'
32
autoload :InterceptedAuth, 'selenium/webdriver/bidi/network/intercepted_auth'
33
autoload :InterceptedItem, 'selenium/webdriver/bidi/network/intercepted_item'
34
35
def initialize(url:)
36
@ws = WebSocketConnection.new(url: url)
37
end
38
39
def close
40
@ws.close
41
end
42
43
def callbacks
44
@ws.callbacks
45
end
46
47
def add_callback(event, &block)
48
@ws.add_callback(event, &block)
49
end
50
51
def remove_callback(event, id)
52
@ws.remove_callback(event, id)
53
end
54
55
def session
56
@session ||= Session.new(self)
57
end
58
59
def send_cmd(method, **params)
60
data = {method: method, params: params.compact}
61
message = @ws.send_cmd(**data)
62
raise Error::WebDriverError, error_message(message) if message['error']
63
64
message['result']
65
end
66
67
def error_message(message)
68
"#{message['error']}: #{message['message']}\n#{message['stacktrace']}"
69
end
70
end # BiDi
71
end # WebDriver
72
end # Selenium
73
74