gpt4 book ai didi

php - Behat/Mink 和 Select2 组合

转载 作者:搜寻专家 更新时间:2023-10-31 21:08:18 25 4
gpt4 key购买 nike

我尝试使用 Select2 通过 Web UI 创建一个 Behat 场景。

当我尝试更改选择值时,我遇到了一个 Behat 错误,因为基本选择被 Select2 隐藏了。

但是我的 select2 组件已经出现错误,因为 mink 无法与之交互。

您已经将 Behat/Mink 与 Select2 一起使用了吗?你有帮助我的提示吗?

最佳答案

我终于写了一个 Behat 来像用户一样与 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;
}
}
}

几天后我将在 Github 上开源 Select2 上下文。

关于php - Behat/Mink 和 Select2 组合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28272268/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com