mirror of
https://github.com/silverstripe/silverstripe-behat-extension
synced 2024-10-22 15:05:32 +00:00
Merge pull request #15 from halkyon/select_radio
Adding definition for selecting an input by the group's label.
This commit is contained in:
commit
0a9505e8b2
@ -503,7 +503,10 @@ It's based on the `vendor/bin/behat -di @cms` output.
|
||||
When /^(?:|I )fill in "(?P<value>(?:[^"]|\\")*)" for "(?P<field>(?:[^"]|\\")*)" dropdown$/
|
||||
- Workaround for chosen.js dropdowns or tree dropdowns which hide the original dropdown field.
|
||||
|
||||
|
||||
Given /^I select "([^"]*)" from "([^"]*)" input group$/
|
||||
- Check an individual input button from a group of inputs
|
||||
- Example: I select "Admins" from "Groups" input group
|
||||
(where "Groups" is the title of the CheckboxSetField or OptionsetField form field)
|
||||
|
||||
### Interactions
|
||||
|
||||
|
@ -392,7 +392,36 @@ JS;
|
||||
return new Step\Given(sprintf('I attach the file "%s" to "%s"', $path, $field));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Select an individual input from within a group, matched by the top-most label.
|
||||
*
|
||||
* @Given /^I select "([^"]*)" from "([^"]*)" input group$/
|
||||
*/
|
||||
public function iSelectFromInputGroup($value, $labelText) {
|
||||
$page = $this->getSession()->getPage();
|
||||
$parent = null;
|
||||
|
||||
foreach($page->findAll('css', 'label') as $label) {
|
||||
if($label->getText() == $labelText) {
|
||||
$parent = $label->getParent();
|
||||
}
|
||||
}
|
||||
|
||||
if(!$parent) throw new \InvalidArgumentException(sprintf('Input group with label "%s" cannot be found', $labelText));
|
||||
|
||||
foreach($parent->findAll('css', 'label') as $option) {
|
||||
if($option->getText() == $value) {
|
||||
$for = $option->getAttribute('for');
|
||||
$input = $parent->findById($for);
|
||||
|
||||
if(!$input) throw new \InvalidArgumentException(sprintf('Input "%s" cannot be found', $value));
|
||||
|
||||
$this->getSession()->getDriver()->click($input->getXPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms relative time statements compatible with strtotime().
|
||||
* Example: "time of 1 hour ago" might return "22:00:00" if its currently "23:00:00".
|
||||
* Customize through {@link setTimeFormat()}.
|
||||
|
Loading…
x
Reference in New Issue
Block a user