Module: Fluent::Generators

Defined in:
lib/fluent/generators.rb

Constant Summary collapse

ELEMENT_LIST =
[:text_field, :text_area, :select_list, :checkbox, :radio,
:link, :button, :table, :cell, :div, :span, :image,
:list_item, :ordered_list, :unordered_list, :form,
:h1, :h2, :h3, :h4, :h5, :h6, :paragraph, :label, :hidden]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.generate_locators(caller) ⇒ Object



350
351
352
353
354
355
356
357
358
359
360
# File 'lib/fluent/generators.rb', line 350

def self.generate_locators(caller)
  ELEMENT_LIST.each do |element|
    caller.send(:define_method, "#{element.to_s}_locate") do |*locator|
      @platform.send "#{element.to_s}", locate_by(locator)
    end
    
    caller.send(:define_method, "#{element.to_s}_elements") do |*locator|
      @platform.send("#{element}s", locator[0] ? locator[0] : {})
    end
  end
end

Instance Method Details

#button(identifier, locator = {index: 0}, &block) ⇒ Object



85
86
87
88
89
90
91
# File 'lib/fluent/generators.rb', line 85

def button(identifier, locator={index: 0}, &block)
  define_method(identifier) do
    return platform.button_click(locator.clone) unless block_given?
  end
  
  common_definition_methods(identifier, locator, __method__, &block)
end

#cell(identifier, locator = {index: 0}, &block) ⇒ Object Also known as: td



223
224
225
226
227
228
229
230
# File 'lib/fluent/generators.rb', line 223

def cell(identifier, locator={index: 0}, &block)
  define_method(identifier) do
    return platform.cell_text(locator.clone) unless block_given?
  end

  common_definition_methods(identifier, locator, __method__, &block)
  common_definition_methods(identifier, locator, 'td', &block)
end

#checkbox(identifier, locator = {index: 0}, &block) ⇒ Object



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/fluent/generators.rb', line 127

def checkbox(identifier, locator={index: 0}, &block)
  define_method("#{identifier}_checked?") do
    return platform.checkbox_check_state(locator.clone) unless block_given?
  end

  define_method("check_#{identifier}") do
    return platform.checkbox_check(locator.clone) unless block_given?
  end
  
  alias_method "#{identifier}_check".to_sym, "check_#{identifier}".to_sym
  
  define_method("uncheck_#{identifier}") do
    return platform.checkbox_uncheck(locator.clone) unless block_given?
  end

  alias_method "#{identifier}_uncheck".to_sym, "uncheck_#{identifier}".to_sym
  
  common_definition_methods(identifier, locator, __method__, &block)
end

#common_definition_methods(identifier, locator, method, &block) ⇒ Object



299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
# File 'lib/fluent/generators.rb', line 299

def common_definition_methods(identifier, locator, method, &block)
  define_method("#{identifier}_object") do
    return process_block(&block) if block_given?
    platform.send(method, locator.clone)
  end
  
  define_method("#{identifier}_exists?") do
    return process_block(&block).exists? if block_given?
    platform.send(method, locator.clone).exists?
  end

  define_method("#{identifier}_visible?") do
    return process_block(&block).visible? if block_given?
    platform.send(method, locator.clone).visible?
  end
        
  alias_method "#{identifier}_#{method}".to_sym, "#{identifier}_object".to_sym
  alias_method "#{identifier}_element".to_sym, "#{identifier}_object".to_sym

  alias_method "#{identifier}?".to_sym, "#{identifier}_exists?".to_sym
  alias_method "#{identifier}_?".to_sym, "#{identifier}_visible?".to_sym
  
  alias_method "#{identifier}_#{method}_exists?".to_sym, "#{identifier}_exists?".to_sym
  alias_method "#{identifier}_#{method}_visible?".to_sym, "#{identifier}_visible?".to_sym
  
  alias_method "#{identifier}_#{method}?".to_sym, "#{identifier}_exists?".to_sym
  alias_method "#{identifier}_#{method}_?".to_sym, "#{identifier}_visible?".to_sym
  
  if Fluent.can_display_text?(method)
    define_method("#{identifier}_text") do
      platform.send(method, locator.clone).text
    end
  end
  
  if Fluent.can_be_enabled?(method)
    define_method("#{identifier}_enabled?") do
      return process_block(&block).enabled? if block_given?
      platform.send(method, locator.clone).enabled?
    end

    alias_method "#{identifier}!".to_sym, "#{identifier}_enabled?".to_sym
    alias_method "#{identifier}_#{method}_enabled?".to_sym, "#{identifier}_enabled?".to_sym
    alias_method "#{identifier}_#{method}!".to_sym, "#{identifier}_exists?".to_sym
  end
end

#div(identifier, locator = {index: 0}, &block) ⇒ Object



69
70
71
72
73
74
75
# File 'lib/fluent/generators.rb', line 69

def div(identifier, locator={index: 0}, &block)
  define_method(identifier) do
    return platform.div_text(locator.clone) unless block_given?
  end
  
  common_definition_methods(identifier, locator, __method__, &block)
