Path: blob/trunk/rb/lib/selenium/webdriver/remote/features.rb
1865 views
# frozen_string_literal: true12# Licensed to the Software Freedom Conservancy (SFC) under one3# or more contributor license agreements. See the NOTICE file4# distributed with this work for additional information5# regarding copyright ownership. The SFC licenses this file6# to you under the Apache License, Version 2.0 (the7# "License"); you may not use this file except in compliance8# with the License. You may obtain a copy of the License at9#10# http://www.apache.org/licenses/LICENSE-2.011#12# Unless required by applicable law or agreed to in writing,13# software distributed under the License is distributed on an14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15# KIND, either express or implied. See the License for the16# specific language governing permissions and limitations17# under the License.1819module Selenium20module WebDriver21module Remote22module Features23REMOTE_COMMANDS = {24upload_file: [:post, 'session/:session_id/se/file'],25get_downloadable_files: [:get, 'session/:session_id/se/files'],26download_file: [:post, 'session/:session_id/se/files'],27delete_downloadable_files: [:delete, 'session/:session_id/se/files']28}.freeze2930def add_commands(commands)31@command_list = command_list.merge(commands)32end3334def command_list35@command_list ||= REMOTE_COMMANDS36end3738def commands(command)39command_list[command]40end4142def upload(local_file)43unless File.file?(local_file)44WebDriver.logger.error("File detector only works with files. #{local_file.inspect} isn`t a file!",45id: :file_detector)46raise Error::WebDriverError, "You are trying to upload something that isn't a file."47end4849execute :upload_file, {}, {file: Zipper.zip_file(local_file)}50end5152def upload_if_necessary(keys)53local_files = keys.first&.split("\n")&.filter_map { |key| @file_detector.call(Array(key)) }54return keys unless local_files&.any?5556keys = local_files.map { |local_file| upload(local_file) }57Array(keys.join("\n"))58end5960def downloadable_files61execute :get_downloadable_files62end6364def download_file(name)65execute :download_file, {}, {name: name}66end6768def delete_downloadable_files69execute :delete_downloadable_files70end71end72end # Remote73end # WebDriver74end # Selenium757677