Created
March 17, 2022 00:50
-
-
Save edysmp/74bf7ea481fa4a24e5e4dbc72871ab55 to your computer and use it in GitHub Desktop.
I fill in the date field behat step definition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @Then I fill in the date field :field with :date | |
* | |
* Assign the specified date to the element. | |
*/ | |
public function iFillDateField($field, $date): void { | |
$field_label = $this->getSession()->getPage()->find('xpath', "//*[text() = '$field']"); | |
if ($field_label == NULL | !$field_label->hasClass('form-item__label')) { | |
throw new ExpectationException('Could not find date field with label: ' . $field, $this->getSession()); | |
} | |
$datetime = new \DateTime($date, \timezone_open('UTC')); | |
$datetime->setTimezone(new \DateTimeZone(\date_default_timezone_get())); | |
$date_input = $field_label->getParent()->find('xpath', "//input[@type='date']"); | |
$date_output_string = $datetime->format('Y-m-d'); | |
$this->getSession()->getPage()->fillField($date_input->getAttribute('id'), $date_output_string); | |
$time_input = $field_label->getParent()->find('xpath', "//input[@type='time']"); | |
if ($time_input) { | |
$time_output_string = $datetime->format('H:i:s'); | |
$this->getSession()->getPage()->fillField($time_input->getAttribute('id'), $time_output_string); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment