【发布时间】:2014-10-07 15:23:38
【问题描述】:
我正在使用 behat 编写测试,当我尝试在引导模式内的输入上调用 fillField 时遇到问题。 当我在这个输入中发送 fillField 时,硒会抛出一个异常:
Element is not currently visible and so may not be interacted with
我手动创建了一个 selenium(通过 selenium IDE)测试并在同一字段上调用 type,它工作正常。
$page = $this->getSession()->getPage()
$page->fillField("id_item", $value);
$value 是我测试中的一个参数。我尝试调用一个函数等待几秒钟,但效果不佳。
更新:
场景:
Scenario: Realizar Pedido de Compra
Given I am on "/"
When I fill the form with "{\"id\": 1, \"items\":[{\"id_item\": 1}]}"
Then I should see "Ok"
我的 FeatureContext:
/**
* @When I fill the form with :arg1
*/
public function iFillForm($json) {
$formHelper = FormHelper::getInstance($this->getSession());
$formHelper->fill($json);
}
在我的课堂FormHelper中:
public function fill($json) {
$handler = new SelectorsHandler();
$handler->registerSelector("css", new CssSelector());
$fileJson = json_decode($json, true);
$page = $this->session->getPage();
foreach ($json as $key => $value) {
if (is_array($value)) {
$addSubGrid = $page->find("css", "#btn-plus-" . $key);
if ($addSubGrid != null) {
$subGrid = $page->find("css", "#" . $key);
$formId = $subGrid->getAttribute("data-form");
$ok = $page->find("css", "#$formId .btn-ok");
foreach ($value as $formItem) {
$itemFilled = array();
$addSubGrid->click();
$this->session->wait(
1000, "$('#modal-$formId').is(':visible')"
);
$this->fillForm($page, array("form-item" => $formItem), $itemFilled, false);
$ok->press();
}
}
} else {
$page->fillField($key, $value);
}
}
$addSubGrid 变量是显示模态的元素。当我执行测试时,它会打开模式,但是当它进入 $page->fillField($key, $value) 时它不起作用。
更新 我发现我正在尝试填写禁用字段。我已经启用它,现在的问题是它没有填充模态框内的字段,只填充外面的字段。
【问题讨论】:
-
显示场景代码?
-
嘿。我已经添加了场景和运行它的代码
-
@ThiagoFrança 我使用来自 Behat 的那个(我已经关注了他们的文档)@IanBytchek 在使用
$addSubGrid->click()打开模式后,fillField上出现错误
标签: twitter-bootstrap selenium behat mink