Filling hidden entrances with Behat

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 used the step

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

Is there anything special you need to do to change hidden input fields?

+4
source share
3 answers

Despite the fact that the user cannot fill in the hidden fields, there are situations when it is desirable to be able to fill in the hidden field for testing (as a rule, the rules have exceptions). You can use the next step in your object context class to populate a 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); } 
+10
source

Right. If the real user can change the input fields via javascript by clicking a button or link. try to do it. Fields that are not visible to the user are also not visible in Mink.

Or what you can do is call $session->executeScript($javascript) from your context using $ javascript, for example

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

and check if this works

+8
source

It is designed by design. Mink is a custom browser emulator. It emulates everything that a real user can do in a real browser. And the user probably will not be able to fill in the hidden fields on the page - he simply does not see them.

Mink is not a crawler, it is a browser emulator. The whole idea of ​​Mink is to describe real user interactions using a simple and clean API. If there is something this user cannot do through a real browser - you cannot do this with a mink.

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

+2
source

All Articles