Class: Fluent::Platforms::WatirWebDriver::PlatformObject

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent/platform_watir/platform_object.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(driver) ⇒ PlatformObject

Returns a new instance of PlatformObject.



8
9
10
# File 'lib/fluent/platform_watir/platform_object.rb', line 8

def initialize(driver)
  @driver = driver
end

Instance Attribute Details

#driverObject (readonly)

Returns the value of attribute driver.



6
7
8
# File 'lib/fluent/platform_watir/platform_object.rb', line 6

def driver
  @driver
end

Instance Method Details

#access_web_element(action, locator, value = nil) ⇒ Any

This method is called by any platform methods that require accessing a web object with the intent of manipulating it or getting information from it.

Parameters:

  • action (String)

    the driver logic to be sent to the browser

  • locator (Hash)

    the specific web object selector

  • value (String) (defaults to: nil)

    any specific information that must be sent to the web object

Returns:

  • (Any)

    the information or object returned by the action



483
484
485
486
# File 'lib/fluent/platform_watir/platform_object.rb', line 483

def access_web_element(action, locator, value=nil)
  encloser = locator.delete(:frame)
  driver.instance_eval("#{enclosed_by(encloser)}#{action}")
end

#button(locator) ⇒ Object



121
122
123
# File 'lib/fluent/platform_watir/platform_object.rb', line 121

def button(locator)
  reference_web_element('button(locator)', WebElements::Button, locator)
end

#button_click(locator) ⇒ Object



129
130
131
# File 'lib/fluent/platform_watir/platform_object.rb', line 129

def button_click(locator)
  access_web_element('button(locator).click', locator)
end

#buttons(locator) ⇒ Object



125
126
127
# File 'lib/fluent/platform_watir/platform_object.rb', line 125

def buttons(locator)
  reference_web_elements('buttons(locator)', WebElements::Button, locator)
end

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



307
308
309
# File 'lib/fluent/platform_watir/platform_object.rb', line 307

def cell(locator)
  reference_web_element('td(locator)', WebElements::Cell, locator)
end

#cell_text(locator) ⇒ Object



315
316
317
# File 'lib/fluent/platform_watir/platform_object.rb', line 315

def cell_text(locator)
  access_web_element('td(locator).text', locator)
end

#cells(locator) ⇒ Object



311
312
313
# File 'lib/fluent/platform_watir/platform_object.rb', line 311

def cells(locator)
  reference_web_elements('tds(locator)', WebElements::Cell, locator)
end

#checkbox(locator) ⇒ Object



165
166
167
# File 'lib/fluent/platform_watir/platform_object.rb', line 165

def checkbox(locator)
  reference_web_element('checkbox(locator)', WebElements::CheckBox, locator)
end

#checkbox_check(locator) ⇒ Object



179
180
181
# File 'lib/fluent/platform_watir/platform_object.rb', line 179

def checkbox_check(locator)
  access_web_element('checkbox(locator).set', locator)
end

#checkbox_check_state(locator) ⇒ Object



175
176
177
# File 'lib/fluent/platform_watir/platform_object.rb', line 175

def checkbox_check_state(locator)
  access_web_element('checkbox(locator).set?', locator)
end

#checkbox_uncheck(locator) ⇒ Object



183
184
185
# File 'lib/fluent/platform_watir/platform_object.rb', line 183

def checkbox_uncheck(locator)
  access_web_element('checkbox(locator).clear', locator)
end

#checkboxes(locator) ⇒ Object Also known as: checkboxs



169
170
171
# File 'lib/fluent/platform_watir/platform_object.rb', line 169

def checkboxes(locator)
  reference_web_elements('checkboxes(locator)', WebElements::CheckBox, locator)
end

#div(locator) ⇒ Object



235
236
237
# File 'lib/fluent/platform_watir/platform_object.rb', line 235

def div(locator)
  reference_web_element('div(locator)', WebElements::Div, locator)
end

#div_text(locator) ⇒ Object



243
244
245
# File 'lib/fluent/platform_watir/platform_object.rb', line 243

def div_text(locator)
  access_web_element('div(locator).text', locator)
end

#divs(locator) ⇒ Object



