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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
# frozen_string_literal: true
module QA
module Support
module Page
module Logging
def assert_no_element(name)
log("asserting no element :#{name}")
super
end
def refresh
log("refreshing #{current_url}")
super
end
def wait_until(max_duration: 60, sleep_interval: 0.1, reload: true, raise_on_failure: false)
log("next wait uses reload: #{reload}")
# Logging of wait start/end/duration is handled by QA::Support::Waiter
super
end
def scroll_to(selector, text: nil)
msg = "scrolling to :#{selector}"
msg += " with text: #{text}" if text
log(msg)
super
end
def asset_exists?(url)
exists = super
log("asset_exists? #{url} returned #{exists}")
exists
end
def find_element(name, **kwargs)
log("finding :#{name} with args #{kwargs}")
element = super
log("found :#{name}") if element
element
end
def all_elements(name, **kwargs)
log("finding all :#{name} with args #{kwargs}")
elements = super
log("found #{elements.size} :#{name}") if elements
elements
end
def check_element(name)
log("checking :#{name}")
super
end
def uncheck_element(name)
log("unchecking :#{name}")
super
end
def click_element(name, page = nil, **kwargs)
msg = ["clicking :#{name}"]
msg << ", expecting to be at #{page.class}" if page
msg << "with args #{kwargs}"
log(msg.compact.join(' '))
super
end
def fill_element(name, content)
masked_content = name.to_s.include?('password') ? '*****' : content
log(%Q(filling :#{name} with "#{masked_content}"))
super
end
def select_element(name, value)
log(%Q(selecting "#{value}" in :#{name}))
super
end
def has_element?(name, **kwargs)
found = super
log_has_element_or_not('has_element?', name, found, **kwargs)
found
end
def has_no_element?(name, **kwargs)
found = super
log_has_element_or_not('has_no_element?', name, found, **kwargs)
found
end
def has_text?(text, **kwargs)
found = super
log(%Q{has_text?('#{text}', wait: #{kwargs[:wait] || Capybara.default_max_wait_time}) returned #{found}})
found
end
def has_no_text?(text, **kwargs)
found = super
log(%Q{has_no_text?('#{text}', wait: #{kwargs[:wait] || Capybara.default_max_wait_time}) returned #{found}})
found
end
def finished_loading?
log('waiting for loading to complete...')
now = Time.now
loaded = super
log("loading complete after #{Time.now - now} seconds")
loaded
end
def wait_for_animated_element(name)
log("waiting for animated element: #{name}")
super
end
def within_element(name, text: nil)
log("within element :#{name}")
element = super
log("end within element :#{name}")
element
end
def within_element_by_index(name, index)
log("within elements :#{name} at index #{index}")
element = super
log("end within elements :#{name} at index #{index}")
element
end
private
def log(msg)
QA::Runtime::Logger.debug(msg)
end
def log_has_element_or_not(method, name, found, **kwargs)
msg = ["#{method} :#{name}"]
msg << %Q(with text "#{kwargs[:text]}") if kwargs[:text]
msg << "class: #{kwargs[:class]}" if kwargs[:class]
msg << "(wait: #{kwargs[:wait] || Capybara.default_max_wait_time})"
msg << "returned: #{found}"
log(msg.compact.join(' '))
end
end
end
end
end
|