Class: Spreewald::FieldErrorFinder

Inherits:
Object
  • Object
show all
Includes:
DriverInfo, WithoutWaiting
Defined in:
lib/spreewald_support/field_errors.rb

Instance Method Summary collapse

Methods included from WithoutWaiting

#without_waiting

Methods included from DriverInfo

#browser, #javascript_capable?, #poltergeist_driver?, #require_selenium!, #selenium_driver?, #webkit_driver?

Constructor Details

#initialize(page, element) ⇒ FieldErrorFinder

Returns a new instance of FieldErrorFinder.



27
28
29
30
# File 'lib/spreewald_support/field_errors.rb', line 27

def initialize(page, element)
  @page = page
  @element = element
end

Instance Method Details

#bootstrap3_error?Boolean

Returns:

  • (Boolean)


46
47
48
49
50
# File 'lib/spreewald_support/field_errors.rb', line 46

def bootstrap3_error?
  has_xpath? do |x|
    x.ancestor(:div)[x.attr(:class).contains_word('form-group')][x.attr(:class).contains_word('has-error')]
  end
end

#bootstrap45_error?Boolean

Returns:

  • (Boolean)


52
53
54
55
56
57
58
59
60
61
# File 'lib/spreewald_support/field_errors.rb', line 52

def bootstrap45_error?
  without_waiting do
    element_classes = @element[:class]&.split(' ') || []
    invalid_elements = if javascript_capable?
      @page.all(':invalid') # Collect all invalid elements as Bootstrap 4 and 5 support client validation
    end

    element_classes.include?('is-invalid') || (invalid_elements && invalid_elements.include?(@element))
  end
end

#custom_error?Boolean

Returns:

  • (Boolean)


38
39
40
41
42
43
44
# File 'lib/spreewald_support/field_errors.rb', line 38

def custom_error?
  return false unless Spreewald.field_error_class

  has_xpath? do |x|
    x.ancestor_or_self(:div)[x.attr(:class).contains_word(Spreewald.field_error_class)]
  end
end

#error_present?Boolean

Returns:

  • (Boolean)


32
33
34
35
36
# File 'lib/spreewald_support/field_errors.rb', line 32

def error_present?
  without_waiting do
    custom_error? || bootstrap3_error? || bootstrap45_error? || rails_error?
  end
end

#rails_error?Boolean

Returns:

  • (Boolean)


63
64
65
66
67
# File 'lib/spreewald_support/field_errors.rb', line 63

def rails_error?
  has_xpath? do |x|
    x.ancestor(:div)[x.attr(:class).contains_word('field_with_errors')]
  end
end