239
240
241
# File 'lib/fluent/platform_watir/platform_object.rb', line 239

def divs(locator)
  reference_web_elements('divs(locator)', WebElements::Div, locator)
end

#enclosed_by(encloser) ⇒ Object



488
489
490
491
492
493
494
495
# File 'lib/fluent/platform_watir/platform_object.rb', line 488

def enclosed_by(encloser)
  return if encloser.nil?

  key = encloser[0].keys.first
  value = encloser[0].values.first
  
  "frame(:#{key} => '#{value}')."
end

#focusedObject



64
65
66
67
68
69
# File 'lib/fluent/platform_watir/platform_object.rb', line 64

def focused
  web_element = driver.execute_script('return document.activeElement')
  type = web_element.type.to_sym if web_element.tag_name.to_sym == :input
  object_class = ::Fluent::WebElements.get_class_for(web_element.tag_name, type)
  object_class.new(web_element, :platform => :watir_webdriver)
end

#form(locator) ⇒ Object



415
416
417
# File 'lib/fluent/platform_watir/platform_object.rb', line 415

def form(locator)
  reference_web_element('form(locator)', WebElements::Form, locator)
end

#forms(locator) ⇒ Object



419
420
421
# File 'lib/fluent/platform_watir/platform_object.rb', line 419

def forms(locator)
  reference_web_elements('forms(locator)', WebElements::Form, locator)
end


18
19
20
21
22
23
24
# File 'lib/fluent/platform_watir/platform_object.rb', line 18

def get_cookie_value(name)
  for cookie in @driver.cookies.to_a
    if cookie[:name] == name
      return cookie[:value]
    end
  end
end

#h1(locator) ⇒ Object



343
344
345
# File 'lib/fluent/platform_watir/platform_object.rb', line 343

def h1(locator)
  reference_web_element('h1(locator)', WebElements::Heading, locator)
end

#h1_text(locator) ⇒ Object



351
352
353
# File 'lib/fluent/platform_watir/platform_object.rb', line 351

def h1_text(locator)
  access_web_element('h1(locator).text', locator)
end

#h1s(locator) ⇒ Object



347
348
349
# File 'lib/fluent/platform_watir/platform_object.rb', line 347

def h1s(locator)
  reference_web_elements('h1s(locator)', WebElements::Heading, locator)
end

#h2(locator) ⇒ Object



355
356
357
# File 'lib/fluent/platform_watir/platform_object.rb', line 355

def h2(locator)
  reference_web_element('h2(locator)', WebElements::Heading, locator)
end

#h2_text(locator) ⇒ Object



363
364
365
# File 'lib/fluent/platform_watir/platform_object.rb', line 363

def h2_text(locator)
  access_web_element('h2(locator).text', locator)
end

#h2s(locator) ⇒ Object



359
360
361
# File 'lib/fluent/platform_watir/platform_object.rb', line 359

def h2s(locator)
  reference_web_elements('h2s(locator)', WebElements::Heading, locator)
end

#h3(locator) ⇒ Object



367
368
369
# File 'lib/fluent/platform_watir/platform_object.rb', line 367

def h3(locator)
  reference_web_element('h3(locator)', WebElements::Heading, locator)
end

#h3_text(locator) ⇒ Object



375
376
377
# File 'lib/fluent/platform_watir/platform_object.rb', line 375

def h3_text(locator)
  access_web_element('h3(locator).text', locator)
end

#h3s(locator) ⇒ Object



371
372
373
# File 'lib/fluent/platform_watir/platform_object.rb', line 371

def h3s(locator)
  reference_web_elements('h3s(locator)', WebElements::Heading, locator)
end

#h4(locator) ⇒ Object



379
380
381
# File 'lib/fluent/platform_watir/platform_object.rb', line 379

def h4(locator)
  reference_web_element('h4(locator)', WebElements::Heading, locator)
end

#h4_text(locator) ⇒ Object



387
388
389
# File 'lib/fluent/platform_watir/platform_object.rb', line 387

def h4_text(locator)
  access_web_element('h4(locator).text', locator)
end

#h4s(locator) ⇒ Object



383
384
385
# File 'lib/fluent/platform_watir/platform_object.rb', line 383

