With chromedriver >= 80, the tests are freezing sometimes, particularly when the same editor is loaded again. We don't know whether it's a CKEditor issue or a chromedriver issue. In the past we've had some errors related to CKEditor trying to load the same instance twice and we aren't sure they have been fixed since we could never reproduce them. It could be a coincidence, though. If we modify the views so the only content of the `<body>` tag is a textarea with the `html-area` class, chromedriver freezes even if we only access the page once. So maybe we're only detecting the problem on the second visit because the second request is faster than the first one. Since chromedriver no longer hangs after this change, we don't have to force any chromedriver version anymore.
36 lines
885 B
Ruby
36 lines
885 B
Ruby
RSpec::Matchers.define :have_ckeditor do |label, with:|
|
|
define_method :textarea_id do
|
|
find("label", text: label)[:for]
|
|
end
|
|
|
|
define_method :ckeditor_id do
|
|
"#cke_#{textarea_id}"
|
|
end
|
|
|
|
define_method :has_ckeditor? do
|
|
has_css?("label", text: label) && has_css?(ckeditor_id)
|
|
end
|
|
|
|
match do
|
|
return false unless has_ckeditor?
|
|
|
|
until page.execute_script("return CKEDITOR.instances.#{textarea_id}.status === 'ready';") do
|
|
sleep 0.01
|
|
end
|
|
|
|
page.within(ckeditor_id) do
|
|
within_frame(0) { has_content?(with, exact: true) }
|
|
end
|
|
end
|
|
|
|
failure_message do
|
|
if has_ckeditor?
|
|
text = page.within(ckeditor_id) { within_frame(0) { page.text } }
|
|
|
|
"expected to find visible CKEditor '#{label}' with '#{with}', but had '#{text}'"
|
|
else
|
|
"expected to find visible CKEditor '#{label}' but there were no matches."
|
|
end
|
|
end
|
|
end
|