Module: Symbiont::Generators

Defined in:
lib/symbiont/generators.rb

Instance Method Summary collapse

Instance Method Details

#begin_at(url) ⇒ Object



10
11
12
13
14
# File 'lib/symbiont/generators.rb', line 10

def begin_at(url)
  define_method("start") do
    platform.visit(url)
  end
end

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



64
65
66
67
68
69
70
71
# File 'lib/symbiont/generators.rb', line 64

def button(identifier, locator={index: 0}, &block)
  define_method(identifier) do
    return platform.click_button_for(locator.clone) unless block_given?
    self.send("#{name}_object").click
  end

  common_definition_methods(identifier, locator, 'button_element', &block)
end

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



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

def cell(identifier, locator={index: 0}, &block)
  define_method(identifier) do
    return platform.get_table_cell_text_for(locator.clone) unless block_given?
    self.send("#{identifier}_object").text
  end

  common_definition_methods(identifier, locator, 'cell_element', &block)
end

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



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/symbiont/generators.rb', line 142

def checkbox(identifier, locator={index: 0}, &block)
  define_method("check_#{identifier}") do
    return platform.check_checkbox_for(locator.clone) unless block_given?
    self.send("#{identifier}_object").check
  end
  
  define_method("uncheck_#{identifier}") do
    return platform.uncheck_checkbox_for(locator.clone) unless block_given?
    self.send("#{identifier}_object").uncheck
  end
  
  define_method("#{identifier}_checked?") do
    return platform.check_checkbox_for_checked(locator.clone) unless block_given?
    self.send("#{identifier}_object").checked?
  end

  common_definition_methods(identifier, locator, 'checkbox_element', &block)
end

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



295
296
297
298
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
# File 'lib/symbiont/generators.rb', line 295

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

  define_method("#{identifier}_enabled?") do
    return process_block(&block).enabled? if block_given?
    platform.send(method, locator.clone).enabled?
  end

  define_method("#{identifier}_text") do
    return process_block(&block).text if block_given?
    platform.send(method, locator.clone).text
  end

  element = method[0..method.rindex("_") - 1] if method.count("_") == 2
  element = method[0..method.index("_") - 1]  if method.count("_") == 1

  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}!".to_sym, "#{identifier}_enabled?".to_sym
end

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



204
205
206
207
208
209
210
211
# File 'lib/symbiont/generators.rb', line 204

def div(identifier, locator={index: 0}, &block)
  define_method(identifier) do
    return platform.div_text_for(locator.clone) unless block_given?
    self.send("#{identifier}_object").text
  end

  common_definition_methods(identifier, locator, 'div_element', &block)
end

#frame(locator, encloser = nil, &block) ⇒ Object



36
37
38
39
40
# File 'lib/symbiont/generators.rb', line 36

def frame(locator, encloser=nil, &block)
  encloser = [] if encloser.nil?
  encloser << locator
  block.call(encloser)
end

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



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

def h1(identifier, locator={index: 0}, &block)
  define_method(identifier) do
    return platform.h1_text_for(locator.clone) unless block_given?
    self.send("#{identifier}_object").text
  end

  common_definition_methods(identifier, locator, 'h1_element', &block)
end

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



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

def h2(identifier, locator={index: 0}, &block)
  define_method(identifier) do
    return platform.h2_text_for(locator.clone) unless block_given?
    self.send("#{identifier}_object").text
  end

  common_definition_methods(identifier, locator, 'h2_element', &block)
end

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



106
107
108
109
110
111
112
113
# File 'lib/symbiont/generators.rb', line 106

def hidden_field(identifier, locator={index: 0}, &block)
  define_method(identifier) do
    return platform.get_hidden_field_value_for(locator.clone) unless block_given?
    self.send("#{identifier}_object").value
  end

  common_definition_methods(identifier, locator, 'hidden_field_element', &block)
end

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



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

def label(identifier, locator={index: 0}, &block)
  define_method(identifier) do
    return platform.label_text_for(locator.clone) unless block_given?
    self.send("#{identifier}_object").text
  end

  common_definition_methods(identifier, locator, 'label_element', &block)
end


53
54
55
56
57
58
59
60
# File 'lib/symbiont/generators.rb', line 53

def link(identifier, locator={index: 0}, &block)
  define_method(identifier) do
    return platform.click_link_for(locator.clone) unless block_given?
    self.send("#{identifier}_object").click
  end

  common_definition_methods(identifier, locator, 'link_element', &block)
end

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



271
272
273
274
275
276
277
278
# File 'lib/symbiont/generators.rb', line 271

def list_item(identifier, locator={:index => 0}, &block)
  define_method(identifier) do
    return platform.list_item_text_for(locator.clone) unless block_given?
    self.send("#{identifier}_object").text
  end

  common_definition_methods(identifier, locator, 'list_item_element', &block)
end

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



26
27
28
29
30
31
32
33
34
# File 'lib/symbiont/generators.rb', line 26

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

#methodObject

Multiple Element Handling ##



284
285
286
287
288
289
290
291
292
293
# File 'lib/symbiont/generators.rb', line 284