def h4s(locator)
  reference_web_elements('h4s(locator)', WebElements::Heading, locator)
end

#h5(locator) ⇒ Object



391
392
393
# File 'lib/fluent/platform_watir/platform_object.rb', line 391

def h5(locator)
  reference_web_element('h5(locator)', WebElements::Heading, locator)
end

#h5_text(locator) ⇒ Object



399
400
401
# File 'lib/fluent/platform_watir/platform_object.rb', line 399

def h5_text(locator)
  access_web_element('h5(locator).text', locator)
end

#h5s(locator) ⇒ Object



395
396
397
# File 'lib/fluent/platform_watir/platform_object.rb', line 395

def h5s(locator)
  reference_web_elements('h5s(locator)', WebElements::Heading, locator)
end

#h6(locator) ⇒ Object



403
404
405
# File 'lib/fluent/platform_watir/platform_object.rb', line 403

def h6(locator)
  reference_web_element('h6(locator)', WebElements::Heading, locator)
end

#h6_text(locator) ⇒ Object



411
412
413
# File 'lib/fluent/platform_watir/platform_object.rb', line 411

def h6_text(locator)
  access_web_element('h6(locator).text', locator)
end

#h6s(locator) ⇒ Object



407
408
409
# File 'lib/fluent/platform_watir/platform_object.rb', line 407

def h6s(locator)
  reference_web_elements('h6s(locator)', WebElements::Heading, locator)
end

#hidden(locator) ⇒ Object



331
332
333
# File 'lib/fluent/platform_watir/platform_object.rb', line 331

def hidden(locator)
  reference_web_element('hidden(locator)', WebElements::Hidden, locator)
end

#hidden_value(locator) ⇒ Object



339
340
341
# File 'lib/fluent/platform_watir/platform_object.rb', line 339

def hidden_value(locator)
  access_web_element('hidden(locator).value', locator)
end

#hiddens(locator) ⇒ Object



335
336
337
# File 'lib/fluent/platform_watir/platform_object.rb', line 335

def hiddens(locator)
  reference_web_elements('hiddens(locator)', WebElements::Hidden, locator)
end

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



423
424
425
# File 'lib/fluent/platform_watir/platform_object.rb', line 423

def image(locator)
  reference_web_element('image(locator)', WebElements::Image, locator)
end

#image_action(locator, action) ⇒ Object



431
432
433
# File 'lib/fluent/platform_watir/platform_object.rb', line 431

def image_action(locator, action)
  access_web_element("image(locator).#{action}", locator)
end

#image_get_alt_text(locator) ⇒ Object



439
440
441
# File 'lib/fluent/platform_watir/platform_object.rb', line 439

def image_get_alt_text(locator)
  access_web_element("image(locator).attribute_value('alt')", locator)
end

#image_get_source(locator) ⇒ Object



435
436
437
# File 'lib/fluent/platform_watir/platform_object.rb', line 435

def image_get_source(locator)
  access_web_element("image(locator).attribute_value('src')", locator)
end

#images(locator) ⇒ Object



427
428
429
# File 'lib/fluent/platform_watir/platform_object.rb', line 427

def images(locator)
  reference_web_elements('images(locator)', WebElements::Image, locator)
end

#label(locator) ⇒ Object



319
320
321
# File 'lib/fluent/platform_watir/platform_object.rb', line 319

def label(locator)
  reference_web_element('label(locator)', WebElements::Label, locator)
end

#label_text(locator) ⇒ Object



327
328
329
# File 'lib/fluent/platform_watir/platform_object.rb', line 327

def label_text(locator)
  access_web_element('label(locator).text', locator)
end

#labels(locator) ⇒ Object



323
324
325
# File 'lib/fluent/platform_watir/platform_object.rb', line 323

def labels(locator)
  reference_web_elements('labels(locator)', WebElements::Label, locator)
end

Generator Actions ##



109
110
111
# File 'lib/fluent/platform_watir/platform_object.rb', line 109

def link(locator)
  reference_web_element('link(locator)', WebElements::Link, locator)
end


117
118
119
# File 'lib/fluent/platform_watir/platform_object.rb', line 117

