Class: TestCentricity::UIElement

Inherits:
Object
  • Object
show all
Includes:
Capybara::DSL, Test::Unit::Assertions
Defined in:
lib/testcentricity_web/ui_elements_helper.rb,
lib/testcentricity_web/siebel_open_ui_helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, locator, context, type = nil) ⇒ UIElement

Returns a new instance of UIElement.



28
29
30
31
32
33
34
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 28

def initialize(parent, locator, context, type = nil)
  @parent  = parent
  @locator = locator
  @context = context
  @type    = type
  @alt_locator = nil
end

Instance Attribute Details

#alt_locatorObject

Returns the value of attribute alt_locator.



26
27
28
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 26

def alt_locator
  @alt_locator
end

#contextObject (readonly)

Returns the value of attribute context.



25
26
27
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 25

def context
  @context
end

#locatorObject (readonly)

Returns the value of attribute locator.



25
26
27
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 25

def locator
  @locator
end

#parentObject (readonly)

Returns the value of attribute parent.



25
26
27
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 25

def parent
  @parent
end

#typeObject (readonly)

Returns the value of attribute type.



25
26
27
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 25

def type
  @type
end

Instance Method Details

#attach_file(file_path) ⇒ Object



324
325
326
327
328
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 324

def attach_file(file_path)
  Capybara.ignore_hidden_elements = false
  page.attach_file(@locator, file_path)
  Capybara.ignore_hidden_elements = true
end

#checked?Boolean

Is checkbox checked?

Examples:

remember_me_checkbox.checked?

Returns:

  • (Boolean)


206
207
208
209
210
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 206

def checked?
  obj, _ = find_element
  object_not_found_exception(obj, 'Checkbox')
  obj.checked?
end

#choose_option(option) ⇒ Object

Select the specified option in a select box object. Supports standard HTML select objects and Chosen select objects.

Examples:

province_select.choose_option('Nova Scotia')

Parameters:

  • option (String)

    text of option to select



337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 337

def choose_option(option)
  obj, _ = find_element
  object_not_found_exception(obj, nil)
  obj.click
  if first(:css, 'li.active-result')
    if option.is_a?(Array)
      option.each do |item|
        page.find(:css, 'li.active-result', text: item.strip).click
      end
    else
      first(:css, 'li.active-result', text: option).click
    end
  else
    if option.is_a?(Array)
      option.each do |item|
        obj.select item
      end
    else
      obj.select option
    end
  end
end

#choose_siebel_option(option) ⇒ Object

Select the specified option in a Siebel OUI select box object.

Examples:

country_select.choose_option('Cayman Islands')

Parameters:

  • option (String)

    text of option to select



23
24
25
26
27
# File 'lib/testcentricity_web/siebel_open_ui_helper.rb', line 23

def choose_siebel_option(option)
  Capybara.wait_on_first_by_default = true
  invoke_siebel_popup
  first(:xpath, "//li[@class='ui-menu-item']", :exact => true, :match => :prefer_exact,text: option).click
end

#clear_alt_locatorObject



44
45
46
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 44

def clear_alt_locator
  @alt_locator = nil
end

#clickObject

Click on an object

Examples:

basket_link.click


53
54
55
56
57
58
59
60
61
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 53

def click
  obj, _ = find_element
  object_not_found_exception(obj, nil)
  begin
    obj.click
  rescue
    obj.click_at(10, 10) unless Capybara.current_driver == :poltergeist
  end
end

#click_at(x, y) ⇒ Object

Click at a specific location within an an object

Examples:

basket_item_image.click_at(10, 10)

Parameters:

  • x (Integer)

    X offset

  • y (Integer)

    Y offset



81
82
83
84
85
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 81

def click_at(x, y)
  obj, _ = find_element
  raise "Object #{@locator} not found" unless obj
  obj.click_at(x, y)
end

#click_header_column(column) ⇒ Object



584
585
586
587
588
589
590
591
592
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 584

def click_header_column(column)
  column_count = get_column_count
  raise "Column #{column} exceeds number of columns (#{column_count}) in table header #{@locator}" if column > column_count
  (column > 1) ?
      set_alt_locator("#{@locator}/thead/tr/th[#{column}]") :
      set_alt_locator("#{@locator}/thead/tr/th")
  click
  clear_alt_locator
end

#click_table_cell(row, column) ⇒ Object

Click in the specified cell in a table object.

Examples:

