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



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

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

#button(locator) ⇒ Object



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

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

#button_click(locator) ⇒ Object



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

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

#buttons(locator) ⇒ Object



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

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

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



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

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

#cell_text(locator) ⇒ Object



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

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

#cells(locator) ⇒ Object



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

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

#checkbox(locator) ⇒ Object



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

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

#checkbox_check(locator) ⇒ Object



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

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

#checkbox_check_state(locator) ⇒ Object



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

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

#checkbox_uncheck(locator) ⇒ Object



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

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

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



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

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

#div(locator) ⇒ Object



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

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

#div_text(locator) ⇒ Object



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

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

#divs(locator) ⇒ Object



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

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

#enclosed_by(encloser) ⇒ Object



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

def enclosed_by(encloser)
  return if encloser.nil?

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

#focusedObject



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

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



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

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

#forms(locator) ⇒ Object



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

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


18
19
20
21
22
23
24
25
# 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
  nil
end

#h1(locator) ⇒ Object



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

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

#h1_text(locator) ⇒ Object



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

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

#h1s(locator) ⇒ Object



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

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

#h2(locator) ⇒ Object



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

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

#h2_text(locator) ⇒ Object



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

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

#h2s(locator) ⇒ Object



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

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

#h3(locator) ⇒ Object



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

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

#h3_text(locator) ⇒ Object



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

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

#h3s(locator) ⇒ Object



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

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

#h4(locator) ⇒ Object



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

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

#h4_text(locator) ⇒ Object



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

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

#h4s(locator) ⇒ Object



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

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

#h5(locator) ⇒ Object



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

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

#h5_text(locator) ⇒ Object



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

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

#h5s(locator) ⇒ Object



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

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

#h6(locator) ⇒ Object



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

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

#h6_text(locator) ⇒ Object



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

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

#h6s(locator) ⇒ Object



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

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

#hidden(locator) ⇒ Object



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

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

#hidden_value(locator) ⇒ Object



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

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

#hiddens(locator) ⇒ Object



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

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

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



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

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

#image_action(locator, action) ⇒ Object



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

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

#image_get_alt_text(locator) ⇒ Object



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

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

#image_get_source(locator) ⇒ Object



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

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

#images(locator) ⇒ Object



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

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

#label(locator) ⇒ Object



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

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

#label_text(locator) ⇒ Object



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

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

#labels(locator) ⇒ Object



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

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

Generator Actions ##



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

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


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

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


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

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

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



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

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

#list_item_text(locator) ⇒ Object



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

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

#list_items(locator) ⇒ Object



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

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

#markupObject

Page-Level Actions ##



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

def markup
  driver.html
end

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



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

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

#ordered_list_text(locator) ⇒ Object



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

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

#ordered_lists(locator) ⇒ Object



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

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

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



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

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

#paragraph_text(locator) ⇒ Object



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

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

#paragraphs(locator) ⇒ Object



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

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

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



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

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

#radio_check_state(locator) ⇒ Object



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

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

#radio_select(locator) ⇒ Object



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

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

#radios(locator) ⇒ Object



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

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



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

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



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

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



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

def refresh
  driver.refresh
end

#remove_cookiesObject



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

def remove_cookies
  driver.cookies.clear
end

#run_script(script) ⇒ Object



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

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

#screenshot(file) ⇒ Object



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

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

#select_list(locator) ⇒ Object



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

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

#select_list_get_selected(locator) ⇒ Object



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

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

#select_list_get_value(locator) ⇒ Object



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

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

#select_list_set(locator, value) ⇒ Object



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

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

#select_lists(locator) ⇒ Object



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

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

#span(locator) ⇒ Object



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

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

#span_text(locator) ⇒ Object



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

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

#spans(locator) ⇒ Object



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

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

#table(locator) ⇒ Object



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

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

#table_text(locator) ⇒ Object



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

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

#tables(locator) ⇒ Object



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

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

#textObject



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

def text
  driver.text
end

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



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

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

#text_area_get(locator) ⇒ Object



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

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

#text_area_set(locator, value) ⇒ Object



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

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

#text_areas(locator) ⇒ Object



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

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

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



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

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

#text_field_get(locator) ⇒ Object



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

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

#text_field_set(locator, value) ⇒ Object



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

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

#text_fields(locator) ⇒ Object



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

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

#titleObject



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

def title
  driver.title
end

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



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

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

#unordered_list_text(locator) ⇒ Object



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

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

#unordered_lists(locator) ⇒ Object



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

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

#urlObject



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

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



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

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

#will_alert(&block) ⇒ Object

Encloser Actions ##



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

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



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

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



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

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



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

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