def link_click(locator)
  access_web_element('link(locator).click', locator)
end


113
114
115
# File 'lib/fluent/platform_watir/platform_object.rb', line 113

def links(locator)
  reference_web_elements('links(locator)', WebElements::Link, locator)
end

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



283
284
285
# File 'lib/fluent/platform_watir/platform_object.rb', line 283

def list_item(locator)
  reference_web_element('li(locator)', WebElements::ListItem, locator)
end

#list_item_text(locator) ⇒ Object



291
292
293
# File 'lib/fluent/platform_watir/platform_object.rb', line 291

def list_item_text(locator)
  access_web_element('li(locator).text', locator)
end

#list_items(locator) ⇒ Object



287
288
289
# File 'lib/fluent/platform_watir/platform_object.rb', line 287

def list_items(locator)
  reference_web_elements('lis(locator)', WebElements::ListItem, locator)
end

#markupObject

Page-Level Actions ##



48
49
50
# File 'lib/fluent/platform_watir/platform_object.rb', line 48

def markup
  driver.html
end

#ordered_list(locator) ⇒ Object Also known as: ol



259
260
261
# File 'lib/fluent/platform_watir/platform_object.rb', line 259

def ordered_list(locator)
  reference_web_element('ol(locator)', WebElements::OrderedList, locator)
end

#ordered_list_text(locator) ⇒ Object



267
268
269
# File 'lib/fluent/platform_watir/platform_object.rb', line 267

def ordered_list_text(locator)
  access_web_element('ol(locator).text', locator)
end

#ordered_lists(locator) ⇒ Object



263
264
265
# File 'lib/fluent/platform_watir/platform_object.rb', line 263

def ordered_lists(locator)
  reference_web_elements('ols(locator)', WebElements::OrderedList, locator)
end

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



223
224
225
# File 'lib/fluent/platform_watir/platform_object.rb', line 223

def paragraph(locator)
  reference_web_element('p(locator)', WebElements::Paragraph, locator)
end

#paragraph_text(locator) ⇒ Object



231
232
233
# File 'lib/fluent/platform_watir/platform_object.rb', line 231

def paragraph_text(locator)
  access_web_element('p(locator).text', locator)
end

#paragraphs(locator) ⇒ Object



227
228
229
# File 'lib/fluent/platform_watir/platform_object.rb', line 227

def paragraphs(locator)
  reference_web_elements('ps(locator)', WebElements::Paragraph, locator)
end

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



207
208
209
# File 'lib/fluent/platform_watir/platform_object.rb', line 207

def radio(locator)
  reference_web_element('radio(locator)', WebElements::Radio, locator)
end

#radio_check_state(locator) ⇒ Object



219
220
221
# File 'lib/fluent/platform_watir/platform_object.rb', line 219

def radio_check_state(locator)
  access_web_element('radio(locator).set?', locator)
end

#radio_select(locator) ⇒ Object



215
216
217
# File 'lib/fluent/platform_watir/platform_object.rb', line 215

def radio_select(locator)
  access_web_element('radio(locator).set', locator)
end

#radios(locator) ⇒ Object



211
212
213
# File 'lib/fluent/platform_watir/platform_object.rb', line 211

def radios(locator)
  reference_web_elements('radios(locator)', WebElements::Radio, locator)
end

#reference_web_element(action, object, locator) ⇒ Object

This method is called by any platform methods that require getting an object reference.

Parameters:

  • action (String)

    the driver logic to be sent to the browser

  • object (Object)

    the type of web object that will receive the action

  • locator (Hash)

    the specific web object selector

Returns:

  • (Object)

    the web object identified by the action



461
462
463
464
465
# File 'lib/fluent/platform_watir/platform_object.rb', line 461

def reference_web_element(action, object, locator)
  encloser = locator.delete(:frame)
  element_object = driver.instance_eval("#{enclosed_by(encloser)}#{action}")
  object.new(element_object, :platform => :watir_webdriver)
end

#reference_web_elements(action, object, locator) ⇒ Object



467
468
469
470
471
472
473
# File 'lib/fluent/platform_watir/platform_object.rb', line 467

