Class: Element

Inherits:
Object
  • Object
show all
Defined in:
lib/core/PageObject.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page, object) ⇒ Element

Returns a new instance of Element.



12
13
14
15
16
# File 'lib/core/PageObject.rb', line 12

def initialize(page, object)
  @page = page
  @name = object['name']
  @xpath = object['xpath']
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



10
11
12
# File 'lib/core/PageObject.rb', line 10

def name
  @name
end

#xpathObject

Returns the value of attribute xpath.



10
11
12
# File 'lib/core/PageObject.rb', line 10

def xpath
  @xpath
end

Instance Method Details

#CheckObject



123
124
125
126
127
# File 'lib/core/PageObject.rb', line 123

def Check()
  checkbox = self.get_checkbox
  checkbox.set
  return true
end

#ClickObject



105
106
107
108
109
# File 'lib/core/PageObject.rb', line 105

def Click()
  element = self.get
  element.click
  return true
end

#enabledObject



55
56
57
# File 'lib/core/PageObject.rb', line 55

def enabled
  return false
end

#existsObject



45
46
47
48
49
50
51
52
53
# File 'lib/core/PageObject.rb', line 45

def exists
  element = self.get
  
  if element.exists?
    return true
  else
    return false
  end
end

#ExistsObject

Verification methods will raise error if failed, don’t use for check condition logic



139
140
141
142
143
144
145
146
# File 'lib/core/PageObject.rb', line 139

def Exists()
  if self.exists
    return true
  end

  Log.Failed("Value not matched", '<not exists>', '<exists>')
  return false
end

#getObject

Basic element properties



22
23
24
# File 'lib/core/PageObject.rb', line 22

def get
  return @page.browser.element(:xpath => @xpath)
end

#get_checkboxObject



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/core/PageObject.rb', line 59

def get_checkbox
  element = self.get

  if element.tag_name == 'input' and element.attribute_value('type') == 'checkbox'
    checkbox = @page.browser.checkbox(:xpath => @xpath)
    return checkbox
  end

  Log.Failed("The element '#{@name}' is not type 'checkbox'\n")
  return nil
end

#get_radioObject



71
72
73
74
75
76
77
78
79
80
81
# File 'lib/core/PageObject.rb', line 71

def get_radio
  element = self.get

  if element.tag_name == 'input' and element.attribute_value('type') == 'radio'
    radio = @page.browser.radio(:xpath => @xpath)
    return radio
  end

  Log.Failed("The element '#{@name}' is not type 'radio'\n")
  return nil
end

#get_selectObject



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/core/PageObject.rb', line 83

def get_select
  element = self.get

  if element.tag_name == 'select'
    select = @page.browser.select_list(:xpath => @xpath)
    return select
  end

  Log.Failed("The element '#{@name}' is not type 'select'\n")
  return nil
end

#HasItem(value) ⇒ Object



253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# File 'lib/core/PageObject.rb', line 253

def HasItem(value)
  select = self.get_select

  options = []
  for option in select.options
    options << option.text
  end

  if options.include? value
    return true
  end

  Log.Failed("Item not found in list", "\n\t" + options.join("\n\t"), value)
  return false
end

#IsCheckedObject



291
292
293
294
295
296
297
298
299
300
# File 'lib/core/PageObject.rb', line 291

def IsChecked()
  checkbox = self.get_checkbox

  if checkbox.set?
    return true
  end

  Log.Failed("Value not matched", '<not checked>', '<checked>')
  return false
end

#IsNotSelectedObject



280
281
282
283
284
285
286
287
288
289
# File 'lib/core/PageObject.rb', line 280

def IsNotSelected()
  radio = self.get_radio

  if not radio.set?
    return true
  end

  Log.Failed("Value not matched", '<selected>', '<not selected>')
  return false
end

#IsSelectedObject



269
270
271
272
273
274
275
276
277
278
# File 'lib/core/PageObject.rb', line 269

def IsSelected()
  radio = self.get_radio

  if radio.set?
    return true
  end

  Log.Failed("Value not matched", '<not selected>', '<selected>')
  return false
end

#IsUncheckedObject



302
303
304
305
306
307
308
309
310
311
# File 'lib/core/PageObject.rb', line 302

def IsUnchecked()
  checkbox = self.get_checkbox

  if not checkbox.set?
    return true
  end

  Log.Failed("Value not matched", 'checked>', '<unchecked>')
  return false
