Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/rb/lib/selenium/webdriver/remote/features.rb
1865 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
module Remote
23
module Features
24
REMOTE_COMMANDS = {
25
upload_file: [:post, 'session/:session_id/se/file'],
26
get_downloadable_files: [:get, 'session/:session_id/se/files'],
27
download_file: [:post, 'session/:session_id/se/files'],
28
delete_downloadable_files: [:delete, 'session/:session_id/se/files']
29
}.freeze
30
31
def add_commands(commands)
32
@command_list = command_list.merge(commands)
33
end
34
35
def command_list
36
@command_list ||= REMOTE_COMMANDS
37
end
38
39
def commands(command)
40
command_list[command]
41
end
42
43
def upload(local_file)
44
unless File.file?(local_file)
45
WebDriver.logger.error("File detector only works with files. #{local_file.inspect} isn`t a file!",
46
id: :file_detector)
47
raise Error::WebDriverError, "You are trying to upload something that isn't a file."
48
end
49
50
execute :upload_file, {}, {file: Zipper.zip_file(local_file)}
51
end
52
53
def upload_if_necessary(keys)
54
local_files = keys.first&.split("\n")&.filter_map { |key| @file_detector.call(Array(key)) }
55
return keys unless local_files&.any?
56
57
keys = local_files.map { |local_file| upload(local_file) }
58
Array(keys.join("\n"))
59
end
60
61
def downloadable_files
62
execute :get_downloadable_files
63
end
64
65
def download_file(name)
66
execute :download_file, {}, {name: name}
67
end
68
69
def delete_downloadable_files
70
execute :delete_downloadable_files
71
end
72
end
73
end # Remote
74
end # WebDriver
75
end # Selenium
76
77