These are chat archives for Behat/Behat

9th
Nov 2016
Laura Hartwell
@fuel-lhartwell
Nov 09 2016 00:18

Just in case someone else runs into this same thing, here was how I finally figured out how to deal with this. I ended up having to edit the php itself of the page. From this:

          <input type="text" class="txt-expires" data-bind="disable: $root.signed().signed, value: expires, event: { change: $root.vialSaveData }, attr: { id: 'txt-expires-entry-' + type_id() + '-' + $index() + '-' + dilutions() }”>

to this

            <input type="text" class="txt-expires" data-bind="disable: $root.signed().signed, value: expires, event: { change: $root.vialSaveData }, attr: { value: expires, id: 'txt-expires-entry-' + type_id() + '-' + $index() + '-' + dilutions() }">

and now when I inspect the element I need to assert on I have value attribute I can grab onto value:

<input id="txt-expires-entry-1-0-0" value="05/08/2017" class="txt-expires" data-bind="disable: $root.signed().signed, value: expires, event: { change: $root.vialSaveData }, attr: { value: expires, id: 'txt-expires-entry-' + type_id() + '-' + $index() + '-' + dilutions() }" type=”text">

I just added under attr: {} section “value: expires, "

Here was my final behat assertion and it’s featureContext method:

 Then I should see the date adjusted by "+6 months" in the "#txt-expires-entry-1-0-0" field

FeatureContext:

    // call currentDate() to fetch and format the date
    public function getCurrentDate($dateAdjust='+0 days') {
        return $this->currentdate = $this->currentDate($dateAdjust)->format('m/d/Y');
    }

    // Get current date time
    protected function currentDate($dateAdjust='+0 days') {
        return new DateTime($dateAdjust);
    }

    /**
     * @Then I should see the date adjusted by :dateAdjust in the :css_locator field
     */
    public function MonthDayYearDateMatch($dateAdjust='+0 days', $css_locator)
    {
        $adjustedDate = $this->getCurrentDate($dateAdjust);
        $elementByCss = $this->getSession()->getPage()->find('css', $css_locator)->getAttribute('value');
        if ($elementByCss != $adjustedDate) {
            throw new Exception('CSS Locator '.$css_locator.' does not contain '.$adjustedDate.'.');
        }
    }