Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/rb/lib/selenium/devtools.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 DevTools
22
class << self
23
attr_accessor :version
24
25
def load_version
26
require "selenium/devtools/v#{@version}"
27
rescue LoadError
28
WebDriver.logger.warn "Could not load selenium-devtools v#{@version}. Trying older versions.",
29
id: :devtools
30
load_older_version
31
end
32
33
private
34
35
# Try to load up to 2 versions back
36
def load_older_version
37
load_old_version(@version - 1)
38
rescue LoadError
39
begin
40
load_old_version(@version - 2)
41
rescue LoadError
42
raise WebDriver::Error::WebDriverError,
43
'Could not find a valid devtools version; use a more recent version of selenium-devtools gem'
44
end
45
end
46
47
def load_old_version(version)
48
require "selenium/devtools/v#{version}"
49
self.version = version
50
msg = "Using selenium-devtools version v#{version}, some features may not work as expected."
51
WebDriver.logger.warn msg, id: :devtools
52
end
53
end
54
end # DevTools
55
end # Selenium
56
57