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
29
29
attr_accessor :http , :file_detector
30
30
attr_reader :capabilities
31
31
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
+
32
42
#
33
43
# Initializes the bridge with the given server URL
34
44
# @param [String, URI] url url for the remote server
@@ -612,7 +622,7 @@ def escaper
612
622
end
613
623
614
624
def commands ( command )
615
- command_list [ command ]
625
+ command_list [ command ] || Bridge . extra_commands [ command ]
616
626
end
617
627
618
628
def unwrap_script_result ( arg )
Original file line number Diff line number Diff line change @@ -23,6 +23,33 @@ module Selenium
23
23
module WebDriver
24
24
module Remote
25
25
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
+
26
53
describe '#initialize' do
27
54
it 'raises ArgumentError if passed invalid options' do
28
55
expect { described_class . new ( foo : 'bar' ) } . to raise_error ( ArgumentError )
You can’t perform that action at this time.
0 commit comments