Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filling in hidden inputs with Behat

Tags:

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 have been using the step

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

Is there something special which needs to be done to modify hidden input fields?

like image 590
Sean Avatar asked Sep 26 '11 20:09

Sean


1 Answers

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);
}
like image 71
WayFarer Avatar answered Oct 10 '22 02:10

WayFarer