1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

Fix test_id issue in :button selector and add test

This commit is contained in:
Thomas Walpole 2021-01-26 08:53:59 -08:00
parent 1480800582
commit 5e4fcae516
3 changed files with 11 additions and 2 deletions

View file

@ -57,7 +57,7 @@ Capybara.add_selector(:button, locator_type: [String, Symbol]) do
XPath.attr(:title).is(locator),
(XPath.attr(:id) == XPath.anywhere(:label)[XPath.string.n.is(locator)].attr(:for)),
(XPath.attr(:'aria-label').is(locator) if config.enable_aria_label),
(XPath.attr(test_id) == locator if config.test_id)
(XPath.attr(config.test_id) == locator if config.test_id)
].compact.inject(&:|)
end
end

View file

@ -38,6 +38,15 @@ Capybara::SpecHelper.spec '#click_link_or_button' do
expect(extract_results(@session)['first_name']).to eq('John')
end
context 'with test_id' do
it 'should click on a button' do
Capybara.test_id = 'data-test-id'
@session.visit('/form')
@session.click_link_or_button('test_id_button')
expect(extract_results(@session)['first_name']).to eq('John')
end
end
context 'with :exact option' do
context 'when `false`' do
it 'clicks on approximately matching link' do

View file

@ -449,7 +449,7 @@ New line after and before textarea tag
<p>
<input type="button" aria-label="Aria button" name="form[fresh]" id="fresh_btn" value="i am fresh"/>
<input type="submit" name="form[awesome]" id="awe123" title="What an Awesome Button" value="awesome"/>
<input type="submit" name="form[awesome]" id="awe123" data-test-id="test_id_button" title="What an Awesome Button" value="awesome"/>
<input type="submit" name="form[crappy]" id="crap321" value="crappy"/>
<input type="image" name="form[okay]" id="okay556" title="Okay 556 Image" value="okay" alt="oh hai thar"/>
<button type="submit" id="click_me_123" title="Click Title button" value="click_me">Click me!</button>