def reference_web_elements(action, object, locator)
  encloser = locator.delete(:frame)
  element_objects = driver.instance_eval("#{enclosed_by(encloser)}#{action}")
  element_objects.map do |element|
    object.new(element, :platform => :watir_webdriver)
  end
end

#refreshObject



34
35
36
# File 'lib/fluent/platform_watir/platform_object.rb', line 34

def refresh
  driver.refresh
end

#remove_cookiesObject



30
31
32
# File 'lib/fluent/platform_watir/platform_object.rb', line 30

def remove_cookies
  driver.cookies.clear
end

#run_script(script) ⇒ Object



38
39
40
# File 'lib/fluent/platform_watir/platform_object.rb', line 38

def run_script(script)
  driver.execute_script(script)
end

#screenshot(file) ⇒ Object



42
43
44
# File 'lib/fluent/platform_watir/platform_object.rb', line 42

def screenshot(file)
  driver.wd.save_screenshot(file)
end

#select_list(locator) ⇒ Object



187
188
189
# File 'lib/fluent/platform_watir/platform_object.rb', line 187

def select_list(locator)
  reference_web_element('select_list(locator)', WebElements::SelectList, locator)
end

#select_list_get_selected(locator) ⇒ Object



195
196
197
# File 'lib/fluent/platform_watir/platform_object.rb', line 195

def select_list_get_selected(locator)
  access_web_element('select_list(locator).selected_options[0].text', locator)
end

#select_list_get_value(locator) ⇒ Object



203
204
205
# File 'lib/fluent/platform_watir/platform_object.rb', line 203

def select_list_get_value(locator)
  access_web_element('select_list(locator).value', locator)
end

#select_list_set(locator, value) ⇒ Object



199
200
201
# File 'lib/fluent/platform_watir/platform_object.rb', line 199

def select_list_set(locator, value)
  access_web_element('select_list(locator).select(value)', locator, value)
end

#select_lists(locator) ⇒ Object



191
192
193
# File 'lib/fluent/platform_watir/platform_object.rb', line 191

def select_lists(locator)
  reference_web_elements('select_lists(locator)', WebElements::SelectList, locator)
end

#span(locator) ⇒ Object



247
248
249
# File 'lib/fluent/platform_watir/platform_object.rb', line 247

def span(locator)
  reference_web_element('span(locator)', WebElements::Span, locator)
end

#span_text(locator) ⇒ Object



255
256
257
# File 'lib/fluent/platform_watir/platform_object.rb', line 255

def span_text(locator)
  access_web_element('span(locator).text', locator)
end

#spans(locator) ⇒ Object



251
252
253
# File 'lib/fluent/platform_watir/platform_object.rb', line 251

def spans(locator)
  reference_web_elements('spans(locator)', WebElements::Span, locator)
end

#table(locator) ⇒ Object



295
296
297
# File 'lib/fluent/platform_watir/platform_object.rb', line 295

def table(locator)
  reference_web_element('table(locator)', WebElements::Table, locator)
end

#table_text(locator) ⇒ Object



303
304
305
# File 'lib/fluent/platform_watir/platform_object.rb', line 303

def table_text(locator)
  access_web_element('table(locator).text', locator)
end

#tables(locator) ⇒ Object



299
300
301
# File 'lib/fluent/platform_watir/platform_object.rb', line 299

def tables(locator)
  reference_web_elements('tables(locator)', WebElements::Table, locator)
end

#textObject



56
57
58
# File 'lib/fluent/platform_watir/platform_object.rb', line 56

def text
  driver.text
end

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



149
150
151
# File 'lib/fluent/platform_watir/platform_object.rb', line 149

def text_area(locator)
  reference_web_element('textarea(locator)', WebElements::TextArea, locator)
end

#text_area_get(locator) ⇒ Object



161
162
163
# File 'lib/fluent/platform_watir/platform_object.rb', line 161

def text_area_get(locator)
  access_web_element('textarea(locator).value', locator)
end

#text_area_set(locator, value) ⇒ Object



157
158
159
# File 'lib/fluent/platform_watir/platform_object.rb', line 157

def text_area_set(locator, value)
  access_web_element('textarea(locator).set(value)', locator, value)
end

#text_areas(locator) ⇒ Object