list_table.click_table_cell(3, 5)

Parameters:

  • row (Integer)

    row number

  • column (Integer)

    column number



437
438
439
440
441
442
443
444
445
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 437

def click_table_cell(row, column)
  row_count = get_row_count
  raise "Row #{row} exceeds number of rows (#{row_count}) in table #{@locator}" if row > row_count
  column_count = get_column_count
  raise "Column #{column} exceeds number of columns (#{column_count}) in table #{@locator}" if column > column_count
  set_table_cell_locator(row, column)
  click
  clear_alt_locator
end

Click the link object embedded within the specified cell in a table object.

Examples:

list_table.click_table_cell_link(3, 1)

Parameters:

  • row (Integer)

    row number

  • column (Integer)

    column number



471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 471

def click_table_cell_link(row, column)
  row_count = get_row_count
  raise "Row #{row} exceeds number of rows (#{row_count}) in table #{@locator}" if row > row_count
  column_count = get_column_count
  raise "Column #{column} exceeds number of columns (#{column_count}) in table #{@locator}" if column > column_count
  set_table_cell_locator(row, column)
  saved_locator = @alt_locator
  set_alt_locator("#{@alt_locator}/a")
  set_alt_locator("#{saved_locator}/span/a") unless exists?
  # if link not present, check for text entry fields and try to dismiss by tabbing out
  unless exists?
    set_alt_locator("#{saved_locator}/input")
    set_alt_locator("#{saved_locator}/textarea") unless exists?
    send_keys(:tab) if exists?
    set_alt_locator("#{saved_locator}/a")
    set_alt_locator("#{saved_locator}/span/a") unless exists?
    send_keys(:tab) unless exists?
  end
  wait_until_exists(1)
  click
  clear_alt_locator
end

#collapse_table_row(row, column) ⇒ Object



82
83
84
85
86
87
88
89
# File 'lib/testcentricity_web/siebel_open_ui_helper.rb', line 82

def collapse_table_row(row, column)
  if is_table_row_expanded?(row, column)
    set_table_cell_locator(row, column)
    set_alt_locator("#{@alt_locator}/div/div[contains(@class, 'tree-minus treeclick')]")
    click if exists?
    clear_alt_locator
  end
end

#disabled?Boolean

Is UI object disabled (not enabled)?

Examples:

.disabled?

Returns:

  • (Boolean)


170
171
172
173
174
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 170

def disabled?
  obj, _ = find_element
  object_not_found_exception(obj, nil)
  obj.disabled?
end

#double_clickObject

Double-click on an object

Examples:

file_image.double_click


68
69
70
71
72
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 68

def double_click
  obj, _ = find_element
  object_not_found_exception(obj, nil)
  page.driver.browser.mouse.double_click(obj.native)
end

#double_click_table_cell(row, column) ⇒ Object

Double-click in the specified cell in a table object.

Examples:

list_table.double_click_table_cell(3, 5)

Parameters:

  • row (Integer)

    row number

  • column (Integer)

    column number



454
455
456
457
458
459
460
461
462
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 454

def double_click_table_cell(row, column)
  row_count = get_row_count
  raise "Row #{row} exceeds number of rows (#{row_count}) in table #{@locator}" if row > row_count
  column_count = get_column_count
  raise "Column #{column} exceeds number of columns (#{column_count}) in table #{@locator}" if column > column_count
  set_table_cell_locator(row, column)
  double_click
  clear_alt_locator
end

#drag_by(right_offset, down_offset) ⇒ Object



318
319
320
321
322
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 318

def drag_by(right_offset, down_offset)
  obj, _ = find_element
  object_not_found_exception(obj, nil)
  obj.drag_by(right_offset, down_offset)
end

#enabled?Boolean

Is UI object enabled?

Examples:

.enabled?

Returns:

  • (Boolean)


160
161
162
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 160

def enabled?
  not disabled?
end

#exists?Boolean

Does UI object exists?

Examples:

basket_link.exists?

Returns:

  • (Boolean)


111
112
113
114
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 111

def exists?
  obj, _ = find_element
  obj != nil
end

#expand_all_table_rows(column) ⇒ Object



91
92
93
94
95
96
97
98
# File 'lib/testcentricity_web/siebel_open_ui_helper.rb', line 91

def expand_all_table_rows(column)
  row_count = get_row_count
  column_count = get_column_count
  raise "Column #{column} exceeds number of columns (#{column_count}) in table #{@locator}" if column > column_count
  row_count.downto(1) do |row|
    expand_table_row(row, column)
  end