[:unordered_lists, :ordered_lists, :list_items].each do |method|
  define_method(method) do |identifier, *locator, &block|
    define_method("#{identifier}_elements") do
      return process_block(&block) unless block.nil?
      platform_method = "#{method.to_s}_elements"
      puts "*********** #{platform_method}"
      platform.send(platform_method, locator.first.clone)
    end
  end
end

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



249
250
251
252
253
254
255
256
# File 'lib/symbiont/generators.rb', line 249

def ordered_list(identifier, locator={:index => 0}, &block)
  define_method(identifier) do
    return platform.ordered_list_text_for(locator.clone) unless block_given?
    self.send("#{identifier}_object").text
  end

  common_definition_methods(identifier, locator, 'ordered_list_element', &block)
end

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



42
43
44
45
46
47
48
49
# File 'lib/symbiont/generators.rb', line 42

def paragraph(identifier, locator={index: 0}, &block)
  define_method(identifier) do
    return platform.paragraph_text_for(locator.clone) unless block_given?
    self.send("#{identifier}_object").text
  end

  common_definition_methods(identifier, locator, 'paragraph_element', &block)
end

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



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/symbiont/generators.rb', line 161

def radio(identifier, locator={index: 0}, &block)
  #alias_method "#{identifier}_radio".to_sym, "#{identifier}_object".to_sym
  #alias_method "#{identifier}_radio_button".to_sym, "#{identifier}_object".to_sym
  
  define_method("#{identifier}_selected?") do
    return platform.check_radio_for_selected(locator.clone) unless block_given?
    self.send("#{identifier}_object").selected?
  end
  
  alias_method "#{identifier}_set?".to_sym, "#{identifier}_selected?".to_sym
  
  define_method("select_#{identifier}") do
    return platform.select_radio_for(locator.clone) unless block_given?
    self.send("#{identifier}_object").select
  end
  
  alias_method "set_#{identifier}".to_sym, "select_#{identifier}".to_sym

  common_definition_methods(identifier, locator, 'radio_element', &block)
end

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



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/symbiont/generators.rb', line 117

def select_list(identifier, locator={index: 0}, &block)
  define_method(identifier) do
    return platform.get_select_list_item_for(locator.clone) unless block_given?
    self.send("#{identifier}_object").value
  end
  
  define_method("#{identifier}_option?") do
    platform.get_select_list_value_for(locator.clone)
  end

  define_method("#{identifier}_options?") do
    object = self.send("#{identifier}_object")
    (object && object.options) ? object.options.collect(&:text) : []
  end

  define_method("#{identifier}=") do |value|
    return platform.set_select_list_value_for(locator.clone, value) unless block_given?
    self.send("#{identifier}_object").select(value)
  end

  common_definition_methods(identifier, locator, 'select_list_element', &block)
end

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



213
214
215
216
217
218
219
220
# File 'lib/symbiont/generators.rb', line 213

def span(identifier, locator={index: 0}, &block)
  define_method(identifier) do
    return platform.span_text_for(locator.clone) unless block_given?
    self.send("#{identifier}_object").text
  end

  common_definition_methods(identifier, locator, 'span_element', &block)
end

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



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

def table(identifier, locator={index: 0}, &block)
  define_method(identifier) do
    return platform.table_text_for(locator.clone) unless block_given?
    self.send("#{identifier}_object").text
  end

  common_definition_methods(identifier, locator, 'table_element', &block)
end

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



90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/symbiont/generators.rb', line 90

def text_area(identifier, locator={index: 0}, &block)
  define_method(identifier) do
    return platform.get_text_area_value_for(locator.clone) unless block_given?
    self.send("#{identifier}_object").value
  end

  define_method("#{identifier}=") do |value|
    return platform.set_text_area_value_for(locator.clone, value) unless block_given?
    self.send("#{identifier}_object").value = value
  end

  common_definition_methods(identifier, locator, 'text_area_element', &block)
end

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



73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/symbiont/generators.rb', line 73

def text_field(identifier, locator={index: 0}, &block)
  define_method(identifier) do
    return platform.get_text_field_value_for(locator.clone) unless block_given?
    self.send("#{identifier}_object").value
  end

  define_method("#{identifier}=") do |value|
    return platform.set_text_field_value_for(locator.clone, value) unless block_given?
    self.send("#{identifier}_object").value = value
  end

  common_definition_methods(identifier, locator, 'text_field_element', &block)
end

#title_is(title) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/symbiont/generators.rb', line 16

def title_is(title)
  define_method('has_title?') do
    wait_for_app
    valid_title = title =~ @browser.title if title.kind_of?(Regexp)
    valid_title = title == @browser.title if title.kind_of?(String)
    raise "\n\nExpected title: '#{title}'; Actual title: '#{@browser.title}'" unless valid_title
    valid_title
  end
end

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



260
261
262
263
264
265
266
267
# File 'lib/symbiont/generators.rb', line 260

def unordered_list(identifier, locator={:index => 0}, &block)
  define_method(identifier) do
    return platform.unordered_list_text_for(locator.clone) unless block_given?
    self.send("#{identifier}_object").text
  end

  common_definition_methods(identifier, locator, 'unordered_list_element', &block)
end

#url_is(url) ⇒ Object



4
5
6
7
8
# File 'lib/symbiont/generators.rb', line 4

def url_is(url)
  define_method("view") do
    platform.visit(url)
  end
end