Path: blob/trunk/rb/lib/selenium/webdriver/remote/features.rb
4014 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'],28fire_session_event: [:post, 'session/:session_id/se/event']29}.freeze3031def add_commands(commands)32@command_list = command_list.merge(commands)33end3435def command_list36@command_list ||= REMOTE_COMMANDS37end3839def commands(command)40command_list[command]41end4243def upload(local_file)44unless File.file?(local_file)45WebDriver.logger.error("File detector only works with files. #{local_file.inspect} isn`t a file!",46id: :file_detector)47raise Error::WebDriverError, "You are trying to upload something that isn't a file."48end4950execute :upload_file, {}, {file: Zipper.zip_file(local_file)}51end5253def upload_if_necessary(keys)54local_files = keys.first&.split("\n")&.filter_map { |key| @file_detector.call(Array(key)) }55return keys unless local_files&.any?5657keys = local_files.map { |local_file| upload(local_file) }58Array(keys.join("\n"))59end6061def downloadable_files62execute :get_downloadable_files63end6465def download_file(name)66execute :download_file, {}, {name: name}67end6869def delete_downloadable_files70execute :delete_downloadable_files71end7273#74# Fires a custom session event to the remote server event bus.75# This allows test code to trigger server-side utilities that subscribe to76# the event bus.77#78# @param [String] event_type The type of event (e.g., "test:failed", "log:collect")79# @param [Hash] payload Optional data to include with the event80# @return [Hash] Response data including success status, event type, and timestamp81#82# @example Fire a simple event83# driver.fire_session_event("test:started")84#85# @example Fire an event with payload86# driver.fire_session_event("test:failed", {87# testName: "LoginTest",88# error: "Element not found"89# })90#91def fire_session_event(event_type, payload = nil)92params = {eventType: event_type}93params[:payload] = payload if payload94execute :fire_session_event, {}, params95end96end97end # Remote98end # WebDriver99end # Selenium100101102