File tree Expand file tree Collapse file tree 2 files changed +26
-2
lines changed
lib/selenium/webdriver/common
spec/unit/selenium/webdriver Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,14 @@ module SearchContext
3535 xpath : 'xpath'
3636 } . freeze
3737
38+ class << self
39+ attr_accessor :extra_finders
40+
41+ def finders
42+ FINDERS . merge ( extra_finders || { } )
43+ end
44+ end
45+
3846 #
3947 # Find the first element matching the given arguments
4048 #
@@ -57,7 +65,7 @@ module SearchContext
5765 def find_element ( *args )
5866 how , what = extract_args ( args )
5967
60- by = FINDERS [ how . to_sym ]
68+ by = SearchContext . finders [ how . to_sym ]
6169 raise ArgumentError , "cannot find element by #{ how . inspect } " unless by
6270
6371 bridge . find_element_by by , what , ref
@@ -72,7 +80,7 @@ def find_element(*args)
7280 def find_elements ( *args )
7381 how , what = extract_args ( args )
7482
75- by = FINDERS [ how . to_sym ]
83+ by = SearchContext . finders [ how . to_sym ]
7684 raise ArgumentError , "cannot find elements by #{ how . inspect } " unless by
7785
7886 bridge . find_elements_by by , what , ref
Original file line number Diff line number Diff line change @@ -89,6 +89,22 @@ def initialize(bridge)
8989 } . to raise_error ( ArgumentError , 'cannot find elements by :foo' )
9090 end
9191 end
92+
93+ context 'when extra finders are registered' do
94+ around do |example |
95+ described_class . extra_finders = { accessibility_id : 'accessibility id' }
96+ example . call
97+ ensure
98+ described_class . extra_finders = nil
99+ end
100+
101+ it 'finds element' do
102+ allow ( bridge ) . to receive ( :find_element_by ) . with ( 'accessibility id' , 'foo' , nil ) . and_return ( element )
103+
104+ expect ( search_context . find_element ( accessibility_id : 'foo' ) ) . to eq ( element )
105+ expect ( bridge ) . to have_received ( :find_element_by ) . with ( 'accessibility id' , 'foo' , nil )
106+ end
107+ end
92108 end
93109 end # WebDriver
94110end # Selenium
You can’t perform that action at this time.
0 commit comments