File tree 2 files changed +26
-2
lines changed
lib/selenium/webdriver/common
spec/unit/selenium/webdriver
2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,14 @@ module SearchContext
35
35
xpath : 'xpath'
36
36
} . freeze
37
37
38
+ class << self
39
+ attr_accessor :extra_finders
40
+
41
+ def finders
42
+ FINDERS . merge ( extra_finders || { } )
43
+ end
44
+ end
45
+
38
46
#
39
47
# Find the first element matching the given arguments
40
48
#
@@ -57,7 +65,7 @@ module SearchContext
57
65
def find_element ( *args )
58
66
how , what = extract_args ( args )
59
67
60
- by = FINDERS [ how . to_sym ]
68
+ by = SearchContext . finders [ how . to_sym ]
61
69
raise ArgumentError , "cannot find element by #{ how . inspect } " unless by
62
70
63
71
bridge . find_element_by by , what , ref
@@ -72,7 +80,7 @@ def find_element(*args)
72
80
def find_elements ( *args )
73
81
how , what = extract_args ( args )
74
82
75
- by = FINDERS [ how . to_sym ]
83
+ by = SearchContext . finders [ how . to_sym ]
76
84
raise ArgumentError , "cannot find elements by #{ how . inspect } " unless by
77
85
78
86
bridge . find_elements_by by , what , ref
Original file line number Diff line number Diff line change @@ -89,6 +89,22 @@ def initialize(bridge)
89
89
} . to raise_error ( ArgumentError , 'cannot find elements by :foo' )
90
90
end
91
91
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
92
108
end
93
109
end # WebDriver
94
110
end # Selenium
You can’t perform that action at this time.
0 commit comments