end

#form(identifier, locator = {index: 0}, &block) ⇒ Object



248
249
250
# File 'lib/fluent/generators.rb', line 248

def form(identifier, locator={index: 0}, &block)
  common_definition_methods(identifier, locator, __method__, &block)
end

#hidden(identifier, locator = {index: 0}, &block) ⇒ Object



240
241
242
243
244
245
246
# File 'lib/fluent/generators.rb', line 240

def hidden(identifier, locator={index: 0}, &block)
  define_method(identifier) do
    return platform.hidden_value(locator.clone) unless block_given?
  end
  
  common_definition_methods(identifier, locator, __method__, &block)
end

#image(identifier, locator = {index: 0}, &block) ⇒ Object Also known as: img



252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# File 'lib/fluent/generators.rb', line 252

def image(identifier, locator={index: 0}, &block)
  define_method("#{identifier}_loaded?") do
    return platform.image_action(locator.clone, 'loaded?') unless block_given?
  end

  define_method("#{identifier}_height") do
    return platform.image_action(locator.clone, 'height') unless block_given?
  end

  define_method("#{identifier}_width") do
    return platform.image_action(locator.clone, 'width') unless block_given?
  end
  
  define_method("#{identifier}_src") do
    return platform.image_get_source(locator.clone) unless block_given?
  end

  define_method("#{identifier}_alt") do
    return platform.image_get_alt_text(locator.clone) unless block_given?
  end
  
  common_definition_methods(identifier, locator, __method__, &block)
  common_definition_methods(identifier, locator, 'img', &block)
end

#label(identifier, locator = {index: 0}, &block) ⇒ Object



232
233
234
235
236
237
238
# File 'lib/fluent/generators.rb', line 232

def label(identifier, locator={index: 0}, &block)
  define_method(identifier) do
    return platform.label_text(locator.clone) unless block_given?
  end

  common_definition_methods(identifier, locator, __method__, &block)
end


51
52
53
54
55
56
57
58
# File 'lib/fluent/generators.rb', line 51

def link(identifier, locator={index: 0}, &block)
  define_method(identifier) do
    return platform.link_click(locator.clone) unless block_given?
  end
  
  common_definition_methods(identifier, locator, __method__, &block)
  common_definition_methods(identifier, locator, 'a', &block)
end

#list_item(identifier, locator = {index: 0}, &block) ⇒ Object Also known as: li



206
207
208
209
210
211
212
213
# File 'lib/fluent/generators.rb', line 206

def list_item(identifier, locator={index: 0}, &block)
  define_method(identifier) do
    return platform.list_item_text(locator.clone) unless block_given?
  end
  
  common_definition_methods(identifier, locator, __method__, &block)
  common_definition_methods(identifier, locator, 'li', &block)
end

#look_for(widget, timeout = ::Fluent.element_level_wait) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/fluent/generators.rb', line 32

def look_for(widget, timeout=::Fluent.element_level_wait)
  define_method('check_objects') do
    if self.respond_to? "#{widget}_object"
      self.send("#{widget}_object").when_present(timeout)
    else
      raise "\n\nThe '#{widget}' object was not declared and could not be checked."
    end
  end
end

#ordered_list(identifier, locator = {index: 0}, &block) ⇒ Object Also known as: ol



188
189
190
191
192
193
194
195
# File 'lib/fluent/generators.rb', line 188

def ordered_list(identifier, locator={index: 0}, &block)
  define_method(identifier) do
    return platform.ordered_list_text(locator.clone) unless block_given?
  end
  
  common_definition_methods(identifier, locator, __method__, &block)
  common_definition_methods(identifier, locator, 'ol', &block)
end

#paragraph(identifier, locator = {index: 0}, &block) ⇒ Object Also known as: p



60
61
62
63
64
65
66
67
# File 'lib/fluent/generators.rb', line 60

def paragraph(identifier, locator={index: 0}, &block)
  define_method(identifier) do
    return platform.paragraph_text(locator.clone) unless block_given?
  end
  
  common_definition_methods(identifier, locator, __method__, &block)
  common_definition_methods(identifier, locator, 'p', &block)
end

#radio(identifier, locator = {index: 0}, &block) ⇒ Object Also known as: radio_button



173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/fluent/generators.rb', line 173

def radio(identifier, locator={index: 0}, &block)
  define_method("set_#{identifier}") do
    return platform.radio_select(locator.clone) unless block_given?
  end

  alias_method "#{identifier}_set".to_sym, "set_#{identifier}".to_sym
  
  define_method("#{identifier}_set?") do
    return platform.radio_check_state(locator.clone) unless block_given?
  end
  
  common_definition_methods(identifier, locator, __method__, &block)
  common_definition_methods(identifier, locator, 'radio_button', &block)
end

#select_list(identifier, locator = {index: 0}, &block) ⇒ Object



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/fluent/generators.rb', line 147

