Php Behat/Mink并选择2组合
我尝试使用Select2创建一个带有web UI的行为场景 当我尝试更改select值时,由于Select2隐藏了基本select,因此出现了Behat错误 但是我已经在select2组件中出现了一个错误,因为mink无法与它交互Php Behat/Mink并选择2组合,php,jquery-select2,behat,mink,Php,Jquery Select2,Behat,Mink,我尝试使用Select2创建一个带有web UI的行为场景 当我尝试更改select值时,由于Select2隐藏了基本select,因此出现了Behat错误 但是我已经在select2组件中出现了一个错误,因为mink无法与它交互 您是否已将Behat/Mink与Select2一起使用?你有什么建议可以帮助我吗?我一直在坚持这一点,但我已经用在网站上找到的信息进行了讨论 我的解决方案只是略有不同: /** * @Given /^I fill hidden field "([^"]*)" wi
您是否已将Behat/Mink与Select2一起使用?你有什么建议可以帮助我吗?我一直在坚持这一点,但我已经用在网站上找到的信息进行了讨论 我的解决方案只是略有不同:
/**
* @Given /^I fill hidden field "([^"]*)" with "([^"]*)"$/
*/
public function iFillHiddenFieldWith($class, $value){
$this->getSession()->getPage()->find('css', $class)->setValue($value);
}
然后我用以下方式使用它:
And I fill hidden field "#s2id_edit-my-field input" with "random value".
最后,我编写了一个行为来与Select2字段交互,就像用户可以做的那样 以下是最完整步骤的摘录:
/**
* @When /^(?:|I )fill in select2 input "(?P<field>(?:[^"]|\\")*)" with "(?P<value>(?:[^"]|\\")*)" and select "(?P<entry>(?:[^"]|\\")*)"$/
*/
public function iFillInSelectInputWithAndSelect($field, $value, $entry)
{
$page = $this->getSession()->getPage();
$inputField = $page->find('css', $field);
if (!$inputField) {
throw new \Exception('No field found');
}
$choice = $inputField->getParent()->find('css', '.select2-selection');
if (!$choice) {
throw new \Exception('No select2 choice found');
}
$choice->press();
$select2Input = $page->find('css', '.select2-search__field');
if (!$select2Input) {
throw new \Exception('No input found');
}
$select2Input->setValue($value);
$this->getSession()->wait(1000);
$chosenResults = $page->findAll('css', '.select2-results li');
foreach ($chosenResults as $result) {
if ($result->getText() == $entry) {
$result->click();
break;
}
}
}
/**
*@When/^(?:| I)将select2输入“(?P(?:[^“]\\”*)”填入“(?P(?:[^“]\\”*”)并选择“(?P(?:[^“]\\”*)”$/
*/
公共函数IFILINSELECTINPUTWITHANDSELECT($field、$value、$entry)
{
$page=$this->getSession()->getPage();
$inputField=$page->find('css',$field);
如果(!$inputField){
抛出new\Exception('未找到字段');
}
$choice=$inputField->getParent()->find('css','select2 selection');
如果(!$choice){
抛出new\Exception('未找到select2选项');
}
$choice->press();
$select2Input=$page->find('css','。选择2-search__字段');
如果(!$select2Input){
抛出新\异常(“未找到输入”);
}
$select2Input->setValue($value);
$this->getSession()->等待(1000);
$chosenResults=$page->findAll('css','.select2 results li');
foreach($chosenResults作为$result){
如果($result->getText()==$entry){
$result->click();
打破
}
}
}
几天后,我将在Github上打开Select2上下文的源代码。我将在上打开Select2上下文的源代码。分支1.x与Behat2兼容,分支2.x与Behat3兼容。