Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Use Capybara.add_selector

Oliver Günther6b026bd59e11
diff --git a/spec/support/finders/test_selector.rb b/spec/support/finders/test_selector.rb
index d8b805040cf..61ee5381a46 100644
--- a/spec/support/finders/test_selector.rb
+++ b/spec/support/finders/test_selector.rb
@@ -25,21 +25,30 @@
#
# See COPYRIGHT and LICENSE files for more details.
#++
+require 'capybara/rspec'
+
module TestSelectorFinders
def test_selector(value)
"[data-test-selector=\"#{value}\"]"
end
def find_test_selector(value, **)
- find(test_selector(value), **)
+ find(:test_id, value, **)
end
def within_test_selector(value, **, &block)
- within(test_selector(value), **, &block)
+ within(:test_id, value, **, &block)
end
end
RSpec.configure do |config|
+ Capybara.test_id = 'data-test-selector'
+ Capybara.add_selector(:test_id) do
+ xpath do |locator|
+ XPath.descendant[XPath.attr(Capybara.test_id) == locator]
+ end
+ end
+
Capybara::Session.include(TestSelectorFinders)
Capybara::DSL.extend(TestSelectorFinders)
config.include TestSelectorFinders, type: :feature