-
Notifications
You must be signed in to change notification settings - Fork 2
/
debug_test_helper.rb
50 lines (40 loc) · 1.67 KB
/
debug_test_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# frozen_string_literal: true
# Public: Contains useful methods for debugging test failures.
class DebugTestHelper < BaseTestHelper
# Finders: A convenient way to get related data or nested elements.
# Public: Returns the inner HTML of the specified element.
def inner_html(element)
element = element.to_capybara_node if element.respond_to?(:to_capybara_node)
(element.respond_to?(:native) ? element.native.inner_html : element.text) if element
end
# Actions: Encapsulate complex actions to provide a cleaner interface.
def screenshot
Rails.env.ci? ? save_screenshot : save_and_open_screenshot
end
def puts_page
puts_and_return body
end
def puts_html(element)
puts_and_return inner_html(element)
end
# Internal: Only used for debuging in development.
def puts_element(*args, **options)
puts_and_return with_js_element(*args, evaluate: '.outerHTML', **options)
end
# Internal: Only used for debuging in development.
def puts_inner_html(*args, **options)
puts_and_return with_js_element(*args, evaluate: '.innerHTML', **options)
end
# Internal: Only used for debuging in development.
def puts_and_return(value)
value.tap { Kernel.puts(value.is_a?(String) ? value.yellow : value.inspect) }
end
# Public: Try to refocus the current window when not running headless.
# NOTE: This is useful when you are doing something else while running the
# test and the browser can't find a `visible` element.
def refocus_window
driver.switch_to_window(current_window.handle)
end
# Assertions: Allow to check on element properties while keeping it DRY.
# Background: Helpers to add/modify/delete data in the database or session.
end