Module: Fluent::Generators

Defined in:
lib/fluent/generators.rb

Instance Method Summary collapse

Instance Method Details

#button(identifier, locator) ⇒ Object



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

def button(identifier, locator)
  define_method(identifier) do
    return platform.button_click(locator.clone)
  end
  
  common_definition_methods(identifier, locator, __method__)
end

#cell(identifier, locator) ⇒ Object Also known as: td



209
210
211
212
213
214
215
216
# File 'lib/fluent/generators.rb', line 209

def cell(identifier, locator)
  define_method(identifier) do
    return platform.cell_text(locator.clone)
  end

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

#checkbox(identifier, locator) ⇒ Object



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/fluent/generators.rb', line 119

def checkbox(identifier, locator)
  define_method("#{identifier}_checked?") do
    return platform.checkbox_check_state(locator.clone)
  end

  define_method("check_#{identifier}") do
    return platform.checkbox_check(locator.clone)
  end

  define_method("uncheck_#{identifier}") do
    return platform.checkbox_uncheck(locator.clone)
  end
  
  common_definition_methods(identifier, locator, __method__)
end

#common_definition_methods(identifier, locator, method) ⇒ Object



277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
# File 'lib/fluent/generators.rb', line 277

def common_definition_methods(identifier, locator, method)
  define_method("#{identifier}_object") do
    platform.send(method, locator.clone)
  end
  
  define_method("#{identifier}_exists?") do
    platform.send(method, locator.clone).exists?
  end

  define_method("#{identifier}_visible?") do
    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_be_enabled?(method)
    define_method("#{identifier}_enabled?") do
      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) ⇒ Object



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

def div(identifier, locator)
  define_method(identifier) do
    return platform.div_text(locator.clone)
  end
  
  common_definition_methods(identifier, locator, __method__)
end

#form(identifier, locator) ⇒ Object



234
235
236
# File 'lib/fluent/generators.rb', line 234

def form(identifier, locator)
  common_definition_methods(identifier, locator, __method__)
end

#hidden(identifier, locator) ⇒ Object



226
227
228
229
230
231
232
# File 'lib/fluent/generators.rb', line 226

def hidden(identifier, locator)
  define_method(identifier) do
    return platform.hidden_value(locator.clone)
  end

  common_definition_methods(identifier, locator, __method__)
end

#image(identifier, locator) ⇒ Object Also known as: img



238
239
240
241
# File 'lib/fluent/generators.rb', line 238

def image(identifier, locator)
  common_definition_methods(identifier, locator, __method__)
  common_definition_methods(identifier, locator, 'img')
end

#label(identifier, locator) ⇒ Object



218
219
220
221
222
223
224
# File 'lib/fluent/generators.rb', line 218

def label(identifier, locator)
  define_method(identifier) do
    return platform.label_text(locator.clone)
  end

  common_definition_methods(identifier, locator, __method__)
end


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

def link(identifier, locator)
  define_method(identifier) do
    return platform.link_click(locator.clone)
  end
  
  common_definition_methods(identifier, locator, __method__)
  common_definition_methods(identifier, locator, 'a')
end

#list_item(identifier, locator) ⇒ Object Also known as: li



192
193
194
195
196
197
198
199
# File 'lib/fluent/generators.rb', line 192

def list_item(identifier, locator)
  define_method(identifier) do
    return platform.list_item_text(locator.clone)
  end
  
  common_definition_methods(identifier, locator, __method__)
  common_definition_methods(identifier, locator, 'li')
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) ⇒ Object Also known as: ol



174
175
176
177
178
179
180
181
# File 'lib/fluent/generators.rb', line 174

def ordered_list(identifier, locator)
  define_method(identifier) do
    return platform.ordered_list_text(locator.clone)
  end
  
  common_definition_methods(identifier, locator, __method__)
  common_definition_methods(identifier, locator, 'ol')
end

#paragraph(identifier, locator) ⇒ Object Also known as: p



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

def paragraph(identifier, locator)
  define_method(identifier) do
    return platform.paragraph_text(locator.clone)
  end
  
  common_definition_methods(identifier, locator, __method__)
  common_definition_methods(identifier, locator, 'p')
end

#radio(identifier, locator) ⇒ Object Also known as: radio_button



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/fluent/generators.rb', line 158

def radio(identifier, locator)
  define_method("select_#{identifier}") do
    return platform.radio_select(locator.clone)
  end

  define_method("#{identifier}_selected?") do
    return platform.radio_check_state(locator.clone)
  end

  alias_method "#{identifier}_set?".to_sym, "#{identifier}_selected?".to_sym
  alias_method "set_#{identifier}".to_sym, "select_#{identifier}".to_sym
  
  common_definition_methods(identifier, locator, __method__)
  common_definition_methods(identifier, locator, 'radio_button')
end

#select_list(identifier, locator) ⇒ Object



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/fluent/generators.rb', line 135

def select_list(identifier, locator)
  define_method(identifier) do
    return platform.select_list_get_selected(locator.clone)
  end

  alias_method "#{identifier}_option?".to_sym, "#{identifier}".to_sym
  
  define_method("#{identifier}=") do |value|
    return platform.select_list_set(locator.clone, value)
  end

  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)
  end
  
  common_definition_methods(identifier, locator, __method__)
end

#span(identifier, locator) ⇒ Object



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

def span(identifier, locator)
  define_method(identifier) do
    return platform.span_text(locator.clone)
  end
  
  common_definition_methods(identifier, locator, __method__)
end

#table(identifier, locator) ⇒ Object



201
202
203
204
205
206
207
# File 'lib/fluent/generators.rb', line 201

def table(identifier, locator)
  define_method(identifier) do
    return platform.table_text(locator.clone)
  end
  
  common_definition_methods(identifier, locator, __method__)
end

#text_area(identifier, locator) ⇒ Object Also known as: textarea



106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/fluent/generators.rb', line 106

def text_area(identifier, locator)
  define_method(identifier) do
    return platform.text_area_get(locator.clone)
  end

  define_method("#{identifier}=") do |value|
    return platform.text_area_set(locator.clone, value)
  end
  
  common_definition_methods(identifier, locator, __method__)
  common_definition_methods(identifier, locator, 'textarea')
end

#text_field(identifier, locator) ⇒ Object Also known as: textfield



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

def text_field(identifier, locator)
  define_method(identifier) do
    return platform.text_field_get(locator.clone)
  end
  
  define_method("#{identifier}=") do |value|
    return platform.text_field_set(locator.clone, value)
  end
  
  common_definition_methods(identifier, locator, __method__)
  common_definition_methods(identifier, locator, 'textfield')
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) ⇒ Object Also known as: ul



183
184
185
186
187
188
189
190
# File 'lib/fluent/generators.rb', line 183

def unordered_list(identifier, locator)
  define_method(identifier) do
    return platform.unordered_list_text(locator.clone)
  end

  common_definition_methods(identifier, locator, __method__)
  common_definition_methods(identifier, locator, 'ul')
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