开发者

Filling in hidden inputs with Behat

开发者 https://www.devze.com 2023-04-07 13:03 出处:网络
I am writing Behat tests and I need to change the value of a hidden input field <input type=\"hidden\" id=\"input_id\" ..... />

I am writing Behat tests and I need to change the value of a hidden input field

<input type="hidden" id="input_id" ..... />

I need to change the value of this input field, but I keep getting

Form field with id|name|label|value "input_id" not found

I have been using the step

$steps->And('I fill in "1" for "input_id"', $world);

Is there somethi开发者_如何转开发ng special which needs to be done to modify hidden input fields?


Despite the fact that user can't fill hidden fields, there are some situations when this is desirable to be able to fill hidden field for testing (as usually rules have exceptions). You can use next step in your feature context class to fill hidden field by name:

/**
 * @Given /^I fill hidden field "([^"]*)" with "([^"]*)"$/
 */
public function iFillHiddenFieldWith($field, $value)
{
    $this->getSession()->getPage()->find('css',
        'input[name="'.$field.'"]')->setValue($value);
}


Rev is right. If real user can can change input fields via javascript by clicking a button or link. try doing that. Fields that are not visible to user are also not visible to Mink also.

Or else what you can do is Call $session->executeScript($javascript) from your context with $javascript like

$javascript = "document.getElementById('input_id').value='abc'";
$this->getSession()->executeScript($javascript);

and check if that works


It's intended by design. Mink is user+browser emulator. It emulates everything, that real user can do in real browser. And user surely can't fill hidden fields on the page - he just don't see them.

Mink is not crawler, it's a browser emulator. The whole idea of Mink is to describe real user interactions through simple and clean API. If there's something, that user can't do through real browser - you can't do it with Mink.

(source: http://groups.google.com/group/behat/browse_thread/thread/f06d423c27754c4d)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号