Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/rb/lib/selenium/webdriver.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
require 'tmpdir'
21
require 'fileutils'
22
require 'date'
23
require 'json'
24
require 'uri'
25
require 'net/http'
26
27
require 'selenium/webdriver/atoms'
28
require 'selenium/webdriver/common'
29
require 'selenium/webdriver/version'
30
31
module Selenium
32
module WebDriver
33
Point = Struct.new(:x, :y)
34
Dimension = Struct.new(:width, :height)
35
Rectangle = Struct.new(:x, :y, :width, :height)
36
37
autoload :BiDi, 'selenium/webdriver/bidi'
38
autoload :Chromium, 'selenium/webdriver/chromium'
39
autoload :Chrome, 'selenium/webdriver/chrome'
40
autoload :DevTools, 'selenium/webdriver/devtools'
41
autoload :Edge, 'selenium/webdriver/edge'
42
autoload :Firefox, 'selenium/webdriver/firefox'
43
autoload :IE, 'selenium/webdriver/ie'
44
autoload :Remote, 'selenium/webdriver/remote'
45
autoload :Safari, 'selenium/webdriver/safari'
46
autoload :Support, 'selenium/webdriver/support'
47
48
# @api private
49
50
def self.root
51
@root ||= File.expand_path('..', __dir__.to_s)
52
end
53
54
#
55
# Create a new Driver instance with the correct bridge for the given browser
56
#
57
# @overload for(browser)
58
# @param [:ie, :internet_explorer, :edge, :remote, :chrome, :firefox, :ff, :safari] browser The browser to
59
# create the driver for
60
# @overload for(browser, opts)
61
# @param [:ie, :internet_explorer, :edge, :remote, :chrome, :firefox, :ff, :safari] browser The browser to
62
# create the driver for
63
# @param [Hash] opts Options passed to Driver.new
64
#
65
# @return [Driver]
66
#
67
# @see Selenium::WebDriver::Remote::Driver
68
# @see Selenium::WebDriver::Firefox::Driver
69
# @see Selenium::WebDriver::IE::Driver
70
# @see Selenium::WebDriver::Edge::Driver
71
# @see Selenium::WebDriver::Chrome::Driver
72
# @see Selenium::WebDriver::Safari::Driver
73
#
74
# @example
75
#
76
# WebDriver.for :firefox, profile: 'some-profile'
77
# WebDriver.for :firefox, profile: Profile.new
78
# WebDriver.for :remote, url: "http://localhost:4444/wd/hub", capabilities: caps
79
#
80
# One special argument is not passed on to the bridges, :listener.
81
# You can pass a listener for this option to get notified of WebDriver events.
82
# The passed object must respond to #call or implement the methods from AbstractEventListener.
83
#
84
# @see Selenium::WebDriver::Support::AbstractEventListener
85
#
86
87
def self.for(*)
88
WebDriver::Driver.for(*)
89
end
90
91
#
92
# Returns logger instance that can be used across the whole Selenium.
93
#
94
# @return [Logger]
95
#
96
97
def self.logger(**)
98
level = $DEBUG || ENV.key?('DEBUG') ? :debug : :info
99
@logger ||= WebDriver::Logger.new('Selenium', default_level: level, **)
100
end
101
end # WebDriver
102
end # Selenium
103
104