Set the value of a datetime field using dmore/behat-chrome-extension

297 Views Asked by At

I can set the value of a datetime form field with Behat/Mink in Selenium Standalone Chrome, but not the Dmore Behat Chrome Extension.

I have defined a step like this:

And I assign the date "yesterday" with timezone "Asia/Tokyo" for "edit-field-datetime-MYFIELD-0-value"

In FeatureContext.php, this is my code:

  /**
   * @Then I assign the date :date with timezone :timezone for :field
   *
   * Assign the specified date to the element with the given CSS.
   */
  public function assertEnterDateForField($field, $timezone, $date_string) {
    $date_field = $field . '-date';
    $time_field = $field . '-time';
    // Drupal stores timezones as UTC so we need the base time in UTC.
    $datetime = new DateTime($date_string, timezone_open('UTC'));
    // We need to convert the UTC time to the user's timezone.
    // This is because when saving the entity,
    // Drupal will convert the value to UTC.
    $datetime->setTimezone(timezone_open($timezone));
    $date_output_string = $datetime->format('mdY');
    $time_output_string = $datetime->format('hisA');
    $datetime_debug_string = $datetime->format('Y-m-d\TH:i:sO');
    $this->fillfield($time_field, $time_output_string);
    $this->fillField($date_field, $date_output_string);
    echo "Datetime $datetime_debug_string
    Field set to
    date: $date_output_string
    time: $time_output_string";
  }

On my local environment (lando, running the Standalone Chrome container), this code works as expected; the date/time is set correctly for the field.

However, on my test server (Pantheon/CircleCI, running the Behat Chrome Extension, it doesn't work. The debug information output by the code on the test server is correct; for example:

  │ Datetime 2020-08-13T09:00:00+0900
  │     Field set to
  │     date: 08132020
  │     time: 090000AM

However, the date/time is not actually filled in. This is a screenshot of the step after running my code:

empty datetime field

Here's the HTML from Drupal for the field:

<div id="edit-field-datetime-review-target-0-value">
    <div class="field js-form-item form-item js-form-type-date form-item-field-datetime-review-target-0-value-date js-form-item-field-datetime-review-target-0-value-date form-no-label">
        <label class="label control-label visually-hidden" for="edit-field-datetime-review-target-0-value-date">
            Date
        </label>
        <div class="control">
            <input id="edit-field-datetime-review-target-0-value-date" class="form-date is-link input" title="Date (e.g. 2020-08-22)" max="2050-12-31" min="1900-01-01" name="field_datetime_review_target[0][value][date]" size="12" type="date" value="2020-08-22" data-drupal-selector="edit-field-datetime-review-target-0-value-date" data-drupal-date-format="Y-m-d" />
        </div>
    </div>
    <div class="field js-form-item form-item js-form-type-date form-item-field-datetime-review-target-0-value-time js-form-item-field-datetime-review-target-0-value-time form-no-label">
        <label class="label control-label visually-hidden" for="edit-field-datetime-review-target-0-value-time">
            Time
        </label>
        <div class="control">
            <input id="edit-field-datetime-review-target-0-value-time" class="form-time is-link input" title="Time (e.g. 15:19:19)" name="field_datetime_review_target[0][value][time]" size="12" step="1" type="time" value="15:19:04" data-drupal-selector="edit-field-datetime-review-target-0-value-time" />
        </div>
    </div>
</div>

So, how can I set the value of a datetime field with Dmore/Behat-chrome-extension?

0

There are 0 best solutions below