end

#expand_table_row(row, column) ⇒ Object



73
74
75
76
77
78
79
80
# File 'lib/testcentricity_web/siebel_open_ui_helper.rb', line 73

def expand_table_row(row, column)
  unless is_table_row_expanded?(row, column)
    set_table_cell_locator(row, column)
    set_alt_locator("#{@alt_locator}/div/div[contains(@class, 'tree-plus treeclick')]")
    click if exists?
    clear_alt_locator
  end
end

#get_column_countInteger

Return number of columns in a table object.

Examples:

num_columns = list_table.get_column_count

Returns:

  • (Integer)


419
420
421
422
423
424
425
426
427
428
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 419

def get_column_count
  row_count = get_row_count
  if row_count == 0
    page.all(:xpath, "#{@locator}/thead/tr/th", :visible => :all).count
  else
    (row_count == 1) ?
        page.all(:xpath, "#{@locator}/tbody/tr/td", :visible => :all).count :
        page.all(:xpath, "#{@locator}/tbody/tr[2]/td", :visible => :all).count
  end
end

#get_header_column(column) ⇒ Object



594
595
596
597
598
599
600
601
602
603
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 594

def get_header_column(column)
  column_count = get_column_count
  raise "Column #{column} exceeds number of columns (#{column_count}) in table header #{@locator}" if column > column_count
  (column > 1) ?
      set_alt_locator("#{@locator}/thead/tr/th[#{column}]") :
      set_alt_locator("#{@locator}/thead/tr/th")
  value = get_value
  clear_alt_locator
  value
end

#get_header_columnsObject



605
606
607
608
609
610
611
612
613
614
615
616
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 605

def get_header_columns
  columns = []
  column_count = get_column_count
  (1..column_count).each do |column|
    (column > 1) ?
        set_alt_locator("#{@locator}/thead/tr/th[#{column}]") :
        set_alt_locator("#{@locator}/thead/tr/th")
    columns.push(get_value)
  end
  clear_alt_locator
  columns
end

#get_list_items(item_locator) ⇒ Object



618
619
620
621
622
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 618

def get_list_items(item_locator)
  obj, _ = find_element
  object_not_found_exception(obj, nil)
  obj.all(item_locator).collect(&:text)
end

#get_locatorObject



36
37
38
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 36

def get_locator
  @locator
end

#get_max_lengthInteger

Return maxlength character count of a text field.

Examples:

max_num_chars = comments_field.get_max_length

Returns:

  • (Integer)


194
195
196
197
198
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 194

def get_max_length
  obj, _ = find_element
  object_not_found_exception(obj, nil)
  obj.native.attribute('maxlength')
end

#get_optionsArray

Return array of strings of all options in a select box object. Supports standard HTML select objects and Chosen select objects.

Examples:

all_colors = color_select.get_options

Returns:

  • (Array)


367
368
369
370
371
372
373
374
375
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 367

def get_options
  obj, _ = find_element
  object_not_found_exception(obj, nil)
  if first(:css, 'li.active-result')
    obj.all('li.active-result').collect(&:text)
  else
    obj.all('option').collect(&:text)
  end
end

#get_row_countInteger

Return number of rows in a table object.

Examples:

num_rows = list_table.get_row_count

Returns:

  • (Integer)


407
408
409
410
411
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 407

def get_row_count
  wait_until_exists(5)
  row_count = page.all(:xpath, "#{@locator}/tbody/tr", :visible => :all).count
  row_count
end

#get_row_data(row) ⇒ Object



517
518
519
520
521
522
523
524
525
526
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 517

def get_row_data(row)
  row_count = get_row_count
  raise "Row #{row} exceeds number of rows (#{row_count}) in table #{@locator}" if row > row_count
  (row > 1) ?
      set_alt_locator("#{@locator}/tbody/tr[#{row}]") :
      set_alt_locator("#{@locator}/tbody/tr")
  value = get_value if exists?
  clear_alt_locator
  value
end

#get_selected_optionString

Return text of first selected option in a select box object. Supports standard HTML select objects and Chosen select objects.

Examples:

current_color = color_select.get_selected_option

Returns:



391
392
393
394
395
396
397
398
399
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 391

