Last active
December 17, 2015 20:49
-
-
Save tomazy/5670433 to your computer and use it in GitHub Desktop.
Using data- attributes in SitePrism/Capybara
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Capybara.add_selector(:test_element) do | |
xpath { |name| XPath.css("[data-test-element='#{name}']") } | |
end | |
module TestElement | |
def test_element(name) | |
element(name, :test_element, name.to_s) | |
end | |
def test_sections(section_name, section_class, matcher_name) | |
sections(section_name, section_class, :test_element, matcher_name.to_s) | |
end | |
def test_section(section_name, section_class, matcher_name) | |
section(section_name, section_class, :test_element, matcher_name.to_s) | |
end | |
end | |
class BaseSection < SitePrism::Section | |
extend TestElement | |
end | |
class BasePage < SitePrism::Page | |
extend TestElement | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe "Goldfinger" do | |
it { sample_page.user_name.text.should == "James Bond" } | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="css-only-class" id="css-only-id" data-test-element="user_name">James Bond</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SamplePage < BasePage | |
test_element :user_name | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment