Skip to content

A platform for community discussion. Free, open, simple.

DEV: Avoid stale selections in system test keyboard actions (#45057)

Alan Guo Xiang Tan36dae60949ba
diff --git a/spec/support/system_helpers.rb b/spec/support/system_helpers.rb
index 706803737f9..f493fd4ead5 100644
--- a/spec/support/system_helpers.rb
+++ b/spec/support/system_helpers.rb
@@ -166,15 +166,17 @@ module SystemHelpers
def select_all_content(selector)
js = <<-JS
+ const done = arguments[arguments.length - 1];
const el = document.querySelector(arguments[0]);
const selection = window.getSelection();
const range = document.createRange();
range.selectNodeContents(el);
+ document.addEventListener("selectionchange", () => done(), { once: true });
selection.removeAllRanges();
selection.addRange(range);
JS
- page.execute_script(js, selector)
+ page.evaluate_async_script(js, selector)
end
def select_text_range(selector, start = 0, offset = 5)