mirror of
https://github.com/silverstripe/silverstripe-behat-extension
synced 2024-10-22 15:05:32 +00:00
Update to mink 1.6 and remove custom fork
Add javascript-workaround for selecting hidden elements
This commit is contained in:
parent
e3ccf1c733
commit
0050149bfa
@ -1,38 +1,39 @@
|
|||||||
{
|
{
|
||||||
"name": "silverstripe/behat-extension",
|
"name": "silverstripe/behat-extension",
|
||||||
"type": "behat-extension",
|
"type": "behat-extension",
|
||||||
"description": "SilverStripe framework extension for Behat",
|
"description": "SilverStripe framework extension for Behat",
|
||||||
"keywords": ["framework", "web", "bdd", "silverstripe"],
|
"keywords": ["framework", "web", "bdd", "silverstripe"],
|
||||||
"homepage": "http://silverstripe.org",
|
"homepage": "http://silverstripe.org",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "Michal Ochman",
|
"name": "Michal Ochman",
|
||||||
"email": "ochman.d.michal@gmail.com"
|
"email": "ochman.d.michal@gmail.com"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Ingo Schommer",
|
"name": "Ingo Schommer",
|
||||||
"email": "ingo@silverstripe.com"
|
"email": "ingo@silverstripe.com"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.3.2",
|
"php": ">=5.3.2",
|
||||||
"phpunit/phpunit": "3.7.*",
|
"phpunit/phpunit": "3.7.*",
|
||||||
"behat/behat": "2.5.*@stable",
|
"behat/behat": "2.5.*@stable",
|
||||||
"behat/mink": "1.5.*@stable",
|
"behat/mink": "1.6.*-dev",
|
||||||
"behat/mink-extension": "1.3.*@stable",
|
"behat/mink-extension": "1.3.*-dev",
|
||||||
"silverstripe/mink-selenium2-driver": "1.1.*-dev",
|
"behat/mink-selenium2-driver": "1.2.*-dev",
|
||||||
"symfony/dom-crawler": "*@stable",
|
"symfony/dom-crawler": "*@stable",
|
||||||
"behat/mink-goutte-driver": "*",
|
"fabpot/goutte": "1.*@stable",
|
||||||
"silverstripe/testsession": "*",
|
"behat/mink-goutte-driver": "1.1.*-dev",
|
||||||
"silverstripe/framework": "~3.1"
|
"silverstripe/testsession": "*",
|
||||||
},
|
"silverstripe/framework": "~3.1"
|
||||||
|
},
|
||||||
|
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-0": {
|
"psr-0": {
|
||||||
"SilverStripe\\BehatExtension": "src/"
|
"SilverStripe\\BehatExtension": "src/"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"minimum-stability": "dev"
|
"minimum-stability": "dev"
|
||||||
}
|
}
|
||||||
|
@ -412,4 +412,73 @@ class SilverStripeContext extends MinkContext implements SilverStripeAwareContex
|
|||||||
$this->testSessionEnvironment->applyState($state);
|
$this->testSessionEnvironment->applyState($state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Selects option in select field with specified id|name|label|value.
|
||||||
|
*
|
||||||
|
* @override /^(?:|I )select "(?P<option>(?:[^"]|\\")*)" from "(?P<select>(?:[^"]|\\")*)"$/
|
||||||
|
*/
|
||||||
|
public function selectOption($select, $option) {
|
||||||
|
// Find field
|
||||||
|
$field = $this
|
||||||
|
->getSession()
|
||||||
|
->getPage()
|
||||||
|
->findField($this->fixStepArgument($select));
|
||||||
|
|
||||||
|
// If field is visible then select it as per normal
|
||||||
|
if($field && $field->isVisible()) {
|
||||||
|
parent::selectOption($select, $option);
|
||||||
|
} else {
|
||||||
|
$this->selectOptionWithJavascript($select, $option);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Selects option in select field with specified id|name|label|value using javascript
|
||||||
|
* This method uses javascript to allow selection of options that may be
|
||||||
|
* overridden by javascript libraries, and thus hide the element.
|
||||||
|
*
|
||||||
|
* @When /^(?:|I )select "(?P<option>(?:[^"]|\\")*)" from "(?P<select>(?:[^"]|\\")*)" with javascript$/
|
||||||
|
*/
|
||||||
|
public function selectOptionWithJavascript($select, $option) {
|
||||||
|
$select = $this->fixStepArgument($select);
|
||||||
|
$option = $this->fixStepArgument($option);
|
||||||
|
$page = $this->getSession()->getPage();
|
||||||
|
|
||||||
|
// Find field
|
||||||
|
$field = $page->findField($select);
|
||||||
|
if (null === $field) {
|
||||||
|
throw $page->elementNotFound('form field', 'id|name|label|value', $select);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find option
|
||||||
|
$opt = $field->find('named', array(
|
||||||
|
'option', $this->getSession()->getSelectorsHandler()->xpathLiteral($option)
|
||||||
|
));
|
||||||
|
if (null === $opt) {
|
||||||
|
throw $field->elementNotFound('select option', 'value|text', $option);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Merge new option in with old handling both multiselect and single select
|
||||||
|
$value = $field->getValue();
|
||||||
|
$newValue = $opt->getAttribute('value');
|
||||||
|
if(is_array($value)) {
|
||||||
|
if(!in_array($newValue, $value)) $value[] = $newValue;
|
||||||
|
} else {
|
||||||
|
$value = $newValue;
|
||||||
|
}
|
||||||
|
$valueEncoded = json_encode($value);
|
||||||
|
|
||||||
|
// Inject this value via javascript
|
||||||
|
$fieldID = $field->getAttribute('ID');
|
||||||
|
$script = <<<EOS
|
||||||
|
(function($) {
|
||||||
|
$("#$fieldID")
|
||||||
|
.val($valueEncoded)
|
||||||
|
.trigger('liszt:updated')
|
||||||
|
.trigger('chosen:updated');
|
||||||
|
})(jQuery);
|
||||||
|
EOS;
|
||||||
|
$this->getSession()->getDriver()->executeScript($script);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user