Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/rb/lib/selenium/webdriver/bidi.rb
4016 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 :LogHandler, 'selenium/webdriver/bidi/log_handler'
25
autoload :Browser, 'selenium/webdriver/bidi/browser'
26
autoload :BrowsingContext, 'selenium/webdriver/bidi/browsing_context'
27
autoload :Struct, 'selenium/webdriver/bidi/struct'
28
autoload :Network, 'selenium/webdriver/bidi/network'
29
autoload :InterceptedRequest, 'selenium/webdriver/bidi/network/intercepted_request'
30
autoload :InterceptedResponse, 'selenium/webdriver/bidi/network/intercepted_response'
31
autoload :InterceptedAuth, 'selenium/webdriver/bidi/network/intercepted_auth'
32
autoload :InterceptedItem, 'selenium/webdriver/bidi/network/intercepted_item'
33
34
def initialize(url:)
35
@ws = WebSocketConnection.new(url: url)
36
end
37
38
def close
39
@ws.close
40
end
41
42
def callbacks
43
@ws.callbacks
44
end
45
46
def add_callback(event, &block)
47
@ws.add_callback(event, &block)
48
end
49
50
def remove_callback(event, id)
51
@ws.remove_callback(event, id)
52
end
53
54
def session
55
@session ||= Session.new(self)
56
end
57
58
def send_cmd(method, **params)
59
data = {method: method, params: params.compact}
60
message = @ws.send_cmd(**data)
61
raise Error::WebDriverError, error_message(message) if message['error']
62
63
message['result']
64
end
65
66
def error_message(message)
67
"#{message['error']}: #{message['message']}\n#{message['stacktrace']}"
68
end
69
end # BiDi
70
end # WebDriver
71
end # Selenium
72
73