def get_selected_option
  obj, _ = find_element
  object_not_found_exception(obj, nil)
  if first(:css, 'li.active-result')
    obj.first("//li[contains(@class, 'result-selected')]").text
  else
    obj.first('option[selected]').text
  end
end

#get_siebel_object_typeObject



100
101
102
103
104
# File 'lib/testcentricity_web/siebel_open_ui_helper.rb', line 100

def get_siebel_object_type
  obj, _ = find_element
  object_not_found_exception(obj, 'Siebel object')
  obj.native.attribute('ot')
end

#get_siebel_optionsArray

Return array of strings of all options in a Siebel OUI select box object.

Examples:

all_countries = country_select.get_options

Returns:

  • (Array)


35
36
37
38
39
40
41
42
# File 'lib/testcentricity_web/siebel_open_ui_helper.rb', line 35

def get_siebel_options
  invoke_siebel_popup
  sleep(0.5)
  options = page.all(:xpath, "//li[@class='ui-menu-item']").collect(&:text)
  obj, _ = find_element
  obj.native.send_keys(:escape)
  options
end

#get_table_cell(row, column) ⇒ String

Return text contained in specified cell of a table object.

Examples:

list_table.get_table_cell(4, 5)

Parameters:

  • row (Integer)

    row number

  • column (Integer)

    column number

Returns:

  • (String)

    value of table cell



536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 536

def get_table_cell(row, column)
  row_count = get_row_count
  raise "Row #{row} exceeds number of rows (#{row_count}) in table #{@locator}" if row > row_count
  column_count = get_column_count
  raise "Column #{column} exceeds number of columns (#{column_count}) in table #{@locator}" if column > column_count
  set_table_cell_locator(row, column)
  saved_locator = @alt_locator
  set_alt_locator("#{saved_locator}/input")
  unless exists?
    set_alt_locator("#{saved_locator}/textarea")
    unless exists?
      set_alt_locator(saved_locator)
    end
  end
  value = get_value
  clear_alt_locator
  value
end

#get_table_row(row) ⇒ Object



494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 494

def get_table_row(row)
  columns = []
  row_count = get_row_count
  raise "Row #{row} exceeds number of rows (#{row_count}) in table #{@locator}" if row > row_count
  column_count = get_column_count
  (1..column_count).each do |column|
    value = ''
    set_table_cell_locator(row, column)
    saved_locator = @alt_locator
    set_alt_locator("#{saved_locator}/input")
    unless exists?
      set_alt_locator("#{saved_locator}/textarea")
      unless exists?
        set_alt_locator(saved_locator)
      end
    end
    value = get_value if exists?
    columns.push(value)
  end
  clear_alt_locator
  columns
end

#get_valueObject



289
290
291
292
293
294
295
296
297
298
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 289

def get_value
  obj, _ = find_element
  object_not_found_exception(obj, nil)
  case obj.tag_name.downcase
    when 'input', 'select', 'textarea'
      obj.value
    else
      obj.text
  end
end

#hidden?Boolean

Is UI object hidden (not visible)?

Examples:

remember_me_checkbox.hidden?

Returns:

  • (Boolean)


150
151
152
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 150

def hidden?
  not visible?
end

#hoverObject

Hover the cursor over an object

Examples:

basket_link.hover


312
313
314
315
316
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 312

def hover
  obj, _ = find_element
  object_not_found_exception(obj, nil)
  obj.hover
end

#invoke_siebel_dialog(popup) ⇒ Object



55
56
57
58
# File 'lib/testcentricity_web/siebel_open_ui_helper.rb', line 55

def invoke_siebel_dialog(popup)
  invoke_siebel_popup
  popup.wait_until_exists(15)
end

#is_table_row_expanded?(row, column) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/testcentricity_web/siebel_open_ui_helper.rb', line 60

def is_table_row_expanded?(row, column)
  row_count = get_row_count
  raise "Row #{row} exceeds number of rows (#{row_count}) in table #{@locator}" if row > row_count
  column_count = get_column_count
  raise "Column #{column} exceeds number of columns (#{column_count}) in table #{@locator}" if column > column_count
  set_table_cell_locator(row, column)
  set_alt_locator("#{@alt_locator}/div/div[contains(@class, 'tree-plus treeclick')]")
  expanded = true
  expanded = false if exists?
  clear_alt_locator
  expanded
end

#read_only?Boolean

Is text field set to read-only?

Examples:

comments_field.read_only?

Returns:

  • (Boolean)


182
183
184
185
186
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 182

