Module: Capybara::Playwright::PageExtension
- Defined in:
- lib/capybara/playwright/page.rb
Defined Under Namespace
Classes: DialogAcceptor, DialogMessageMatcher, Headers
Instance Method Summary
collapse
Instance Method Details
#capybara_accept_modal(dialog_type, **options, &block) ⇒ Object
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
|
# File 'lib/capybara/playwright/page.rb', line 91
def capybara_accept_modal(dialog_type, **options, &block)
timeout_sec = options[:wait]
acceptor = DialogAcceptor.new(dialog_type, options)
matcher = DialogMessageMatcher.new(options[:text])
message_promise = Concurrent::Promises.resolvable_future
handler = -> (dialog) {
message = dialog.message
if matcher.matches?(message)
message_promise.fulfill(message)
acceptor.handle(dialog)
else
message_promise.reject(Capybara::ModalNotFound.new("Dialog message=\"#{message}\" dowsn't match"))
dialog.dismiss
end
}
capybara_dialog_event_handler.with_handler(handler) do
block.call
message = message_promise.value!(timeout_sec)
if message_promise.fulfilled?
message
else
raise Capybara::ModalNotFound
end
end
end
|
#capybara_current_frame ⇒ Object
180
181
182
|
# File 'lib/capybara/playwright/page.rb', line 180
def capybara_current_frame
@capybara_frames.last || main_frame
end
|
#capybara_dismiss_modal(dialog_type, **options, &block) ⇒ Object
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
|
# File 'lib/capybara/playwright/page.rb', line 119
def capybara_dismiss_modal(dialog_type, **options, &block)
timeout_sec = options[:wait]
matcher = DialogMessageMatcher.new(options[:text])
message_promise = Concurrent::Promises.resolvable_future
handler = -> (dialog) {
message = dialog.message
if matcher.matches?(message)
message_promise.fulfill(message)
else
message_promise.reject(Capybara::ModalNotFound.new("Dialog message=\"#{message}\" dowsn't match"))
end
dialog.dismiss
}
capybara_dialog_event_handler.with_handler(handler) do
block.call
message = message_promise.value!(timeout_sec)
if message_promise.fulfilled?
message
else
raise Capybara::ModalNotFound
end
end
end
|
#capybara_pop_frame ⇒ Object
176
177
178
|
# File 'lib/capybara/playwright/page.rb', line 176
def capybara_pop_frame
@capybara_frames.pop
end
|
#capybara_push_frame(frame) ⇒ Object
172
173
174
|
# File 'lib/capybara/playwright/page.rb', line 172
def capybara_push_frame(frame)
@capybara_frames << frame
end
|
#capybara_reset_frames ⇒ Object
167
168
169
|
# File 'lib/capybara/playwright/page.rb', line 167
def capybara_reset_frames
@capybara_frames.clear
end
|
153
154
155
156
157
158
159
160
161
|
# File 'lib/capybara/playwright/page.rb', line 153
def
= @capybara_last_response&. || {}
Headers.new.tap do |h|
.each do |key, value|
h[key] = value
end
end
end
|
#capybara_status_code ⇒ Object
163
164
165
|
# File 'lib/capybara/playwright/page.rb', line 163
def capybara_status_code
@capybara_last_response&.status.to_i
end
|
#initialize(*args, **kwargs) ⇒ Object
6
7
8
9
10
11
12
13
|
# File 'lib/capybara/playwright/page.rb', line 6
def initialize(*args, **kwargs)
if kwargs.empty?
super(*args)
else
super(*args, **kwargs)
end
capybara_initialize
end
|