Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for finding buttons that use aria-label for a value. #865

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Selector/ExactNamedSelector.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function __construct()
$this->registerReplacement('%altMatch%', './@alt = %locator%');
$this->registerReplacement('%relMatch%', './@rel = %locator%');
$this->registerReplacement('%labelAttributeMatch%', './@label = %locator%');
$this->registerReplacement('%ariaLabelAttributeMatch%', './@aria-label = %locator%');

parent::__construct();
}
Expand Down
8 changes: 4 additions & 4 deletions src/Selector/NamedSelector.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class NamedSelector implements SelectorInterface
'%fieldFilterWithoutPlaceholder%' => 'self::input[%inputTypeWithoutPlaceholderFilter%] | self::select',
'%buttonTypeFilter%' => "%lowercaseType% = 'submit' or %lowercaseType% = 'image' or %lowercaseType% = 'button' or %lowercaseType% = 'reset'",
'%notFieldTypeFilter%' => "not(%buttonTypeFilter% or %lowercaseType% = 'hidden')",
'%buttonMatch%' => '%idOrNameMatch% or %valueMatch% or %titleMatch%',
'%buttonMatch%' => '%idOrNameMatch% or %valueMatch% or %titleMatch% or %ariaLabelAttributeMatch%',
'%linkMatch%' => '(%idMatch% or %tagTextMatch% or %titleMatch% or %relMatch%)',
'%imgAltMatch%' => './/img[%altMatch%]',
);
Expand Down Expand Up @@ -99,16 +99,16 @@ class NamedSelector implements SelectorInterface
[./@href][(%linkMatch% or %imgAltMatch%)]
|
.//input
[%buttonTypeFilter%][(%idOrValueMatch% or %titleMatch%)]
[%buttonTypeFilter%][(%idOrValueMatch% or %titleMatch% or %ariaLabelAttributeMatch%)]
|
.//input
[%lowercaseType% = 'image'][%altMatch%]
|
.//button
[(%idOrValueMatch% or %titleMatch% or %tagTextMatch%)]
[(%idOrValueMatch% or %titleMatch% or %tagTextMatch% or %ariaLabelAttributeMatch%)]
|
.//*
[(%lowercaseRole% = 'button' or %lowercaseRole% = 'link')][(%idOrValueMatch% or %titleMatch% or %tagTextMatch%)]
[(%lowercaseRole% = 'button' or %lowercaseRole% = 'link')][(%idOrValueMatch% or %titleMatch% or %tagTextMatch% or %ariaLabelAttributeMatch%)]
XPATH

,'content' => <<<XPATH
Expand Down
1 change: 1 addition & 0 deletions src/Selector/PartialNamedSelector.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public function __construct()
$this->registerReplacement('%altMatch%', 'contains(./@alt, %locator%)');
$this->registerReplacement('%relMatch%', 'contains(./@rel, %locator%)');
$this->registerReplacement('%labelAttributeMatch%', 'contains(./@label, %locator%)');
$this->registerReplacement('%ariaLabelAttributeMatch%', 'contains(./@aria-label, %locator%)');

parent::__construct();
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Selector/NamedSelectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public function getSelectorTests()
'link (without-href) ignored' => array('test.html', 'link', 'bad-link-text', 0),
'link* (role=link)' => array('test.html', 'link', 'link-role-text', 4, 7),

'button (input, name/value/title)' => array('test.html', 'button', 'button-text', 25, 42),
'button (input, name/value/title/aria-label)' => array('test.html', 'button', 'button-text', 33, 58),
'button (type=image, with-alt)' => array('test.html', 'button', 'button-alt-text', 1, 2),
'button (input type=submit, with-id)' => array('test.html', 'button', 'input-submit-button', 1),
'button (input type=image, with-id)' => array('test.html', 'button', 'input-image-button', 1),
Expand All @@ -150,8 +150,8 @@ public function getSelectorTests()
'link_or_button (without-href) ignored' => array('test.html', 'link_or_button', 'bad-link-text', 0),
'link_or_button* (role=link)' => array('test.html', 'link_or_button', 'link-role-text', 4, 7),

// bug in selector: 17 instead of 25 and 34 instead of 42, because 8 buttons with `name` attribute were not matched
'link_or_button (input, name/value/title)' => array('test.html', 'link_or_button', 'button-text', 17, 34),
// bug in selector: 25 instead of 33 and 50 instead of 58, because 8 buttons with `name` attribute were not matched
'link_or_button (input, name/value/title/aria-label)' => array('test.html', 'link_or_button', 'button-text', 25, 50),
'link_or_button (type=image, with-alt)' => array('test.html', 'link_or_button', 'button-alt-text', 1, 2),
'link_or_button (input type=submit, with-id)' => array('test.html', 'link_or_button', 'input-submit-button', 1),
'link_or_button (input type=image, with-id)' => array('test.html', 'link_or_button', 'input-image-button', 1),
Expand Down
19 changes: 19 additions & 0 deletions tests/Selector/fixtures/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,25 @@
<button type="button" title="some button-text"></button>
<button type="reset" title="some button-text"></button>

<!-- match buttons by `aria-label` attribute -->
<input type="submit" aria-label="button-text"/>
<input type="image" aria-label="button-text"/>
<input type="button" aria-label="button-text"/>
<input type="reset" aria-label="button-text"/>
<button type="submit" aria-label="button-text"></button>
<button type="image" aria-label="button-text"></button>
<button type="button" aria-label="button-text"></button>
<button type="reset" aria-label="button-text"></button>
<!-- partial match -->
<input type="submit" aria-label="some button-text"/>
<input type="image" aria-label="some button-text"/>
<input type="button" aria-label="some button-text"/>
<input type="reset" aria-label="some button-text"/>
<button type="submit" aria-label="some button-text"></button>
<button type="image" aria-label="some button-text"></button>
<button type="button" aria-label="some button-text"></button>
<button type="reset" aria-label="some button-text"></button>

<!-- match some buttons by `alt` attribute -->
<input type="submit" alt="button-alt-text"/>
<input type="imaGe" alt="button-alt-text"/>
Expand Down
Loading