Module: Avo::WaitForLoaded

Included in:
TestHelpers
Defined in:
lib/avo/wait_for_loaded.rb

Instance Method Summary collapse

Instance Method Details

#wait_for_action_dialog_to_disappear(time = Capybara.default_max_wait_time) ⇒ Object



72
73
74
# File 'lib/avo/wait_for_loaded.rb', line 72

def wait_for_action_dialog_to_disappear(time = Capybara.default_max_wait_time)
  wait_for_element_missing("[role='dialog']", time)
end

#wait_for_body_class_missing(klass = "turbo-loading", time = Capybara.default_max_wait_time) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/avo/wait_for_loaded.rb', line 33

def wait_for_body_class_missing(klass = "turbo-loading", time = Capybara.default_max_wait_time)
  Timeout.timeout(time) do
    body = page.find(:xpath, "//body")
    break if !body[:class].to_s.include?(klass)

    if page.present? && body.present? && body[:class].present? && body[:class].is_a?(String)
      sleep(0.1) until page.present? && !body[:class].to_s.include?(klass)
    else
      sleep 0.1
    end
  end
rescue Timeout::Error
  puts "\n\nMethod '#{__method__}' raised 'Timeout::Error' after #{time}s"
end

#wait_for_element_missing(identifier = ".element", time = Capybara.default_max_wait_time) ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'lib/avo/wait_for_loaded.rb', line 48

def wait_for_element_missing(identifier = ".element", time = Capybara.default_max_wait_time)
  Timeout.timeout(time) do
    if page.present?
      break if page.has_no_css?(identifier, wait: time)
    else
      sleep 0.05
    end
  end
end

#wait_for_element_present(identifier = ".element", time = Capybara.default_max_wait_time) ⇒ Object



58
59
60
61
62
63
64
65
66
# File 'lib/avo/wait_for_loaded.rb', line 58

def wait_for_element_present(identifier = ".element", time = Capybara.default_max_wait_time)
  Timeout.timeout(time) do
    if page.present?
      break if page.has_css?(identifier, wait: time)
    else
      sleep 0.05
    end
  end
end

#wait_for_loadedObject



68
69
70
# File 'lib/avo/wait_for_loaded.rb', line 68

def wait_for_loaded
  wait_for_turbo_loaded
end

#wait_for_route_loaded(time = Capybara.default_max_wait_time) ⇒ Object



9
10
11
# File 'lib/avo/wait_for_loaded.rb', line 9

def wait_for_route_loaded(time = Capybara.default_max_wait_time)
  Timeout.timeout(time) { sleep(0.01) while page.find("body")[:class].include?("route-loading") }
end

#wait_for_route_loading(time = Capybara.default_max_wait_time) ⇒ Object



5
6
7
# File 'lib/avo/wait_for_loaded.rb', line 5

def wait_for_route_loading(time = Capybara.default_max_wait_time)
  Timeout.timeout(time) { sleep(0.01) until page.find("body")[:class].include?("route-loading") }
end

#wait_for_search_loaded(time = Capybara.default_max_wait_time) ⇒ Object



17
18
19
# File 'lib/avo/wait_for_loaded.rb', line 17

def wait_for_search_loaded(time = Capybara.default_max_wait_time)
  wait_for_body_class_missing("search-loading", time)
end

#wait_for_search_to_dissapear(time = Capybara.default_max_wait_time) ⇒ Object



21
22
23
# File 'lib/avo/wait_for_loaded.rb', line 21

def wait_for_search_to_dissapear(time = Capybara.default_max_wait_time)
  wait_for_element_missing(".aa-DetachedOverlay", time)
end

#wait_for_tag_suggestions_to_appear(time = Capybara.default_max_wait_time) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/avo/wait_for_loaded.rb', line 88

def wait_for_tag_suggestions_to_appear(time = Capybara.default_max_wait_time)
  Capybara.using_wait_time(time) do
    page.has_css?(".tagify__dropdown")
  end

  current_count = prev_count = page.all(".tagify__dropdown__item").count
  attempts = 5

  loop do
    sleep(0.05)
    current_count = page.all(".tagify__dropdown__item").count

    # Break when suggestions stop appearing
    # Or attempts reach 0
    attempts -= 1
    break if (current_count == prev_count) || (attempts == 0)
    prev_count = current_count
  end
end

#wait_for_tag_to_appear(tag, time = Capybara.default_max_wait_time) ⇒ Object



82
83
84
85
86
# File 'lib/avo/wait_for_loaded.rb', line 82

def wait_for_tag_to_appear(tag, time = Capybara.default_max_wait_time)
  Capybara.using_wait_time(time) do
    page.has_css?(".tagify__tag", text: tag)
  end
end

#wait_for_tag_to_disappear(tag, time = Capybara.default_max_wait_time) ⇒ Object



76
77
78
79
80
# File 'lib/avo/wait_for_loaded.rb', line 76

def wait_for_tag_to_disappear(tag, time = Capybara.default_max_wait_time)
  Capybara.using_wait_time(time) do
    page.has_no_css?(".tagify__tag", text: tag)
  end
end

#wait_for_turbo_frame_id(frame_id = "", time = Capybara.default_max_wait_time) ⇒ Object



25
26
27
# File 'lib/avo/wait_for_loaded.rb', line 25

def wait_for_turbo_frame_id(frame_id = "", time = Capybara.default_max_wait_time)
  wait_for_element_missing("turbo-frame[id='#{frame_id}'][busy]", time)
end

#wait_for_turbo_frame_src(frame_src = "", time = Capybara.default_max_wait_time) ⇒ Object



29
30
31
# File 'lib/avo/wait_for_loaded.rb', line 29

def wait_for_turbo_frame_src(frame_src = "", time = Capybara.default_max_wait_time)
  wait_for_element_missing("turbo-frame[src='#{frame_src}'][busy]", time)
end

#wait_for_turbo_loaded(time = Capybara.default_max_wait_time) ⇒ Object



13
14
15
# File 'lib/avo/wait_for_loaded.rb', line 13

def wait_for_turbo_loaded(time = Capybara.default_max_wait_time)
  wait_for_body_class_missing("turbo-loading", time)
end