# frozen_string_literal: true# Licensed to the Software Freedom Conservancy (SFC) under one# or more contributor license agreements. See the NOTICE file# distributed with this work for additional information# regarding copyright ownership. The SFC licenses this file# to you under the Apache License, Version 2.0 (the# "License"); you may not use this file except in compliance# with the License. You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing,# software distributed under the License is distributed on an# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY# KIND, either express or implied. See the License for the# specific language governing permissions and limitations# under the License.moduleSeleniummoduleWebDrivermoduleSupport## @api private#classEventFiringBridgedefinitialize(delegate,listener)@delegate=delegate@listener=iflistener.respond_to?:callBlockEventListener.new(listener)elselistenerendenddefget(url)dispatch(:navigate_to,url,driver)do@delegate.get(url)endenddefgo_forwarddispatch(:navigate_forward,driver)do@delegate.go_forwardendenddefgo_backdispatch(:navigate_back,driver)do@delegate.go_backendenddefclick_element(ref)dispatch(:click,create_element(ref),driver)do@delegate.click_element(ref)endenddefclear_element(ref)dispatch(:change_value_of,create_element(ref),driver)do@delegate.clear_element(ref)endenddefsend_keys_to_element(ref,keys)dispatch(:change_value_of,create_element(ref),driver)do@delegate.send_keys_to_element(ref,keys)endenddeffind_element_by(how,what,parent=nil)e=dispatch(:find,how,what,driver)do@delegate.find_element_byhow,what,parentendElement.newself,e.ref.lastenddeffind_elements_by(how,what,parent=nil)es=dispatch(:find,how,what,driver)do@delegate.find_elements_by(how,what,parent)endes.map{|e|Element.newself,e.ref.last}enddefexecute_script(script,*args)dispatch(:execute_script,script,driver)do@delegate.execute_script(script,*args)endenddefquitdispatch(:quit,driver){@delegate.quit}enddefclosedispatch(:close,driver){@delegate.close}endprivatedefcreate_element(ref)# hmm. we're not passing self here to not fire events for potential calls made by the listenerElement.new@delegate,refenddefdriver@driver||=Driver.new(bridge: self)enddefdispatch(name,*args)@listener.__send__(:"before_#{name}",*args)returned=yield@listener.__send__(:"after_#{name}",*args)returnedenddefmethod_missing(meth,...)# rubocop:disable Style/MissingRespondToMissing@delegate.__send__(meth,...)endend# EventFiringBridgeend# Supportend# WebDriverend# Selenium