summaryrefslogtreecommitdiff
path: root/qa/qa/page/base.rb
diff options
context:
space:
mode:
Diffstat (limited to 'qa/qa/page/base.rb')
-rw-r--r--qa/qa/page/base.rb19
1 files changed, 17 insertions, 2 deletions
diff --git a/qa/qa/page/base.rb b/qa/qa/page/base.rb
index 69f14386223..1d4a5c54969 100644
--- a/qa/qa/page/base.rb
+++ b/qa/qa/page/base.rb
@@ -1,3 +1,5 @@
+require 'capybara/dsl'
+
module QA
module Page
class Base
@@ -9,8 +11,6 @@ module QA
end
def wait(css = '.application', time: 60)
- # This resolves cold boot / background tasks problems
- #
Time.now.tap do |start|
while Time.now - start < time
break if page.has_css?(css, wait: 5)
@@ -25,6 +25,21 @@ module QA
def self.address
raise NotImplementedError
end
+
+ def scroll_to(selector, text: nil)
+ page.execute_script <<~JS
+ var elements = Array.from(document.querySelectorAll('#{selector}'));
+ var text = '#{text}';
+
+ if (text.length > 0) {
+ elements.find(e => e.textContent === text).scrollIntoView();
+ } else {
+ elements[0].scrollIntoView();
+ }
+ JS
+
+ page.within(selector) { yield } if block_given?
+ end
end
end
end