153
154
155
# File 'lib/fluent/platform_watir/platform_object.rb', line 153

def text_areas(locator)
  reference_web_elements('textareas(locator)', WebElements::TextArea, locator)
end

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



133
134
135
# File 'lib/fluent/platform_watir/platform_object.rb', line 133

def text_field(locator)
  reference_web_element('text_field(locator)', WebElements::TextField, locator)
end

#text_field_get(locator) ⇒ Object



145
146
147
# File 'lib/fluent/platform_watir/platform_object.rb', line 145

def text_field_get(locator)
  access_web_element('text_field(locator).value', locator)
end

#text_field_set(locator, value) ⇒ Object



141
142
143
# File 'lib/fluent/platform_watir/platform_object.rb', line 141

def text_field_set(locator, value)
  access_web_element('text_field(locator).set(value)', locator, value)
end

#text_fields(locator) ⇒ Object



137
138
139
# File 'lib/fluent/platform_watir/platform_object.rb', line 137

def text_fields(locator)
  reference_web_elements('text_fields(locator)', WebElements::TextField, locator)
end

#titleObject



52
53
54
# File 'lib/fluent/platform_watir/platform_object.rb', line 52

def title
  driver.title
end

#unordered_list(locator) ⇒ Object Also known as: ul



271
272
273
# File 'lib/fluent/platform_watir/platform_object.rb', line 271

def unordered_list(locator)
  reference_web_element('ul(locator)', WebElements::UnorderedList, locator)
end

#unordered_list_text(locator) ⇒ Object



279
280
281
# File 'lib/fluent/platform_watir/platform_object.rb', line 279

def unordered_list_text(locator)
  access_web_element('ul(locator).text', locator)
end

#unordered_lists(locator) ⇒ Object



275
276
277
# File 'lib/fluent/platform_watir/platform_object.rb', line 275

def unordered_lists(locator)
  reference_web_elements('uls(locator)', WebElements::UnorderedList, locator)
end

#urlObject



26
27
28
# File 'lib/fluent/platform_watir/platform_object.rb', line 26

def url
  driver.url
end

#visit(url) ⇒ Object

Browser-Level Actions ##



14
15
16
# File 'lib/fluent/platform_watir/platform_object.rb', line 14

def visit(url)
  driver.goto(url.to_s)
end

#wait_until(timeout, message = 'wait condition was not found', &block) ⇒ Object



60
61
62
# File 'lib/fluent/platform_watir/platform_object.rb', line 60

def wait_until(timeout, message='wait condition was not found', &block)
  driver.wait_until(timeout, message, &block)
end

#will_alert(&block) ⇒ Object

Encloser Actions ##



73
74
75
76
77
78
79
80
81
# File 'lib/fluent/platform_watir/platform_object.rb', line 73

def will_alert(&block)
  yield
  value = nil
  if driver.alert.exists?
    value = driver.alert.text
    driver.alert.ok
  end
  value
end

#will_confirm(response, &block) ⇒ Object



83
84
85
86
87
88
89
90
91
# File 'lib/fluent/platform_watir/platform_object.rb', line 83

def will_confirm(response, &block)
  yield
  value = nil
  if driver.alert.exists?
    value = driver.alert.text
    response ? driver.alert.ok : driver.alert.close
  end
  value
end

#will_prompt(response, &block) ⇒ Object



93
94
95
96
97
98
99
100
# File 'lib/fluent/platform_watir/platform_object.rb', line 93

def will_prompt(response, &block)
  cmd = "window.prompt = function(text, value) {window.__lastWatirPrompt = {message: text, default_value: value}; return '#{response}';}"
  driver.wd.execute_script(cmd)
  yield
  result = driver.wd.execute_script('return window.__lastWatirPrompt')
  result && result.dup.each_key { |k| result[k.to_sym] = result.delete(k) }
  result
end

#within_window(locator, &block) ⇒ Object



102
103
104
105
# File 'lib/fluent/platform_watir/platform_object.rb', line 102

def within_window(locator, &block)
  identifier = {locator.keys.first => /#{Regexp.escape(locator.values.first)}/}
  driver.window(identifier).use(&block)
end