def read_only?
  obj, _ = find_element
  object_not_found_exception(obj, nil)
  !!obj.native.attribute('readonly')
end

#send_keys(*keys) ⇒ Object

comment_field.send_keys(:enter)



99
100
101
102
103
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 99

def send_keys(*keys)
  obj, _ = find_element
  object_not_found_exception(obj, nil)
  obj.send_keys(*keys)
end

#set(value) ⇒ Object



87
88
89
90
91
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 87

def set(value)
  obj, _ = find_element
  object_not_found_exception(obj, nil)
  obj.set(value)
end

#set_alt_locator(temp_locator) ⇒ Object



40
41
42
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 40

def set_alt_locator(temp_locator)
  @alt_locator = temp_locator
end

#set_checkbox_state(state) ⇒ Object

Set the check state of a checkbox object.

Examples:

remember_me_checkbox.set_checkbox_state(true)

Parameters:

  • state (Boolean)

    true = checked / false = unchecked



218
219
220
221
222
223
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 218

def set_checkbox_state(state)
  obj, _ = find_element
  object_not_found_exception(obj, 'Checkbox')
  invalid_object_type_exception(obj, 'checkbox')
  obj.set(state)
end

#set_siebel_checkbox_state(state) ⇒ Object

Set the check state of a Siebel OUI JCheckBox object.

Examples:

remember_me_checkbox.set_checkbox_state(true)

Parameters:

  • state (Boolean)

    true = checked / false = unchecked



9
10
11
12
13
14
15
# File 'lib/testcentricity_web/siebel_open_ui_helper.rb', line 9

def set_siebel_checkbox_state(state)
  obj, _ = find_element
  object_not_found_exception(obj, 'Siebel checkbox')
  raise "#{locator} is not a Siebel CheckBox object" unless get_siebel_object_type == 'JCheckBox'
  expected = state.to_bool
  obj.click unless expected == obj.checked?
end

#set_table_cell(row, column, value) ⇒ Object

Set the value of the specified cell in a table object.

Examples:

list_table.set_table_cell(3, 1, 'Ontario')

Parameters:

  • row (Integer)

    row number

  • column (Integer)

    column number

  • value (String)

    text to set



570
571
572
573
574
575
576
577
578
579
580
581
582
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 570

def set_table_cell(row, column, value)
  row_count = get_row_count
  raise "Row #{row} exceeds number of rows (#{row_count}) in table #{@locator}" if row > row_count
  # column_count = get_column_count
  # raise "Column #{column} exceeds number of columns (#{column_count}) in table #{@locator}" if column > column_count
  set_table_cell_locator(row, column)
  click if exists?
  saved_locator = @alt_locator
  set_alt_locator("#{saved_locator}/input")
  set_alt_locator("#{saved_locator}/textarea") unless exists?
  set(value)
  clear_alt_locator
end

#verify_check_state(state, enqueue = false) ⇒ Object



225
226
227
228
229
230
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 225

def verify_check_state(state, enqueue = false)
  actual = checked?
  enqueue ?
      ExceptionQueue.enqueue_assert_equal(state, actual, "Expected #{@locator}") :
      assert_equal(state, actual, "Expected #{@locator} to be #{state} but found #{actual} instead")
end

#verify_options(expected, enqueue = false) ⇒ Object



377
378
379
380
381
382
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 377

def verify_options(expected, enqueue = false)
  actual = get_options
  enqueue ?
      ExceptionQueue.enqueue_assert_equal(expected, actual, "Expected list of options in list #{@locator}") :
      assert_equal(expected, actual, "Expected list of options in list #{@locator} to be #{expected} but found #{actual}")
end

#verify_siebel_options(expected, enqueue = false) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'lib/testcentricity_web/siebel_open_ui_helper.rb', line 44

def verify_siebel_options(expected, enqueue = false)
  invoke_siebel_popup
  sleep(0.5)
  actual = page.all(:xpath, "//li[@class='ui-menu-item']").collect(&:text)
  enqueue ?
      ExceptionQueue.enqueue_assert_equal(expected, actual, "Expected list of options in list #{@locator}") :
      assert_equal(expected, actual, "Expected list of options in list #{@locator} to be #{expected} but found #{actual}")
  obj, _ = find_element
  obj.native.send_keys(:escape)
end

#verify_table_cell(row, column, expected, enqueue = false) ⇒ Object



555
556
557
558
559
560
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 555