def select_list(identifier, locator={index: 0}, &block)
  define_method(identifier) do
    return platform.select_list_get_selected(locator.clone) unless block_given?
  end

  alias_method "#{identifier}_get".to_sym, "#{identifier}".to_sym
  alias_method "#{identifier}_option?".to_sym, "#{identifier}".to_sym
  
  define_method("#{identifier}_set") do |value|
    return platform.select_list_set(locator.clone, value) unless block_given?
  end
  
  alias_method "#{identifier}_select", "#{identifier}_set".to_sym
  
  define_method("#{identifier}_options?") do
    web_object = self.send("#{identifier}_object")
    (web_object && web_object.options) ? web_object.options.collect(&:text) : []
  end

  define_method("#{identifier}_value?") do
    return platform.select_list_get_value(locator.clone) unless block_given?
  end
  
  common_definition_methods(identifier, locator, __method__, &block)
end

#span(identifier, locator = {index: 0}, &block) ⇒ Object



77
78
79
80
81
82
83
# File 'lib/fluent/generators.rb', line 77

def span(identifier, locator={index: 0}, &block)
  define_method(identifier) do
    return platform.span_text(locator.clone) unless block_given?
  end
  
  common_definition_methods(identifier, locator, __method__, &block)
end

#table(identifier, locator = {index: 0}, &block) ⇒ Object



215
216
217
218
219
220
221
# File 'lib/fluent/generators.rb', line 215

def table(identifier, locator={index: 0}, &block)
  define_method(identifier) do
    return platform.table_text(locator.clone) unless block_given?
  end
  
  common_definition_methods(identifier, locator, __method__, &block)
end

#text_area(identifier, locator = {index: 0}, &block) ⇒ Object Also known as: textarea



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/fluent/generators.rb', line 110

def text_area(identifier, locator={index: 0}, &block)
  define_method(identifier) do
    return platform.text_area_get(locator.clone) unless block_given?
  end

  alias_method "#{identifier}_get".to_sym, "#{identifier}".to_sym
  
  define_method("#{identifier}=") do |value|
    return platform.text_area_set(locator.clone, value) unless block_given?
  end

  alias_method "#{identifier}_set", "#{identifier}=".to_sym
  
  common_definition_methods(identifier, locator, __method__, &block)
  common_definition_methods(identifier, locator, 'textarea', &block)
end

#text_field(identifier, locator = {index: 0}, &block) ⇒ Object Also known as: textfield



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/fluent/generators.rb', line 93

def text_field(identifier, locator={index: 0}, &block)
  define_method(identifier) do
    return platform.text_field_get(locator.clone) unless block_given?
  end
  
  alias_method "#{identifier}_get".to_sym, "#{identifier}".to_sym
  
  define_method("#{identifier}=") do |value|
    return platform.text_field_set(locator.clone, value) unless block_given?
  end
  
  alias_method "#{identifier}_set", "#{identifier}=".to_sym
  
  common_definition_methods(identifier, locator, __method__, &block)
  common_definition_methods(identifier, locator, 'textfield', &block)
end

#title_is(title = nil) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/fluent/generators.rb', line 19

def title_is(title=nil)
  msg = "The title_is assertion is empty on the definition #{self}."
  raise Fluent::Errors::NoTitleForDefinition, msg if title.nil?
  
  define_method('check_title') do
    msg  = "Expected title: '#{title}'; Actual title: '#{driver.title}'"
    valid_title = title == driver.title if title.kind_of?(String)
    valid_title = title =~ driver.title if title.kind_of?(Regexp)
    raise Fluent::Errors::TitleNotMatched, msg unless valid_title
    valid_title
  end
end

#unordered_list(identifier, locator = {index: 0}, &block) ⇒ Object Also known as: ul



197
198
199
200
201
202
203
204
# File 'lib/fluent/generators.rb', line 197

def unordered_list(identifier, locator={index: 0}, &block)
  define_method(identifier) do
    return platform.unordered_list_text(locator.clone) unless block_given?
  end

  common_definition_methods(identifier, locator, __method__, &block)
  common_definition_methods(identifier, locator, 'ul', &block)
end

#url_is(url = nil) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/fluent/generators.rb', line 4

def url_is(url=nil)
  msg = "The url_is assertion is empty on the definition #{self}."
  raise Fluent::Errors::NoUrlForDefinition, msg if url.nil?
  
  define_method('view') do
    platform.visit(url)
  end
  
  define_method('check_url') do
    msg  = "Expected url: '#{url}'; Actual url: '#{driver.url}'"
    valid_url = url == driver.url
    raise Fluent::Errors::UrlNotMatched, msg unless valid_url
  end
end

#within_frame(locator, &block) ⇒ Object

This is required to allow declaring element definitions as being within a frame in a page definition. The logic here makes sure that the enclosed element definitions have their actions generated.



45
46
47
48
49
# File 'lib/fluent/generators.rb', line 45

def within_frame(locator, &block)
  frame = []
  frame << locator
  block.call(frame)
end