Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/rb/lib/selenium/webdriver/common/driver_extensions/uploads_files.rb
1990 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
#
23
# @api private
24
#
25
26
module DriverExtensions
27
module UploadsFiles
28
#
29
# Set the file detector to pass local files to a remote WebDriver.
30
#
31
# The detector is an object that responds to #call, and when called
32
# will determine if the given string represents a file. If it does,
33
# the path to the file on the local file system should be returned,
34
# otherwise nil or false.
35
#
36
# Example:
37
#
38
# driver = Selenium::WebDriver.for :remote
39
# driver.file_detector = lambda do |args|
40
# # args => ["/path/to/file"]
41
# str = args.first.to_s
42
# str if File.exist?(str)
43
# end
44
#
45
# driver.find_element(:id => "upload").send_keys "/path/to/file"
46
#
47
# By default, no file detection is performed.
48
#
49
# @api public
50
#
51
52
def file_detector=(detector)
53
raise ArgumentError, 'detector must respond to #call' unless detector.nil? || detector.respond_to?(:call)
54
55
bridge.file_detector = detector
56
end
57
end # UploadsFiles
58
end # DriverExtensions
59
end # WebDriver
60
end # Selenium
61
62