File tree Expand file tree Collapse file tree 2 files changed +38
-1
lines changed
lib/selenium/webdriver/remote
spec/unit/selenium/webdriver/remote Expand file tree Collapse file tree 2 files changed +38
-1
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,16 @@ class Bridge
2929 attr_accessor :http , :file_detector
3030 attr_reader :capabilities
3131
32+ class << self
33+ attr_reader :extra_commands
34+
35+ def add_command ( name , verb , url , &block )
36+ @extra_commands ||= { }
37+ @extra_commands [ name ] = [ verb , url ]
38+ define_method ( name , &block )
39+ end
40+ end
41+
3242 #
3343 # Initializes the bridge with the given server URL
3444 # @param [String, URI] url url for the remote server
@@ -612,7 +622,7 @@ def escaper
612622 end
613623
614624 def commands ( command )
615- command_list [ command ]
625+ command_list [ command ] || Bridge . extra_commands [ command ]
616626 end
617627
618628 def unwrap_script_result ( arg )
Original file line number Diff line number Diff line change @@ -23,6 +23,33 @@ module Selenium
2323 module WebDriver
2424 module Remote
2525 describe Bridge do
26+ describe '.add_command' do
27+ let ( :http ) { WebDriver ::Remote ::Http ::Default . new }
28+ let ( :bridge ) { described_class . new ( http_client : http , url : 'http://localhost' ) }
29+
30+ before do
31+ allow ( http ) . to receive ( :request )
32+ . with ( any_args )
33+ . and_return ( 'status' => 200 , 'value' => { 'sessionId' => 'foo' , 'capabilities' => { } } )
34+
35+ bridge . create_session ( { } )
36+ end
37+
38+ after do
39+ described_class . extra_commands . clear
40+ end
41+
42+ it 'adds new command' do
43+ described_class . add_command ( :highlight , :get , 'session/:session_id/highlight/:id' ) do |element |
44+ execute :highlight , id : element
45+ end
46+
47+ bridge . highlight ( 'bar' )
48+ expect ( http ) . to have_received ( :request )
49+ . with ( :get , URI ( 'http://localhost/session/foo/highlight/bar' ) , any_args )
50+ end
51+ end
52+
2653 describe '#initialize' do
2754 it 'raises ArgumentError if passed invalid options' do
2855 expect { described_class . new ( foo : 'bar' ) } . to raise_error ( ArgumentError )
You can’t perform that action at this time.
0 commit comments