end

#NotExistsObject



148
149
150
151
152
153
154
155
# File 'lib/core/PageObject.rb', line 148

def NotExists()
  if not self.exists
    return true
  end

  Log.Failed("Value not matched", '<exists>', '<not exists>')
  return false
end

#SelectItem(value) ⇒ Object

def Select() ## for radio button radio = self.get_radio radio.set return true end



117
118
119
120
121
# File 'lib/core/PageObject.rb', line 117

def SelectItem(value) ## for select list

  select = self.get_select
  select.select(value)
  return true
end

#SendKeys(value) ⇒ Object

Action methods



99
100
101
102
103
# File 'lib/core/PageObject.rb', line 99

def SendKeys(value)
  element = self.get
  element.send_keys(value)
  return true
end

#UncheckObject



129
130
131
132
133
# File 'lib/core/PageObject.rb', line 129

def Uncheck()
  checkbox = self.get_checkbox
  checkbox.clear
  return true
end

#valueObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/core/PageObject.rb', line 26

def value
  element = self.get
  
  if element.tag_name == 'select'
    select = self.get_select

    text = []
    for option in select.selected_options
      text << option.text
    end

    return text.join('\n')
  elsif ['input', 'button'].include? element.tag_name
    return element.value
  else
    return element.text
  end
end

#ValueContains(value) ⇒ Object



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

def ValueContains(value)
  if self.value.include? value
    return true
  end

  Log.Failed("Value not matched", self.value, value)
  return false
end

#ValueIs(value) ⇒ Object



175
176
177
178
179
180
181
182
# File 'lib/core/PageObject.rb', line 175

def ValueIs(value)
  if self.value == value
    return true
  end

  Log.Failed("Value not matched", self.value, value)
  return false
end

#ValueIsBetween(value1, value2) ⇒ Object



238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/core/PageObject.rb', line 238

def ValueIsBetween(value1, value2)
  if value1 < value2
    if self.value >= value1 and self.value <= value2
      return true
    end
  else
    if self.value <= value1 and self.value >= value2
      return true
    end
  end

  Log.Failed("Value not matched", self.value, " x in (#{value1} - #{value2})")
  return false
end

#ValueIsEmptyObject



157
158
159
160
161
162
163
164
# File 'lib/core/PageObject.rb', line 157

def ValueIsEmpty()
  if self.value == ''
    return true
  end

  Log.Failed("Value not matched", self.value, '<empty>')
  return false
end

#ValueIsLessThan(value) ⇒ Object



220
221
222
223
224
225
226
227
# File 'lib/core/PageObject.rb', line 220

def ValueIsLessThan(value)
  if self.value < value
    return true
  end

  Log.Failed("Value not matched", self.value, "( x < #{value} )")
  return false
end

#ValueIsLessThanOrEqual(value) ⇒ Object



229
230
231
232
233
234
235
236
# File 'lib/core/PageObject.rb', line 229

def ValueIsLessThanOrEqual(value)
  if self.value <= value
    return true
  end

  Log.Failed("Value not matched", self.value, "( x <= #{value} )")
  return false
end

#ValueIsMoreThan(value) ⇒ Object



202
203
204
205
206
207
208
209
# File 'lib/core/PageObject.rb', line 202

def ValueIsMoreThan(value)
  if self.value > value
    return true
  end

  Log.Failed("Value not matched", self.value, "( x > #{value} )")
  return false
end

#ValueIsMoreThanOrEqual(value) ⇒ Object



211
212
213
214
215
216
217
218
# File 'lib/core/PageObject.rb', line 211

def ValueIsMoreThanOrEqual(value)
  if self.value >= value
    return true
  end

  Log.Failed("Value not matched", self.value, "( x >= #{value} )")
  return false
end

#ValueIsNot(value) ⇒ Object



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

def ValueIsNot(value)
  if self.value != value
    return true
  end

  Log.Failed("Value not matched", self.value, value)
  return false
end

#ValueIsNotEmptyObject



166
167
168
169
170
171
172
173
# File 'lib/core/PageObject.rb', line 166

def ValueIsNotEmpty()
  if self.value != ''
    return true
  end

  Log.Failed("Value not matched", '<empty>', '<not empty>')
  return false
end