Class: Pincers::Core::SearchContext
Constant Summary
Extension::Queries::TEXT_INPUTS
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#[](*args) ⇒ Object
-
#[]=(key, value) ⇒ Object
-
#attribute(_name, _value = nil) ⇒ Object
-
#backend ⇒ Object
-
#click(*_modifiers) ⇒ Object
-
#double_click ⇒ Object
-
#drag_to(_element) ⇒ Object
-
#each ⇒ Object
-
#element ⇒ Object
-
#element! ⇒ Object
-
#elements ⇒ Object
-
#first ⇒ Object
-
#first! ⇒ Object
-
#frozen? ⇒ Boolean
-
#goto ⇒ Object
-
#hover ⇒ Object
-
#initialize(_elements, _parent, _query) ⇒ SearchContext
constructor
A new instance of SearchContext.
-
#last ⇒ Object
-
#reload ⇒ Object
-
#replicate ⇒ Object
-
#right_click ⇒ Object
-
#root ⇒ Object
-
#root? ⇒ Boolean
-
#search(_selector = nil, _options = {}, &_block) ⇒ Object
-
#set_text(_value) ⇒ Object
-
#submit(&_block) ⇒ Object
-
#tag ⇒ Object
-
#text ⇒ Object
-
#to_html ⇒ Object
-
#wait(_condition = nil, _options = {}, &_block) ⇒ Object
-
#wait?(_condition = nil, _options = {}, &_block) ⇒ Boolean
#readonly
#set
#checked, #classes, #download, #id, #input_mode, #selected, #value
Constructor Details
#initialize(_elements, _parent, _query) ⇒ SearchContext
Returns a new instance of SearchContext.
20
21
22
23
24
25
26
|
# File 'lib/pincers/core/search_context.rb', line 20
def initialize(_elements, _parent, _query)
@elements = _elements
@scope = if @elements.nil? then nil else :all end
@parent = _parent
@query = _query
@waiting = false
end
|
Instance Attribute Details
#parent ⇒ Object
Returns the value of attribute parent.
16
17
18
|
# File 'lib/pincers/core/search_context.rb', line 16
def parent
@parent
end
|
#query ⇒ Object
Returns the value of attribute query.
16
17
18
|
# File 'lib/pincers/core/search_context.rb', line 16
def query
@query
end
|
Instance Method Details
#[](*args) ⇒ Object
71
72
73
74
75
76
77
|
# File 'lib/pincers/core/search_context.rb', line 71
def [](*args)
if args[0].is_a? String or args[0].is_a? Symbol
attribute args[0]
else
wrap_siblings Array(elements.send(:[],*args))
end
end
|
#[]=(key, value) ⇒ Object
79
80
81
|
# File 'lib/pincers/core/search_context.rb', line 79
def []=(key, value)
attribute key, value
end
|
#attribute(_name, _value = nil) ⇒ Object
107
108
109
110
111
112
113
114
115
|
# File 'lib/pincers/core/search_context.rb', line 107
def attribute(_name, _value=nil)
wrap_errors do
if _value.nil?
backend. element!, _name
else
backend.set_element_attribute element!, _name, _value
end
end
end
|
#backend ⇒ Object
40
41
42
|
# File 'lib/pincers/core/search_context.rb', line 40
def backend
root.backend
end
|
#click(*_modifiers) ⇒ Object
141
142
143
|
# File 'lib/pincers/core/search_context.rb', line 141
def click(*_modifiers)
perform_action { |el| backend.click_on_element el, _modifiers }
end
|
#double_click ⇒ Object
149
150
151
|
# File 'lib/pincers/core/search_context.rb', line 149
def double_click
perform_action { |el| backend.double_click_on_element el }
end
|
#drag_to(_element) ⇒ Object
157
158
159
160
161
162
163
164
165
166
167
|
# File 'lib/pincers/core/search_context.rb', line 157
def drag_to(_element)
wrap_errors do
if advanced_mode?
wait_actionable
_element.wait_actionable
end
backend.drag_and_drop element!, _element.element!
end
self
end
|
#each ⇒ Object
67
68
69
|
# File 'lib/pincers/core/search_context.rb', line 67
def each
elements.each { |el| yield wrap_siblings [el] }
end
|
#element ⇒ Object
49
50
51
52
|
# File 'lib/pincers/core/search_context.rb', line 49
def element
reload_elements :single
@elements.first
end
|
#element! ⇒ Object
54
55
56
57
58
|
# File 'lib/pincers/core/search_context.rb', line 54
def element!
wait(:present) if should_wait?
raise Pincers::EmptySetError.new self if element.nil?
element
end
|
#elements ⇒ Object
44
45
46
47
|
# File 'lib/pincers/core/search_context.rb', line 44
def elements
reload_elements :all
@elements
end
|
#first ⇒ Object
83
84
85
86
|
# File 'lib/pincers/core/search_context.rb', line 83
def first
wait?(:present) if should_wait?
if element.nil? then nil else wrap_siblings [element] end
end
|
#first! ⇒ Object
88
89
90
|
# File 'lib/pincers/core/search_context.rb', line 88
def first!
wrap_siblings [element!]
end
|
#frozen? ⇒ Boolean
28
29
30
|
# File 'lib/pincers/core/search_context.rb', line 28
def frozen?
!backend.javascript_enabled? || @query.nil?
end
|
#goto ⇒ Object
191
192
193
|
# File 'lib/pincers/core/search_context.rb', line 191
def goto
root.goto frame: self
end
|
#hover ⇒ Object
153
154
155
|
# File 'lib/pincers/core/search_context.rb', line 153
def hover
perform_action { |el| backend.hover_over_element el }
end
|
#last ⇒ Object
92
93
94
|
# File 'lib/pincers/core/search_context.rb', line 92
def last
if elements.last.nil? then nil else wrap_siblings [elements.last] end
end
|
#reload ⇒ Object
60
61
62
63
64
65
|
# File 'lib/pincers/core/search_context.rb', line 60
def reload
raise Pincers::FrozenSetError.new self if frozen?
parent.reload if parent_needs_reload?
wrap_errors { reload_elements }
self
end
|
#replicate ⇒ Object
176
177
178
179
180
181
182
183
184
185
186
187
|
# File 'lib/pincers/core/search_context.rb', line 176
def replicate
wrap_errors do
case tag
when 'form'
Replicas::Form.new backend, element!
when 'a'
Replicas::Link.new backend, element!
else
raise Pincers::MissingFeatureError, "No replica avaliable for #{tag}"
end
end
end
|
#right_click ⇒ Object
145
146
147
|
# File 'lib/pincers/core/search_context.rb', line 145
def right_click
perform_action { |el| backend.right_click_on_element el }
end
|
#root ⇒ Object
32
33
34
|
# File 'lib/pincers/core/search_context.rb', line 32
def root
parent.root
end
|
#root? ⇒ Boolean
36
37
38
|
# File 'lib/pincers/core/search_context.rb', line 36
def root?
false
end
|
#search(_selector = nil, _options = {}, &_block) ⇒ Object
96
97
98
99
100
101
102
103
104
105
|
# File 'lib/pincers/core/search_context.rb', line 96
def search(_selector=nil, _options={}, &_block)
if _selector.is_a? Hash
_options = _selector
_selector = nil
end
query = Helpers::Query.build_from_options(backend, _selector, _options, &_block)
wrap_errors { wrap_childs query }
end
|
#set_text(_value) ⇒ Object
137
138
139
|
# File 'lib/pincers/core/search_context.rb', line 137
def set_text(_value)
perform_action { |el| backend.set_element_text el, _value }
end
|
#submit(&_block) ⇒ Object
169
170
171
172
173
174
|
# File 'lib/pincers/core/search_context.rb', line 169
def submit(&_block)
wrap_errors do
backend.submit_form element!
end
end
|
#tag ⇒ Object
117
118
119
120
121
|
# File 'lib/pincers/core/search_context.rb', line 117
def tag
wrap_errors do
backend.(element!).downcase
end
end
|
#text ⇒ Object
123
124
125
126
127
|
# File 'lib/pincers/core/search_context.rb', line 123
def text
wrap_errors do
elements.map { |e| backend. e }.join
end
end
|
#to_html ⇒ Object
129
130
131
132
133
|
# File 'lib/pincers/core/search_context.rb', line 129
def to_html
wrap_errors do
elements.map { |e| backend. e }.join
end
end
|
#wait(_condition = nil, _options = {}, &_block) ⇒ Object
220
221
222
223
224
225
226
227
228
229
|
# File 'lib/pincers/core/search_context.rb', line 220
def wait(_condition=nil, _options={}, &_block)
if _condition.is_a? Hash
_options = _condition
_condition = nil
end
raise Pincers::ConditionTimeoutError.new(self, _condition) unless wait?(_condition, _options, &_block)
return self
end
|
#wait?(_condition = nil, _options = {}, &_block) ⇒ Boolean
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
|
# File 'lib/pincers/core/search_context.rb', line 197
def wait?(_condition=nil, _options={}, &_block)
if _condition.is_a? Hash
_options = _condition
_condition = nil
end
poll_until(_options) do
next ensure_block _block if _block
case _condition
when :present
ensure_present
when :actionable
ensure_present and ensure_actionable
when :enabled
ensure_present and !attribute(:disabled)
else
ensure_present and !!attribute(_condition)
end
end
end
|