def verify_table_cell(row, column, expected, enqueue = false)
  actual = get_table_cell(row, column)
  enqueue ?
      ExceptionQueue.enqueue_assert_equal(expected.strip, actual.strip, "Expected #{@locator} row #{row}/column #{column}") :
      assert_equal(expected.strip, actual.strip, "Expected #{@locator} row #{row}/column #{column} to display '#{expected}' but found '#{actual}'")
end

#verify_value(expected, enqueue = false) ⇒ Object



300
301
302
303
304
305
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 300

def verify_value(expected, enqueue = false)
  actual = get_value
  enqueue ?
      ExceptionQueue.enqueue_assert_equal(expected.strip, actual.strip, "Expected #{@locator}") :
      assert_equal(expected.strip, actual.strip, "Expected #{@locator} to display '#{expected}' but found '#{actual}'")
end

#visible?Boolean

Is UI object visible?

Examples:

remember_me_checkbox.visible?

Returns:

  • (Boolean)


122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 122

def visible?
  obj, type = find_element
  exists = obj
  invisible = false
  if type == :css
    Capybara.using_wait_time 0.1 do
      # is object itself hidden with .ui-helper-hidden class?
      self_hidden = page.has_css?("#{@locator}.ui-helper-hidden")
      # is parent of object hidden, thus hiding the object?
      parent_hidden = page.has_css?(".ui-helper-hidden > #{@locator}")
      # is grandparent of object, or any other ancestor, hidden?
      other_ancestor_hidden = page.has_css?(".ui-helper-hidden * #{@locator}")
      # if any of the above conditions are true, then object is invisible
      invisible = self_hidden || parent_hidden || other_ancestor_hidden
    end
  else
    invisible = !obj.visible? if exists
  end
  # the object is visible if it exists and it is not invisible
  (exists && !invisible) ? true : false
end

#wait_until_exists(seconds) ⇒ Object

Wait until the object exists, or until the specified wait time has expired.

Examples:

run_button.wait_until_exists(0.5)

Parameters:

  • seconds (Integer or Float)

    wait time in seconds



238
239
240
241
242
243
244
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 238

def wait_until_exists(seconds)
  timeout = seconds.nil? ? Capybara.default_max_wait_time : seconds
  wait = Selenium::WebDriver::Wait.new(timeout: timeout)
  wait.until { exists? }
rescue
  raise "Could not find element #{@locator} after #{timeout} seconds" unless exists?
end

#wait_until_gone(seconds) ⇒ Object

Wait until the object no longer exists, or until the specified wait time has expired.

Examples:

logout_button.wait_until_gone(5)

Parameters:

  • seconds (Integer or Float)

    wait time in seconds



252
253
254
255
256
257
258
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 252

def wait_until_gone(seconds)
  timeout = seconds.nil? ? Capybara.default_max_wait_time : seconds
  wait = Selenium::WebDriver::Wait.new(timeout: timeout)
  wait.until { !exists? }
rescue
  raise "Element #{@locator} remained visible after #{timeout} seconds" if exists?
end

#wait_until_value_changes(seconds) ⇒ Object

Wait until the object's value changes to a different value, or until the specified wait time has expired.

Examples:

basket_grand_total_label.wait_until_value_changes(5)

Parameters:

  • seconds (Integer or Float)

    wait time in seconds



280
281
282
283
284
285
286
287
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 280

def wait_until_value_changes(seconds)
  value = get_value
  timeout = seconds.nil? ? Capybara.default_max_wait_time : seconds
  wait = Selenium::WebDriver::Wait.new(timeout: timeout)
  wait.until { get_value != value }
rescue
  raise "Value of UI element #{@locator} failed to change from '#{value}' after #{timeout} seconds" unless exists?
end

#wait_until_value_is(value, seconds) ⇒ Object

Wait until the object's value equals the specified value, or until the specified wait time has expired.

Examples:

card_authorized_label.wait_until_value_is(5, 'Card authorized')

Parameters:

  • seconds (Integer or Float)

    wait time in seconds



266
267
268
269
270
271
272
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 266

def wait_until_value_is(value, seconds)
  timeout = seconds.nil? ? Capybara.default_max_wait_time : seconds
  wait = Selenium::WebDriver::Wait.new(timeout: timeout)
  wait.until { get_value == value }
rescue
  raise "Value of UI element #{@locator} failed to equal '#{value}' after #{timeout} seconds" unless exists?
end